downloader

package
v0.0.0-...-4bd6544 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2016 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHTTPBlobOpener

func NewHTTPBlobOpener(hostnameVerification utils.SSLHostnameVerification) func(*url.URL) (io.ReadCloser, error)

NewHTTPBlobOpener returns a blob opener func suitable for use with Download. The opener func uses an HTTP client that enforces the provided SSL hostname verification policy.

func NewSha256Verifier

func NewSha256Verifier(expected string) func(*os.File) error

NewSha256Verifier returns a verifier suitable for Request. The verifier checks the SHA-256 checksum of the file to ensure that it matches the one returned by the provided func.

Types

type Download

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

Download can download a file from the network.

func StartDownload

func StartDownload(req Request, openBlob func(*url.URL) (io.ReadCloser, error)) *Download

StartDownload starts a new download as specified by `req` using `openBlob` to actually pull the remote data.

func (*Download) Done

func (dl *Download) Done() <-chan Status

Done returns a channel that receives a status when the download has completed or is aborted. Exactly one Status value will be sent for each download once it finishes (successfully or otherwise) or is aborted.

It is the receiver's responsibility to handle and remove the downloaded file.

func (*Download) Wait

func (dl *Download) Wait() (string, error)

Wait blocks until the download finishes (successfully or otherwise), or the download is aborted. There will only be a filename if err is nil.

type Downloader

type Downloader struct {
	// OpenBlob is the func used to gain access to the blob, whether
	// through an HTTP request or some other means.
	OpenBlob func(*url.URL) (io.ReadCloser, error)
}

Downloader provides the functionality for downloading files.

func New

func New(args NewArgs) *Downloader

New returns a new Downloader for the given args.

func (Downloader) Download

func (dlr Downloader) Download(req Request) (string, error)

Download starts a new download, waits for it to complete, and returns the local name of the file. The download can be aborted by closing the Abort channel in the Request provided.

func (Downloader) Start

func (dlr Downloader) Start(req Request) *Download

Start starts a new download and returns it.

type NewArgs

type NewArgs struct {
	// HostnameVerification is that which should be used for the client.
	// If it is disableSSLHostnameVerification then a non-validating
	// client will be used.
	HostnameVerification utils.SSLHostnameVerification
}

NewArgs holds the arguments to New().

type Request

type Request struct {
	// URL is the location from which the file will be downloaded.
	URL *url.URL

	// TargetDir is the directory into which the file will be downloaded.
	// It defaults to os.TempDir().
	TargetDir string

	// Verify is used to ensure that the download result is correct. If
	// the download is invalid then the func must return errors.NotValid.
	// If no func is provided then no verification happens.
	Verify func(*os.File) error

	// Abort is a channel that will cancel the download when it is closed.
	Abort <-chan struct{}
}

Request holds a single download request.

type Status

type Status struct {
	// Filename is the name of the file which holds the downloaded
	// data on success.
	Filename string

	// Err describes any error encountered while downloading.
	Err error
}

Status represents the status of a completed download.

Jump to

Keyboard shortcuts

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