Documentation
¶
Overview ¶
Package progresstracking provides wrappers around io.Reader and io.Writer that track progress, and a Ticker for reporting progress from an atomic counter on a regular interval.
Index ¶
- func NewReader(r io.Reader, interval time.Duration, onProgress func(totalRead int, err error)) io.Reader
- func NewWriter(w io.Writer, expectedTotal int64, interval time.Duration, ...) io.Writer
- func Ticker(done func() int64, total int64, report func(done, total int64)) (stop func())
- type CountingWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewReader ¶
func NewReader(r io.Reader, interval time.Duration, onProgress func(totalRead int, err error)) io.Reader
NewReader wraps the given Reader with a progress tracking Reader that reports progress at the following points:
- First read - Every read spaced at least interval since the prior read - Last read
func NewWriter ¶ added in v1.102.0
func NewWriter(w io.Writer, expectedTotal int64, interval time.Duration, onProgress func(totalWritten int64)) io.Writer
NewWriter wraps w with a writer that calls onProgress after every write that brings the total past the next interval threshold. onProgress receives the cumulative byte count. If expectedTotal > 0, a final onProgress call is guaranteed when the cumulative count reaches or exceeds it, even if the interval hasn't elapsed.
func Ticker ¶ added in v1.102.0
Ticker reports progress on a regular interval by polling a counter function. It spawns a background goroutine that calls report approximately every second. Call the returned stop function when the operation is complete; stop calls report one final time and blocks until the goroutine exits. The stop function is safe to call multiple times, but will only call report the first time it is invoked.
Types ¶
type CountingWriter ¶ added in v1.102.0
CountingWriter wraps an io.Writer and atomically tracks total bytes written, suitable for use with Ticker.
func (*CountingWriter) Count ¶ added in v1.102.0
func (c *CountingWriter) Count() int64
Count returns the total number of bytes written.