download

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package download fetches the files that Golet keeps in the user's cache: the native libraries plugins name in their golet-plugin.json, which the CLI and unpackaged programs download into <cache>/golet/natives/<sha256>/, and the tools the CLI runs, as NSIS. Every download checks the file's SHA-256, tries again when the host fails in passing, and processes that need one file at once (two apps, `go test` running packages side by side) download it once, one after the other.

Index

Constants

This section is empty.

Variables

View Source
var Backoff = []time.Duration{time.Second, 2 * time.Second, 4 * time.Second}

Backoff is how long Get waits before each new attempt after a transient failure: 5xx, 408 and 429 responses, and connections that fail or break off. Hosts like GitHub's release downloads answer 502 and 504 now and then, and the next request succeeds.

Functions

func Cached

func Cached(ctx context.Context, f File, path string) error

Cached makes the file path hold f, downloading it when it is missing or differs, executable, as native libraries are. It holds a lock on the directory of path while it checks and downloads, so that processes that need the file at the same time download it once: the first downloads it and renames it into place, the others wait for it, then find it there.

Without the lock, each would rename its own download onto path, and on Windows renaming onto a file that another process has open or loaded, or is renaming itself, fails with "Access is denied".

func Check

func Check(path, sum string) bool

Check reports whether the file path exists and has the SHA-256 sum.

func FileSHA256

func FileSHA256(path string) (string, error)

FileSHA256 returns the SHA-256 of a file, in hex.

func Get

func Get(ctx context.Context, f File, path string) error

Get downloads f into the file path, which it creates or truncates, and checks its SHA-256. It tries again, after Backoff, when an attempt fails in passing (see transient); the error is the last attempt's.

func Lock

func Lock(path string, wait func()) (unlock func(), err error)

Lock takes an exclusive lock on the file path, which it creates, and returns what releases it. When another process (or another call) holds it, Lock calls wait, if set, then waits for it. The system releases the lock too when the process ends, so a process that dies downloading leaves no stale lock behind.

Types

type File

type File struct {
	URL string
	// SHA256 is the file's SHA-256 in lowercase hex.
	SHA256 string
	// Client sends the requests; nil means http.DefaultClient.
	Client *http.Client
	// Header is added to every request.
	Header http.Header
	// Progress, when set, returns where each attempt copies what arrives
	// too, given the length the response announces (or -1).
	Progress func(total int64) io.Writer
}

File is a file to download.

type StatusError

type StatusError struct {
	URL    string
	Code   int
	Status string
}

StatusError is a response other than 200 OK.

func (*StatusError) Error

func (e *StatusError) Error() string

Jump to

Keyboard shortcuts

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