downloader

package
v0.0.0-...-56cb166 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrUnexpectedHash is returned when the hash of the downloaded resource
	// does not match the expected hash.
	ErrUnexpectedHash = errors.ConstError("downloaded resource has unexpected hash")

	// ErrUnexpectedSize is returned when the size of the downloaded resources
	// does not match the expected size.
	ErrUnexpectedSize = errors.ConstError("downloaded resource has unexpected size")
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DownloadClient

type DownloadClient interface {
	// Download retrieves the specified resource from the store and saves its
	// contents to the specified path. Read the path to get the contents of the
	// resource.
	Download(ctx context.Context, url *url.URL, path string, options ...charmhub.DownloadOption) (*charmhub.Digest, error)
}

DownloadClient describes the API exposed by the charmhub client.

type ResourceDownloader

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

ResourceDownloader implements store-agnostic download and persistence of charm blobs.

func NewResourceDownloader

func NewResourceDownloader(client DownloadClient, logger logger.Logger) *ResourceDownloader

NewResourceDownloader returns a new charm downloader instance.

func (*ResourceDownloader) Download

func (d *ResourceDownloader) Download(
	ctx context.Context,
	url *url.URL,
	sha384 string,
	size int64,
) (io.ReadCloser, error)

Download looks up the requested resource using the appropriate store, downloads it to a temporary file and returns a ReadCloser that deletes the temporary file on closure.

The resulting resource is verified to have the right hash and size.

Returns ErrUnexpectedHash if the hash of the downloaded resource does not match the expected hash. Returns ErrUnexpectedSize if the size of the downloaded resource does not match the expected size.

Jump to

Keyboard shortcuts

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