downloader

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNetworkConnection = errors.New("network connection error")
	ErrHTTPStatus        = errors.New("HTTP error")
	ErrResumeFailed      = errors.New("resume failed")
	ErrSHAValidation     = errors.New("SHA validation failed")
)

Sentinel errors for type checking

Functions

func CacheFilename added in v0.7.0

func CacheFilename(url string) string

CacheFilename returns the computed filename for the url.

func Download

func Download(host hostActions, r Request) (string, error)

Download downloads file at url and returns the location of the downloaded file.

func DownloadToGuest added in v0.7.0

func DownloadToGuest(host hostActions, guest guestActions, r Request, filename string) error

DownloadToGuest downloads file at url and saves it in the destination.

In the implementation, the file is downloaded (and cached) on the host, but copied to the desired destination for the guest. filename must be an absolute path and a directory on the guest that does not require root access.

Types

type DownloadOptions added in v0.10.0

type DownloadOptions struct {
	URL            string
	DestPath       string
	ExpectedETag   string // for resume validation
	ResumeFromByte int64  // byte offset to resume from
	ShowProgress   bool
}

DownloadOptions configures a download operation

type DownloadResult added in v0.10.0

type DownloadResult struct {
	FinalURL   string // After following redirects
	ETag       string // For future resume validation
	TotalBytes int64
	WasResumed bool
}

DownloadResult contains metadata about the completed download

type HTTPClient added in v0.10.0

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

HTTPClient encapsulates HTTP download operations

func NewHTTPClient added in v0.10.0

func NewHTTPClient() *HTTPClient

NewHTTPClient creates a configured HTTP client

func (*HTTPClient) Download added in v0.10.0

func (h *HTTPClient) Download(ctx context.Context, opts DownloadOptions) (*DownloadResult, error)

Download performs a file download with optional resume support

func (*HTTPClient) Fetch added in v0.10.0

func (h *HTTPClient) Fetch(ctx context.Context, url string) ([]byte, error)

Fetch downloads content from a URL and returns it as bytes (for small files like SHA checksums)

func (*HTTPClient) GetFinalURL added in v0.10.0

func (h *HTTPClient) GetFinalURL(ctx context.Context, rawURL string) (string, error)

GetFinalURL follows redirects and returns the final URL

type HTTPStatusError added in v0.10.0

type HTTPStatusError struct {
	StatusCode int
	Status     string
	URL        string
}

HTTPStatusError represents HTTP error responses

func (*HTTPStatusError) Error added in v0.10.0

func (e *HTTPStatusError) Error() string

func (*HTTPStatusError) Unwrap added in v0.10.0

func (e *HTTPStatusError) Unwrap() error

type NetworkError added in v0.10.0

type NetworkError struct {
	Op  string // "connect", "resolve", "download"
	URL string
	Err error
}

NetworkError wraps network-related errors with user-friendly messages

func (*NetworkError) Error added in v0.10.0

func (e *NetworkError) Error() string

func (*NetworkError) Unwrap added in v0.10.0

func (e *NetworkError) Unwrap() error

type Request added in v0.6.0

type Request struct {
	URL string // request URL
	SHA *SHA   // shasum url
}

Request is download request

type ResumeError added in v0.10.0

type ResumeError struct {
	Reason string
	URL    string
}

ResumeError indicates a failed resume attempt

func (*ResumeError) Error added in v0.10.0

func (e *ResumeError) Error() string

func (*ResumeError) Unwrap added in v0.10.0

func (e *ResumeError) Unwrap() error

type ResumeInfo added in v0.10.0

type ResumeInfo struct {
	ETag         string `json:"etag"`
	BytesWritten int64  `json:"bytes_written"`
}

ResumeInfo stores metadata for resumable downloads

type SHA added in v0.6.0

type SHA struct {
	Digest string // shasum
	URL    string // url to download the shasum file (if Digest is empty)
	Size   int    // one of 256 or 512
}

SHA is the shasum of a file.

func (SHA) ValidateFile added in v0.8.1

func (s SHA) ValidateFile(host hostActions, file string) error

ValidateFile validates the SHA of the file. The host parameter is kept for API compatibility but is not used.

type SHAValidationError added in v0.10.0

type SHAValidationError struct {
	File     string
	Expected string
	Actual   string
	Size     int // 256 or 512
}

SHAValidationError indicates checksum mismatch

func (*SHAValidationError) Error added in v0.10.0

func (e *SHAValidationError) Error() string

func (*SHAValidationError) Unwrap added in v0.10.0

func (e *SHAValidationError) Unwrap() error

Jump to

Keyboard shortcuts

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