Documentation
¶
Overview ¶
Package fetch downloads one zip archive from the first of several hosts to respond, verifies its SHA-256 before extraction, and lands the extracted tree in the destination directory with one atomic rename.
The package knows nothing about what the archive holds: URL templates, platform names and version pins belong to the caller.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Zip ¶
Zip fetches the archive served at any of urls and extracts it into dir.
Every URL is probed concurrently and the first host to answer with the start of the archive is downloaded from; the others are fallbacks, in the order they answered, for a download that fails or does not match the expected digest. Extraction goes into a temporary sibling of dir that is renamed into place at the end, so dir either does not exist or is complete. A file lock next to dir serializes concurrent fetchers of the same directory; when dir already exists, Zip returns without a request.
Types ¶
type HashMismatchError ¶
HashMismatchError reports an archive whose SHA-256 differs from the one given with WithSHA256. Nothing was extracted from it.
func (*HashMismatchError) Error ¶
func (e *HashMismatchError) Error() string
type Logger ¶
type Logger interface {
Println(v ...any)
}
Logger receives one line per event: the host chosen, download progress, verification and extraction. A *log.Logger satisfies it.
type Option ¶
type Option func(*fetcher)
Option configures Zip.
func WithClient ¶
WithClient sets the HTTP client. The default is http.DefaultClient.
func WithLogger ¶
WithLogger sets where event lines go. The default discards them.
func WithSHA256 ¶
WithSHA256 sets the expected hex digest of the archive. The download is hashed as it streams and compared before the archive is opened; a mismatch fails with a *HashMismatchError. An empty digest means no verification, which the logger reports.
func WithStripFirstDir ¶
func WithStripFirstDir() Option
WithStripFirstDir expects the archive to hold exactly one top-level directory and makes that directory's content the destination, the way browser archives nest one folder.