progresstracking

package
v1.102.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: BSD-3-Clause Imports: 4 Imported by: 1

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

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

func Ticker(done func() int64, total int64, report func(done, total int64)) (stop func())

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

type CountingWriter struct {
	W io.Writer
	// contains filtered or unexported fields
}

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.

func (*CountingWriter) Write added in v1.102.0

func (c *CountingWriter) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL