download

package
v0.0.0-...-8b1022e Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2016 License: Apache-2.0, Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Download

type Download struct {
	// net/http.Client to use when downloading the update.
	// If nil, a default http.Client is used
	HttpClient *http.Client

	// As bytes are downloaded, they are written to Target.
	// Download also uses the Target's Seek method to determine
	// the size of partial-downloads so that it may properly
	// request the remaining bytes to resume the download.
	Target Target

	// Progress returns the percentage of the download
	// completed as an integer between 0 and 100
	Progress chan (int)

	// HTTP Method to use in the download request. Default is "GET"
	Method string

	// HTTP URL to issue the download request to
	Url string
}

Download encapsulates the state and parameters to download content from a URL which:

- Publishes the percentage of the download completed to a channel. - May resume a previous download that was partially completed.

Create an instance with the New() factory function.

func New

func New(url string, target Target) *Download

New initializes a new Download object which will download the content from url into target.

func (*Download) Get

func (d *Download) Get() (err error)

Get() downloads the content of a url to a target destination.

Only HTTP/1.1 servers that implement the Range header support resuming a partially completed download.

On success, the server must return 200 and the content, or 206 when resuming a partial download. If the HTTP server returns a 3XX redirect, it will be followed according to d.HttpClient's redirect policy.

type FileTarget

type FileTarget struct {
	*os.File
}

func (*FileTarget) Size

func (t *FileTarget) Size() (int, error)

type MemoryTarget

type MemoryTarget struct {
	bytes.Buffer
}

func (*MemoryTarget) Size

func (t *MemoryTarget) Size() (int, error)

type Target

type Target interface {
	io.Writer
	Size() (int, error)
}

A Target is what you can supply to Download, it's just an io.Writer with a Size() method so that the a Download can "resume" an interrupted download

Jump to

Keyboard shortcuts

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