downloader

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckReachable

func CheckReachable(ctx context.Context, cfg *config.Config, rawURL string, headers map[string]string) (bool, string)

CheckReachable performs a quick HEAD to determine network reachability to the resource. It returns reachable=true when an HTTP response is received regardless of status code. Only network errors (DNS failure, connect timeout, etc.) cause reachable=false.

func ComputeRemoteSHA256

func ComputeRemoteSHA256(ctx context.Context, cfg *config.Config, rawURL string, headers map[string]string) (string, error)

ComputeRemoteSHA256 streams the content at URL and computes its SHA256 without saving to disk. This fully downloads the resource, so it can be slow and bandwidth-heavy.

func StagePartPath

func StagePartPath(cfg *config.Config, url, dest string) string

StagePartPath is an exported helper for UI components to locate the .part file for an in-progress download, consistent with downloader behavior.

Types

type Auto

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

Auto implements Interface by delegating to the chunked downloader which already contains robust fallback to the single-stream downloader. This centralizes the selection logic behind Interface.

func NewAuto

func NewAuto(c *config.Config, l *logging.Logger, st *state.DB, m interface {
	AddBytes(int64)
	IncRetries(int64)
	IncDownloadsSuccess()
	ObserveDownloadSeconds(float64)
	Write() error
}) *Auto

func (*Auto) Download

func (a *Auto) Download(ctx context.Context, url, destPath, expectedSHA string, headers map[string]string, noResume bool) (string, string, error)

type Chunked

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

func NewChunked

func NewChunked(cfg *config.Config, log *logging.Logger, st *state.DB, m interface {
	AddBytes(int64)
	IncRetries(int64)
	IncDownloadsSuccess()
	ObserveDownloadSeconds(float64)
	Write() error
}) *Chunked

func (*Chunked) Download

func (e *Chunked) Download(ctx context.Context, url, destPath, expectedSHA string, headers map[string]string, noResume bool) (string, string, error)

Download orchestrates a chunked download if possible; otherwise falls back to single-stream.

type Interface

type Interface interface {
	Download(ctx context.Context, url, destPath, expectedSHA string, headers map[string]string, noResume bool) (finalPath string, sha256 string, err error)
}

Interface is the common downloader interface used across implementations.

type ProbeMeta

type ProbeMeta struct {
	FinalURL     string
	Filename     string
	Size         int64
	ETag         string
	LastModified string
	AcceptRange  bool
}

func ProbeURL

func ProbeURL(ctx context.Context, cfg *config.Config, rawURL string, headers map[string]string) (ProbeMeta, error)

ProbeURL queries metadata for a URL using a HEAD request, with fallbacks to a small Range GET and one-step redirect resolution. It returns filename (from Content-Disposition when present), final URL after redirects, size (if known), and other useful headers.

type Single

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

func NewSingle

func NewSingle(cfg *config.Config, log *logging.Logger, st *state.DB, m interface {
	AddBytes(int64)
	IncDownloadsSuccess()
	ObserveDownloadSeconds(float64)
	Write() error
}) *Single

func (*Single) Download

func (s *Single) Download(ctx context.Context, url, destPath, expectedSHA string, headers map[string]string, noResume bool) (string, string, error)

Download downloads a single file from url to destPath. If destPath is empty, it uses cfg.General.DownloadRoot + last URL segment. It resumes if a .part file exists and the server supports Range requests.

Jump to

Keyboard shortcuts

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