Skip to content

Latest commit

 

History

History
35 lines (27 loc) · 960 Bytes

File metadata and controls

35 lines (27 loc) · 960 Bytes

Package progress - progress meters through a channel, wrapping an io.Reader

Build Status GoDoc

Example:

func progress(reader io.Reader) {
	r = NewReader("an_file.tar", reader, 100*time.Millisecond)
	defer r.Close()

	var count uint64
	// This goroutine consumes the channel and concatenates the count to display
	// the total as it increases.
	go func(r *Reader) {
		for tick := range r.C {
			count += tick.Value
			fmt.Printf("\r%d", count)
		}

		fmt.Println()
	}(r)

	// use r like you normally would; progress will be reported to C every 100
	// milliseconds.
	if _, err := io.Copy(ioutil.Discard, r); err != nil {
		panic(err)
	}
}

Author

Erik Hollensbe github@hollensbe.org