downloader

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultProgress

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

DefaultProgress just shows the progress as a percentage.

func (*DefaultProgress) SetTotalBytes added in v0.0.2

func (dp *DefaultProgress) SetTotalBytes(totalBytes int64)

SetTotalBytes sets the total number of bytes to be downloaded.

func (*DefaultProgress) Write added in v0.0.2

func (dp *DefaultProgress) Write(p []byte) (int, error)

Write implements the io.Writer interface.

type Downloader

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

Downloader represents a downloader that can download files from a URL, and verify the checksum of the downloaded file.

func New

func New(
	dlDir string,
	httpClient *http.Client,
	fsys fs.FS,
	hasher Hasher,
	progressWriter ProgressWriter,
	verifier HashVerifier,
) (*Downloader, error)

New returns a new Downloader.

func (*Downloader) Download

func (dl *Downloader) Download(
	ctx context.Context, url, filename, hashPath string,
) error

Download downloads a file from a URL, and verifies the checksum of the downloaded file.

type HashVerifier

type HashVerifier interface {
	// Verify ensure the checksum of the given io.Reader
	//  matches the given hash.
	Verify(in io.Reader, want string) error
}

HashVerifier is an interface to verify a file's checksum.

type Hasher

type Hasher interface {
	// Hash returns the checksum at the given path.
	// path can be a local file containing the checksum
	// or a remote URL to download the checksum from.
	Hash(ctx context.Context, path string) (string, error)
}

Hasher is an interface to retrieve a file's checksum.

type ProgressBar added in v0.0.2

type ProgressBar struct {
	*progressbar.ProgressBar
}

func (*ProgressBar) SetTotalBytes added in v0.0.2

func (pb *ProgressBar) SetTotalBytes(totalBytes int64)

type ProgressWriter added in v0.0.2

type ProgressWriter interface {
	io.Writer
	// Progress reports the progress of a download.
	SetTotalBytes(totalBytes int64)
}

Progresser is an interface to report the progress of a download.

Jump to

Keyboard shortcuts

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