Help us shape the future of Go! Take the 2026 Go Developer Survey

progress

package
v5.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ScaleGiB is the scale for computing IEC Gibibytes
	ScaleGiB = IECScale(30)
	// ScaleMiB is the scale for computing IEC Mebibytes
	ScaleMiB = IECScale(20)
	// ScaleKiB is the scale for computing IEC Kibibytes
	ScaleKiB = IECScale(10)
	// ScaleBiB is the base scale for representing a number of bytes
	ScaleBiB = IECScale(1)

	// ReceivingObjects represents progress from counting received objects
	ReceivingObjects UpdateType = iota
	// ResolvingDeltas represents progress from counting resolved deltas
	ResolvingDeltas
)
View Source
const (
	// ThroughputRateSlotCount is the number of samples used to calculate rate
	ThroughputRateSlotCount = 8
)

Variables

This section is empty.

Functions

func ToIEC

func ToIEC(v uint64, scale IECScale) float32

ToIEC converts a size of bytes into the corresponding IEC unit SEE: https://github.com/git/git/blob/be8661a3286c67a5d4088f4226cbd7f8b76544b0/strbuf.c#L830-L869

func ToIECString

func ToIECString(v uint64) string

ToIECString returns a string representation of a size of bytes including its IEC unit Example: 3.14 GiB

Types

type Collector

type Collector struct {
	Reader io.Reader
	// contains filtered or unexported fields
}

Collector collects data to send progress updates

func NewCollector

func NewCollector(reader io.Reader, pr *Reporter) *Collector

NewCollector creates a Collector

func (*Collector) Read

func (pc *Collector) Read(b []byte) (int, error)

Read satisfies the io.Reader interface; sends bytes read to the background process to be tracked

func (*Collector) ReceiveObject

func (pc *Collector) ReceiveObject(count, max uint32)

ReceiveObject sends an object to the background process to be tracked

func (*Collector) ResolveDelta

func (pc *Collector) ResolveDelta(count, max uint32)

ResolveDelta sends an object to the background process to be tracked

func (*Collector) Seek

func (pc *Collector) Seek(offset int64, whence int) (int64, error)

Seek satisfies the io.Seeker interface

func (*Collector) Start

func (pc *Collector) Start(ctx context.Context)

Start begins a background process that will send periodic progress updates

type CountingUpdate

type CountingUpdate struct {
	Type  UpdateType
	Count uint32
	Max   uint32
}

CountingUpdate holds the part and whole for calculating percentage of progress

type IECScale

type IECScale uint64

IECScale is a number used to represent bytes at various scales (GiB, MiB, KiB, bytes)

type Reporter

type Reporter struct {
	Receive      chan *Update
	UpdatePeriod time.Duration
	RatePeriod   time.Duration
}

Reporter sends digested progress updates

func NewReporter

func NewReporter(updatePeriod time.Duration, ratePeriod time.Duration) *Reporter

NewReporter creates a new Reporter

func (*Reporter) CreateCollector

func (r *Reporter) CreateCollector(reader io.Reader) *Collector

CreateCollector creates a new Collector that will report progress updates to this Reporter

type Throughput

type Throughput struct {
	CurrentTotal        uint64
	PreviousTotal       uint64
	PreviousNanoseconds uint64
	AverageBytes        uint64
	AverageMisecs       uint64   // a "misec" is 1/1024 sec
	LastBytes           []uint64 // size = 8
	LastMisecs          []uint64 // size = 8; "misec" is 1/1024 sec
	Index               uint32
}

Throughput calculates the rate that data is read

func NewThroughput

func NewThroughput() *Throughput

NewThroughput creates a new throughput

func (*Throughput) AdvanceBytesRead

func (t *Throughput) AdvanceBytesRead(bytesRead int)

AdvanceBytesRead tracks the number of bytes read

func (*Throughput) AdvanceTime

func (t *Throughput) AdvanceTime(now int64) uint64

AdvanceTime tracks the progress and returns the current rate of bytes being read SEE: https://github.com/git/git/blob/be8661a3286c67a5d4088f4226cbd7f8b76544b0/progress.c#L186-L244

type Update

type Update struct {
	Type          UpdateType
	Count         uint32
	Max           uint32
	BytesReceived uint64
	Rate          uint64
}

Update is what the consuming code will get notified with

func (*Update) BytesReceivedIEC

func (p *Update) BytesReceivedIEC() string

BytesReceivedIEC returns the IEC representation of BytesReceived, e.g. GiB, MiB, KiB

func (*Update) Percentage

func (p *Update) Percentage() float32

Percentage calculates the completion percentage

func (*Update) RateIEC

func (p *Update) RateIEC() string

RateIEC returns the IEC representation of Rate, e.g. GiB/s, MiB/s, KiB/s

func (*Update) String

func (p *Update) String() string

String honors the Stringer interface

type UpdateType

type UpdateType int

UpdateType is the type of progress update being sent

Jump to

Keyboard shortcuts

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