Skip to content

Latest commit

 

History

History
43 lines (33 loc) · 1.3 KB

README.md

File metadata and controls

43 lines (33 loc) · 1.3 KB

progress

Build Status Coverage Status GoDevDoc Time Tracker Code lines Comments

This library instruments io.Reader/io.Writer with progress printer.

Usage

See catp for an example.

var pr = &progress.Progress{
	Interval: 5 * time.Second,
	Print: func(status progress.ProgressStatus) {
		println(Status(status))
	},
}

func cat(filename string) {
	file, err := os.Open(filename)
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	st, err := file.Stat()
	if err != nil {
		log.Fatalf("failed to read file stats %s: %s", filename, err)
	}

	cr := &progress.CountingReader{Reader: file}

	pr.Start(st.Size, cr.Bytes, cr.Lines, filename)
	defer pr.Stop()

	readFile(cr)
}