progress

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package progress provides progress tracking functionality for downloads.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager provides advanced progress tracking with moving averages and chunk tracking.

func NewManager

func NewManager() *Manager

NewManager creates a new progress manager.

func (*Manager) GetProgress

func (m *Manager) GetProgress() ProgressInfo

GetProgress returns the current progress.

func (*Manager) Start

func (m *Manager) Start()

Start starts the progress manager with rate limiting.

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops the progress manager.

func (*Manager) Update

func (m *Manager) Update(downloaded, total int64)

Update updates the download progress.

func (*Manager) UpdateChunks

func (m *Manager) UpdateChunks(complete, total int)

UpdateChunks updates chunk completion status.

type Progress

type Progress struct {
	// TotalBytes is the total size of the download in bytes.
	// Set to -1 if unknown.
	TotalBytes int64

	// DownloadedBytes is the number of bytes downloaded so far.
	DownloadedBytes int64

	// Speed is the current download speed in bytes per second.
	Speed int64

	// StartTime is when the download started.
	StartTime time.Time

	// LastUpdate is when the progress was last updated.
	LastUpdate time.Time
	// contains filtered or unexported fields
}

Progress represents the current state of a download operation.

func NewProgress

func NewProgress(totalBytes int64, callback ProgressCallback) *Progress

NewProgress creates a new Progress instance with the specified parameters.

func (*Progress) ForceUpdate

func (p *Progress) ForceUpdate(downloadedBytes int64)

ForceUpdate forces an immediate progress update, bypassing rate limiting.

func (*Progress) GetSnapshot

func (p *Progress) GetSnapshot() ProgressSnapshot

GetSnapshot returns a thread-safe snapshot of the current progress state.

func (*Progress) Update

func (p *Progress) Update(downloadedBytes int64)

Update updates the progress with new downloaded bytes count. It calculates speed and calls the callback if rate limiting allows it.

type ProgressCallback

type ProgressCallback func(bytesDownloaded, totalBytes int64, speed int64)

type ProgressInfo

type ProgressInfo struct {
	TotalBytes      int64
	DownloadedBytes int64
	Speed           int64
	TimeRemaining   time.Duration
	ChunksComplete  int
	TotalChunks     int
	StartTime       time.Time
	LastUpdateTime  time.Time
}

ProgressInfo represents detailed progress information.

type ProgressReader

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

ProgressReader wraps an io.Reader to track progress as data is read.

func NewProgressReader

func NewProgressReader(
	reader io.Reader,
	totalBytes int64,
	callback ProgressCallback,
) *ProgressReader

NewProgressReader creates a new ProgressReader that wraps the given reader.

func (*ProgressReader) GetProgress

func (pr *ProgressReader) GetProgress() *Progress

GetProgress returns the underlying progress tracker.

func (*ProgressReader) Read

func (pr *ProgressReader) Read(p []byte) (n int, err error)

Read reads data from the underlying reader and updates progress.

type ProgressSnapshot

type ProgressSnapshot struct {
	TotalBytes      int64
	DownloadedBytes int64
	Speed           int64
	StartTime       time.Time
	LastUpdate      time.Time
}

ProgressSnapshot represents a point-in-time snapshot of progress data.

func (ProgressSnapshot) ETA

func (ps ProgressSnapshot) ETA() time.Duration

ETA returns the estimated time to completion. Returns -1 if total size is unknown or speed is zero.

func (ProgressSnapshot) Elapsed

func (ps ProgressSnapshot) Elapsed() time.Duration

Elapsed returns the time elapsed since the download started.

func (ProgressSnapshot) Percentage

func (ps ProgressSnapshot) Percentage() float64

Percentage returns the completion percentage (0-100). Returns -1 if total size is unknown.

func (ProgressSnapshot) String

func (ps ProgressSnapshot) String() string

String returns a human-readable representation of the progress.

type RateLimiter

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

RateLimiter controls the frequency of progress updates to avoid overwhelming the callback with too many updates.

func NewRateLimiter

func NewRateLimiter(interval time.Duration) *RateLimiter

NewRateLimiter creates a new rate limiter with the specified minimum interval.

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow() bool

Allow returns true if enough time has passed since the last update.

Jump to

Keyboard shortcuts

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