downloader

package
v0.18.0-beta.0 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HideProgress bool

HideProgress is used only for testing

Functions

func Decompressor added in v0.15.1

func Decompressor(ext string) ([]string, bool)

func IsLocal added in v0.7.2

func IsLocal(s string) bool

Types

type Opt

type Opt func(*options) error

func WithCache

func WithCache() Opt

WithCache enables caching using filepath.Join(os.UserCacheDir(), "lima") as the cache dir.

func WithCacheDir

func WithCacheDir(cacheDir string) Opt

WithCacheDir enables caching using the specified dir. Empty value disables caching.

func WithDecompress added in v0.15.1

func WithDecompress(decompress bool) Opt

WithDecompress decompress the download from the cache.

func WithDescription added in v0.15.1

func WithDescription(description string) Opt

WithDecription adds a user description of the download.

func WithExpectedDigest

func WithExpectedDigest(expectedDigest digest.Digest) Opt

WithExpectedDigest is used to validate the downloaded file against the expected digest.

The digest is not verified in the following cases: - The digest was not specified. - The file already exists in the local target path.

When the `data` file exists in the cache dir with `<ALGO>.digest` file, the digest is verified by comparing the content of `<ALGO>.digest` with the expected digest string. So, the actual digest of the `data` file is not computed.

type Result

type Result struct {
	Status          Status
	CachePath       string // "/Users/foo/Library/Caches/lima/download/by-url-sha256/<SHA256_OF_URL>/data"
	ValidatedDigest bool
}

func Cached added in v0.18.0

func Cached(remote string, opts ...Opt) (*Result, error)

Cached checks if the remote resource is in the cache.

Download caches the remote resource if WithCache or WithCacheDir option is specified. Local files are not cached.

When the cache path already exists, Cached returns Result with StatusUsedCache.

func Download

func Download(local, remote string, opts ...Opt) (*Result, error)

Download downloads the remote resource into the local path.

Download caches the remote resource if WithCache or WithCacheDir option is specified. Local files are not cached.

When the local path already exists, Download returns Result with StatusSkipped. (So, the local path cannot be set to /dev/null for "caching only" mode.)

The local path can be an empty string for "caching only" mode.

type Status

type Status = string
const (
	StatusUnknown    Status = ""
	StatusDownloaded Status = "downloaded"
	StatusSkipped    Status = "skipped"
	StatusUsedCache  Status = "used-cache"
)

Jump to

Keyboard shortcuts

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