progress

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2025 License: Apache-2.0, Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const MinBytesForUpdate = 1024 * 1024 // 1MB

MinBytesForUpdate defines the minimum number of bytes that need to be transferred before sending a progress update

View Source
const UpdateInterval = 100 * time.Millisecond

UpdateInterval defines how often progress updates should be sent

Variables

This section is empty.

Functions

func NewReader

func NewReader(r io.Reader, updates chan<- v1.Update) io.Reader

NewReader returns a reader that reports progress to the given channel while reading.

func NewReaderWithOffset added in v1.0.4

func NewReaderWithOffset(r io.Reader, updates chan<- v1.Update, initialOffset int64) io.Reader

NewReaderWithOffset returns a reader that reports progress starting from an initial offset. This is useful for resuming interrupted downloads.

func PullMsg

func PullMsg(update v1.Update) string

func PushMsg

func PushMsg(update v1.Update) string

func WriteError

func WriteError(w io.Writer, message string) error

WriteError writes an error message

func WriteProgress

func WriteProgress(w io.Writer, msg string, imageSize, layerSize, current uint64, layerID string) error

WriteProgress writes a progress update message

func WriteSuccess

func WriteSuccess(w io.Writer, message string) error

WriteSuccess writes a success message

func WriteWarning added in v1.0.4

func WriteWarning(w io.Writer, message string) error

WriteWarning writes a warning message

Types

type Layer

type Layer struct {
	ID      string // Layer ID
	Size    uint64 // Layer size
	Current uint64 // Current bytes transferred
}

type Message

type Message struct {
	Type    string `json:"type"`    // "progress", "success", "warning", or "error"
	Message string `json:"message"` // Deprecated: the message should be defined by clients based on Message.Total and Message.Layer
	Total   uint64 `json:"total"`
	Pulled  uint64 `json:"pulled"` // Deprecated: use Layer.Current
	Layer   Layer  `json:"layer"`  // Current layer information
}

Message represents a structured message for progress reporting

type Reader

type Reader struct {
	Reader       io.Reader
	ProgressChan chan<- v1.Update
	Total        int64
}

Reader wraps an io.Reader to track reading progress

func (*Reader) Read

func (pr *Reader) Read(p []byte) (int, error)

type Reporter

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

func NewProgressReporter

func NewProgressReporter(w io.Writer, msgF progressF, imageSize int64, layer v1.Layer) *Reporter

func (*Reporter) Updates

func (r *Reporter) Updates() chan<- v1.Update

Updates returns a channel for receiving progress Updates. It is the responsibility of the caller to close the channel when they are done sending Updates. Should only be called once per Reporter instance.

func (*Reporter) Wait

func (r *Reporter) Wait() error

Wait waits for the progress Reporter to finish and returns any error encountered.

Jump to

Keyboard shortcuts

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