progress

package
v0.6.19 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidTotal = errors.New("invalid total")

Functions

This section is empty.

Types

type Progress

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

A thread-safe progress tracker; reports percentages exactly (i.e. greater than '1.0' is possible), but will panic on denominators <= '0'.

NOTE: A 'Progress' struct must not be copied after first use.

func NewWithTotal

func NewWithTotal(total uint64) (*Progress, error)

Creates a new 'Progress' struct with the specified 'total' size.

func (*Progress) Add

func (p *Progress) Add(n uint64) uint64

Adds the specified amount to the current progress and returns the new 'current' value. This method is thread-safe.

func (*Progress) Current

func (p *Progress) Current() uint64

Return the 'current' value for the 'Progress' struct. This method is thread-safe.

func (*Progress) Percentage

func (p *Progress) Percentage() float64

Retrieves the current progress as a decimal fraction. This method is thread-safe.

NOTE: This method returns '0.0' if the underlying total is unset.

func (*Progress) Reset

func (p *Progress) Reset()

Resets the current progress to '0'. This method is thread-safe.

NOTE: This method does *NOT* modify the 'total' value.

func (*Progress) SetTotal

func (p *Progress) SetTotal(total uint64) error

Modifies the 'total' size value for the 'Progress' struct. This method is thread-safe.

func (*Progress) Total

func (p *Progress) Total() uint64

Return the 'total' value for the 'Progress' struct. This method is thread-safe.

type Writer

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

A thread-safe 'io.Writer' implementation that tracks the percentage of bytes written against a specified total.

func NewWriter

func NewWriter(p *Progress) *Writer

Creates a new 'Writer' with the specified 'Progress' reporter.

NOTE: It's the caller's responsibility to ensure that the initial 'Progress' provided is correctly configured so that the calculated progress is accurate.

func (*Writer) Write

func (w *Writer) Write(data []byte) (int, error)

Jump to

Keyboard shortcuts

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