download

package module
v0.0.0-...-7f9a90c Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2016 License: Apache-2.0 Imports: 22 Imported by: 65

README

go-download

Travis Appveyor Go Report Card Coverage GoDoc license

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// MkdirAll is used to create all intermediate directories if required.
	MkdirAll = Mkdirs(newBool(true))
	// MkdirNone is used to create no intermediate directories.
	MkdirNone = Mkdirs(newBool(false))
)

Functions

func FromURL

func FromURL(src *url.URL, w io.Writer, options Options) error

FromURL downloads the specified `src` URL to `w` writer using the specified `Options`.

func ToFile

func ToFile(src, dest string, options FileOptions) error

ToFile downloads the specified `src` URL to `dest` file using the specified `FileOptions`.

func ToWriter

func ToWriter(src string, w io.Writer, options Options) error

ToWriter downloads the specified `src` URL to `w` writer using the specified `Options`.

Types

type FileOptions

type FileOptions struct {
	// Options is the common set of downloader options.
	Options
	// Mkdirs is the option to create parent directories of target directory if they don't
	// exist. Use `download.MkdirAll` or `download.MkdirNone` (or any `*bool`). Defaults to
	// `download.MkdirAll`.
	Mkdirs Mkdirs
}

FileOptions holds the possible configuration options to download to a file.

type Mkdirs

type Mkdirs *bool

Mkdirs is a custom type so we can differentiate between not specified (nil) and set.

type Options

type Options struct {
	// HTTPClient is an optional client to perform downloads with. If nil, `http.DefaultClient`
	// will be used.
	HTTPClient *http.Client
	// Checksum is either a checksum string, or a URL or path to a file containing the checksum. The file
	// can either contain the checksum only or contain multiple lines of the format:
	// CHECKSUM FILENAME
	Checksum string
	// Checksum hash is the hash for the checksum. Currently only supports SHA1, SHA256, SHA512 and MD5.
	// If unspecified, defaults to SHA256.
	ChecksumHash crypto.Hash
	// ProgressBars is the configuration of progress bars output. Set to `nil` (default) to disable.
	ProgressBars *ProgressBarOptions
	// Retries is the number of retries for retriable errors. Defaults to 5 if unset. Set to -1 for
	// infinite retries.
	Retries int
	// RetryInterval is the interval between retries.
	RetryInterval time.Duration
}

Options holds the possible configuration options for the Downloader.

type ProgressBarOptions

type ProgressBarOptions struct {
	// Writer holds where to output the progress bars to. Defaults to `os.Stdout`.
	Writer io.Writer
	// Width is the maximum width of the progress bar. If output to a narrower terminal then this
	// will be ignored.
	MaxWidth int
}

ProgressBarOptions holds the configuration for progress bars if required.

Jump to

Keyboard shortcuts

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