downloader

package
v0.0.0-...-68d9d71 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSkipCurrent — user requested to skip the current download
	// (state is discarded, batch continues).
	ErrSkipCurrent = errors.New("skip current item")

	// ErrAbortBatch — user wants the entire batch to stop immediately
	// (state is saved when resumable, no further items are started).
	ErrAbortBatch = errors.New("abort batch")

	// ErrUserQuit — single-download equivalent of ErrAbortBatch.
	// State is saved when resumable.
	ErrUserQuit = errors.New("user quit")
)

Cancellation causes used as the second argument to context.CancelCauseFunc. Execute and the batch loop use these to distinguish user intent.

Functions

func DebugProbe

func DebugProbe(url string, skipTLS bool, proxyServer string, timeout time.Duration)

DebugProbe performs HEAD and a 0-0 Range GET to print diagnostics without downloading.

func DownloadSigFile

func DownloadSigFile(sigURL, destPath string, skipTLS bool, proxyServer string, timeout time.Duration) error

DownloadSigFile fetches the detached GPG signature file at sigURL and writes it to destPath. It reuses the same proxy/TLS settings as the main download.

func Execute

func Execute(ctx context.Context, url string, st *state.State, conn int, skiptls bool, proxyServer string, bwLimit string, timeout time.Duration) error

Execute downloads url, observing ctx for cancellation. Returns:

  • nil on success;
  • context.Cause(ctx) (one of ErrSkipCurrent, ErrAbortBatch, ErrUserQuit, or context.Canceled) when ctx was cancelled;
  • the underlying download/IO error on failure.

Execute always waits for every part goroutine to exit before returning, guaranteeing that no orphaned goroutines from the previous run can write into a future TUI session's ui.Program handle.

func PartCalculate

func PartCalculate(par int64, length int64, url string) []state.Part

PartCalculate splits the download into parts.

func ProxyAwareHTTPClient

func ProxyAwareHTTPClient(proxyServer string, skipTLS bool, timeout time.Duration) *http.Client

ProxyAwareHTTPClient returns an HTTP client that may use an HTTP or SOCKS5 proxy.

func ReconstructStateFromParts

func ReconstructStateFromParts(url string, skiptls bool, proxyServer string, timeout time.Duration) (*state.State, error)

ReconstructStateFromParts rebuilds a *State for a URL that has existing part files in the download folder but no state.json (e.g. killed with SIGKILL). It probes the server for the total content length, recalculates the original part boundaries, then advances RangeFrom by each part file's current size.

func RunVerify

func RunVerify(url string, skipTLS bool, proxyServer string, timeout time.Duration) (ok bool, detail string)

RunVerify downloads the .sig file for url and runs gpg --verify. It sends TUI messages when ui.Program is active (during the TUI alt-screen). It always returns (ok, detail) so the caller can print a post-TUI summary.

func VerifyGPGSignature

func VerifyGPGSignature(sigPath, filePath string) (string, error)

VerifyGPGSignature runs `gpg --verify sigPath filePath` and returns an error (including gpg's stderr output) when verification fails.

It passes --keyserver-options auto-key-retrieve so missing public keys are fetched automatically from the default keyserver. When the key still cannot be found (e.g. the keyserver is unreachable), the key fingerprint parsed from gpg output is included in the error so the caller can surface a manual hint.

Types

type HTTPDownloader

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

HTTPDownloader holds the required configurations.

func NewHTTPDownloader

func NewHTTPDownloader(url string, par int, skipTLS bool, proxyServer string, bwLimit string, timeout time.Duration) *HTTPDownloader

NewHTTPDownloader returns a configured HTTPDownloader ready to download url.

func NewHTTPDownloaderFromState

func NewHTTPDownloaderFromState(st *state.State, client *http.Client, proxyServer string, skipTLS bool, timeout time.Duration) *HTTPDownloader

NewHTTPDownloaderFromState rebuilds an HTTPDownloader from a saved State, applying the given connection settings. Used when resuming a download.

func (*HTTPDownloader) Do

func (d *HTTPDownloader) Do(doneChan chan bool, fileChan chan string, errorChan chan error, interruptChan chan bool, stateSaveChan chan state.Part)

Do is the main download entry point. It dispatches the download to multiple parts.

func (*HTTPDownloader) IsResumable

func (d *HTTPDownloader) IsResumable() bool

IsResumable reports whether this download supports resumption.

func (*HTTPDownloader) NumParts

func (d *HTTPDownloader) NumParts() int

NumParts returns the number of download parts.

Jump to

Keyboard shortcuts

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