downloader

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDownloadInProgress = errors.New("download already in progress")
	ErrFileNotFound       = errors.New("file not found")
	ErrSourceNotFound     = errors.New("source not found")
)

Functions

This section is empty.

Types

type DownloadProgress

type DownloadProgress struct {
	FileID       string    `json:"fileId"`
	FileName     string    `json:"fileName"`
	BytesWritten int64     `json:"bytesWritten"`
	TotalBytes   int64     `json:"totalBytes"`
	StartedAt    time.Time `json:"startedAt"`
	Speed        float64   `json:"speed"` // bytes per second
}

DownloadProgress represents the progress of a single download

func (*DownloadProgress) ETA

func (p *DownloadProgress) ETA() time.Duration

ETA returns the estimated time remaining

func (*DownloadProgress) Percent

func (p *DownloadProgress) Percent() float64

Percent returns the download progress as a percentage

type Downloader

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

Downloader manages file downloads

func New

func New(db *database.DB, registry *sources.Registry, hooks *hooks.Manager, cfg *config.Config) *Downloader

New creates a new downloader

func (*Downloader) ActiveDownloads

func (d *Downloader) ActiveDownloads() []DownloadProgress

ActiveDownloads returns progress for all active downloads

func (*Downloader) Cancel

func (d *Downloader) Cancel(fileID string) error

Cancel cancels an in-progress download

func (*Downloader) Download

func (d *Downloader) Download(ctx context.Context, fileID string) error

Download starts downloading a file

func (*Downloader) GetProgress

func (d *Downloader) GetProgress(fileID string) *DownloadProgress

GetProgress returns progress for a specific download

type ProgressTracker

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

ProgressTracker tracks download progress for multiple files

func NewProgressTracker

func NewProgressTracker() *ProgressTracker

NewProgressTracker creates a new progress tracker

func (*ProgressTracker) Complete

func (pt *ProgressTracker) Complete(fileID string)

Complete removes a download from tracking

func (*ProgressTracker) Get

func (pt *ProgressTracker) Get(fileID string) *DownloadProgress

Get returns progress for a specific download

func (*ProgressTracker) GetAll

func (pt *ProgressTracker) GetAll() []DownloadProgress

GetAll returns progress for all active downloads

func (*ProgressTracker) Start

func (pt *ProgressTracker) Start(fileID, fileName string, totalBytes int64)

Start registers a new download

func (*ProgressTracker) Update

func (pt *ProgressTracker) Update(fileID string, bytesWritten, totalBytes int64)

Update updates progress for a download

Jump to

Keyboard shortcuts

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