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

progress

package
v0.33.13 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DirectionDownload = Direction{
	ActiveWord:   "Downloading",
	DoneWord:     "Download complete",
	WaitResource: "DataExport",
	PastVerb:     "downloaded",
}

DirectionDownload is the default direction: docker-pull-style download wording, used by `d8 snapshot download`.

View Source
var DirectionUpload = Direction{
	ActiveWord:   "Uploading",
	DoneWord:     "Upload complete",
	WaitResource: "DataImport",
	PastVerb:     "uploaded",
}

DirectionUpload is the direction used by `d8 snapshot upload`.

Functions

This section is empty.

Types

type Direction

type Direction struct {
	// ActiveWord is the state word shown while a stream is actively
	// transferring, e.g. "Downloading" or "Uploading".
	ActiveWord string
	// DoneWord is the state word shown for a stream that finished after
	// Activate was called, e.g. "Download complete" or "Upload complete".
	DoneWord string
	// WaitResource names the resource a waiting stream is blocked on
	// ("DataExport" or "DataImport"), interpolated into the
	// direction-independent "Waiting for %s to be Ready" template.
	WaitResource string
	// PastVerb is the lower-case past-tense verb used in the non-TTY
	// aggregate line, e.g. "downloaded" or "uploaded".
	PastVerb string
}

Direction supplies the direction-specific wording rendered by stateWord and the non-TTY aggregate line. It deliberately covers ONLY the words that differ between a download and an upload; "Already exists" (resume skip) and "Interrupted" (Fail) are direction-independent and stay hard-coded in stateWord regardless of Direction.

type Option

type Option func(*sinkConfig)

Option configures the progress Sink constructor.

func WithDirection

func WithDirection(d Direction) Option

WithDirection sets the direction-specific wording (see Direction) rendered by the returned Sink. Default is DirectionDownload, so a caller downloading may omit this option entirely.

func WithInterval

func WithInterval(d time.Duration) Option

WithInterval sets the periodic reporting interval for the non-TTY fallback sink. Default is 2 seconds.

type Sink

type Sink interface {
	// NewStream registers a named stream with a known total byte count.
	// A total of 0 is allowed when the size is not yet known; call SetTotal later.
	NewStream(name string, total int64) Stream

	// SetVolumeTotal sets M, the total number of volume streams this run will
	// download, for the live "N/M volumes downloaded" counter.
	SetVolumeTotal(n int)

	// Wait blocks until all streams have finished and flushes remaining output.
	Wait()

	// LogWriter returns an io.Writer that is safe to use for log output while
	// the sink is active. For the TTY sink it returns a writer whose writes are
	// coordinated with the mpb renderer, so log lines print cleanly above the
	// live bars instead of corrupting their cursor accounting (which otherwise
	// makes the bar re-print as multiple blocks). For the plain (non-TTY) sink
	// it returns os.Stderr, preserving the existing logging behaviour.
	LogWriter() io.Writer
}

Sink is a multi-bar progress container for concurrent byte-stream transfers. NewStream creates a per-stream progress handle; Wait drains all rendering and emits a final aggregate line (non-TTY) or waits for bar completion (TTY).

func New

func New(w io.Writer, tty bool, opts ...Option) Sink

New constructs a Sink. When tty is true it returns an mpb/v8-backed multi-bar renderer writing to w with one docker-pull-style row per stream (no aggregate summary header). When tty is false it returns a plain-log fallback that writes "downloaded X / total Y" aggregate lines (humanised via decor.SizeB1024) to w on a periodic interval and always emits a final deterministic line on Wait(). The rendered wording (both TTY state words and the non-TTY past-tense verb) follows cfg.direction, which defaults to DirectionDownload; pass WithDirection(DirectionUpload) for an upload-flavored Sink.

type Stream

type Stream interface {
	// IncrBy advances the stream's byte counter by n.
	IncrBy(n int)

	// SetTotal updates the stream's expected total byte count.
	SetTotal(total int64)

	// SetCurrent sets the stream's current byte counter to an absolute value.
	// It exists for the pipeline's resume-seed clamp: when a resume seed
	// credited from stale on-disk state (a chunk geometry about to be purged,
	// or a stale sizes sidecar) exceeds the fresh authoritative total — a
	// volume shrunk between runs — downloadBlock/downloadFS call
	// SetCurrent(0) to reset the displayed value to 0 BEFORE lowering the
	// total, so the bar never renders current > total. It is an absolute
	// DOWNWARD correction only; ordinary forward progress is reported with
	// IncrBy, never with SetCurrent.
	SetCurrent(current int64)

	// Activate transitions the stream from waiting to downloading state.
	// For the TTY sink it flips the bar from "waiting for export…" to the live
	// byte-counter display. For the plain (non-TTY) sink it is a no-op.
	// Must be called exactly once after the DataExport becomes ready, before
	// byte transfer begins.
	Activate()

	// Done marks the stream as successfully complete and counts it toward the
	// "N/M volumes downloaded" completion total. If Fail was already called on
	// this stream, Done is a no-op (the first terminal call wins; see Fail).
	Done()

	// Fail marks the stream as terminated WITHOUT completing successfully (the
	// underlying transfer was cancelled or errored, or the stream's DataExport
	// never became ready). Unlike Done, a failed stream is excluded from the
	// "N/M volumes downloaded" / "(N/M volumes)" completion counters, so M (the
	// total) stays correct but a failed stream never counts as one of the N
	// completions. Fail still unblocks Wait() the same way Done does, and may be
	// called from the waiting state (before Activate) or the active state.
	// If Done was already called on this stream, Fail is a no-op (the first
	// terminal call wins; see Done).
	Fail()
}

Stream is a per-stream progress handle returned by Sink.NewStream.

Jump to

Keyboard shortcuts

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