ioprogress

package
v0.0.0-...-f2e76ad Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: AGPL-3.0, Apache-2.0 Imports: 7 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProgressReader

func NewProgressReader(readCloser io.ReadCloser, trackerOpts ...TrackerOption) io.ReadCloser

NewProgressReader returns a ProgressReader with the given list of TrackerOption.

func NewProgressWriter

func NewProgressWriter(writeCloser io.WriteCloser, trackerOpts ...TrackerOption) io.WriteCloser

NewProgressWriter returns a ProgressWriter with the given list of TrackerOption.

func NewProgressWriterWrapper

func NewProgressWriterWrapper(trackerOpts ...TrackerOption) func(io.WriteCloser) io.WriteCloser

NewProgressWriterWrapper returns a WriterWrapper with the given list of TrackerOption.

Types

type ProgressData

type ProgressData struct {
	// Text is a string representation of progress.
	Text string

	// Percentage is the percentage progress. This is only set if TotalBytes is non-zero.
	Percentage int

	// TransferredBytes is the number of transferred bytes.
	TransferredBytes int64

	// TotalBytes is the number of expected bytes.
	TotalBytes int64

	// Bytes per second (mean value calculated since I/O operation started).
	BytesPerSecond int64
}

The ProgressData struct contains details about an I/O task.

type ProgressHandler

type ProgressHandler func(ProgressData)

ProgressHandler is a function that receives ProgressData and performs some action with it (e.g. printing to stdout).

type ProgressReader

type ProgressReader struct {
	io.ReadCloser
	Tracker *ProgressTracker
}

ProgressReader is a wrapper around io.ReadCloser which allows for progress tracking.

func (*ProgressReader) Read

func (pt *ProgressReader) Read(p []byte) (int, error)

Read in ProgressReader is the same as io.Read.

type ProgressReporter

type ProgressReporter interface {
	ProgressHandler(action string) ProgressHandler
}

ProgressReporter is a type which, given some action, can return a ProgressHandler. This is useful when several different I/O actions are performed in the same API call or code path.

type ProgressTracker

type ProgressTracker struct {
	Length  int64
	Handler func(percentage int64, bytesTransferred int64, bytesPerSecond int64)
	// contains filtered or unexported fields
}

ProgressTracker provides the stream information needed for tracking.

func NewProgressTracker

func NewProgressTracker(opts ...TrackerOption) *ProgressTracker

NewProgressTracker returns a ProgressTracker configured with the given list of TrackerOption.

type ProgressUpdater

type ProgressUpdater interface {
	UpdateProgress(data ProgressData)
}

ProgressUpdater is a type with a function defining what to do with ProgressData.

type ProgressWriter

type ProgressWriter struct {
	io.WriteCloser
	Tracker *ProgressTracker
}

ProgressWriter is a wrapper around an io.WriteCloser which allows for progress tracking.

func (*ProgressWriter) Write

func (pt *ProgressWriter) Write(p []byte) (int, error)

Write in ProgressWriter is the same as io.Write.

type ReaderWrapper

type ReaderWrapper func(closer io.ReadCloser) io.ReadCloser

ReaderWrapper is a function that returns a ProgressReader from a given io.ReadCloser using a previously configured ProgressReader.

func NewProgressReaderWrapper

func NewProgressReaderWrapper(trackerOpts ...TrackerOption) ReaderWrapper

NewProgressReaderWrapper returns a ReaderWrapper with the given list of TrackerOption.

type TrackerOption

type TrackerOption func(tracker *ProgressTracker)

TrackerOption is a function that configures a ProgressTracker.

func WithDescriptiveProgressHandler

func WithDescriptiveProgressHandler(description string, handler func(data ProgressData)) TrackerOption

WithDescriptiveProgressHandler sets a ProgressHandler for tracker updates. The description is prepended to [ProgressData.Text] with a ": " separator.

func WithDescriptiveProgressReporter

func WithDescriptiveProgressReporter(action string, description string, reporter ProgressReporter) TrackerOption

WithDescriptiveProgressReporter is a convenience for configuring a ProgressTracker for types that implement ProgressReporter. The description is prepended to [ProgressData.Text] with a ": " separator.

func WithLength

func WithLength(length int64) TrackerOption

WithLength sets the expected total number of bytes to be read.

func WithProgressHandler

func WithProgressHandler(handler ProgressHandler) TrackerOption

WithProgressHandler sets a ProgressHandler for tracker updates.

func WithProgressReporter

func WithProgressReporter(action string, reporter ProgressReporter) TrackerOption

WithProgressReporter is a convenience for configuring a ProgressTracker for types that implement ProgressReporter.

func WithProgressUpdater

func WithProgressUpdater(updater ProgressUpdater) TrackerOption

WithProgressUpdater is a convenience for configuring a ProgressTracker for types that implement ProgressUpdater.

type WriterWrapper

type WriterWrapper func(closer io.WriteCloser) io.WriteCloser

WriterWrapper is a function that returns a ProgressWriter from a given io.WriteCloser using a previously configured ProgressWriter.

Jump to

Keyboard shortcuts

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