progress_report

package
v0.33.3 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: GPL-3.0 Imports: 4 Imported by: 2

Documentation

Index

Constants

View Source
const (
	UnitsNone = iota
	UnitsBytes
)

Variables

View Source
var ErrorProgressDone = errors.New("Progress is done")

Not a real error, just a flag that can be used to tell progress reporter that this process is Done

Functions

func NewBytesReporterContext

func NewBytesReporterContext(
	ctx context.Context,
	reporter *BytesReporter,
) context.Context

func NewContext

func NewContext(ctx context.Context, updateFunc ReportProgress) context.Context

Insert a progress reporting function in the context

This serves kind of like an interface, as the implementation of what to do when progress is reported is done by the caller

func NewReporterReader

func NewReporterReader(parent io.Reader, reportProgress ReportRead) *reporterReader

Wraps an io.Reader in another Reader which reports the amount of bytes read anytime the parent is read

func NewReporterWriter

func NewReporterWriter(parent io.Writer, reportProgress ReportWrite) *reporterWriter

Types

type BytesReporter

type BytesReporter struct {
	// contains filtered or unexported fields
}

func BytesReporterFromContext

func BytesReporterFromContext(ctx context.Context) *BytesReporter

func NewBytesReporter

func NewBytesReporter(
	ctx context.Context,
	name string,
	size uint64,
) *BytesReporter

func (*BytesReporter) End

func (r *BytesReporter) End()

func (*BytesReporter) Report

func (r *BytesReporter) Report(bytes uint64, err error)

Report the amount of new bytes progressed, if any, and an error, if any. Nil-pointer safe

func (*BytesReporter) Start

func (r *BytesReporter) Start()

type ReportProgress

type ReportProgress func(msg string, done, total uint64, units Units, reportErr error)

Progress reporting function signature

func FromContext

func FromContext(ctx context.Context) ReportProgress

Retrieves the progress reporting function from the context

type ReportRead

type ReportRead func(n uint64, err error)

type ReportWrite

type ReportWrite func(n uint64, err error)

type Units

type Units int

type UnitsReporter

type UnitsReporter struct {
	// contains filtered or unexported fields
}

func NewUnitsReporter

func NewUnitsReporter(
	ctx context.Context,
	name string,
	total uint64,
) *UnitsReporter

func (*UnitsReporter) End

func (r *UnitsReporter) End()

func (*UnitsReporter) Report

func (r *UnitsReporter) Report(units uint64, total uint64, err error)

Report the amount of new units progressed, if any, an update to the total value, if any, and an error, if any. Nil-pointer safe

func (*UnitsReporter) Start

func (r *UnitsReporter) Start()

Jump to

Keyboard shortcuts

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