download

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: BSD-3-Clause Imports: 9 Imported by: 3

README

download

A library to implement fast downloading, with concurrency.

godoc

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoData       = errors.New("nothing to download")
	ErrNoGoroutines = errors.New("MaxGoroutines should be positive")
)
View Source
var DefaultOptions = &Options{
	Separator:     "/",
	MaxAttempts:   3,
	MaxGoroutines: 64,
}

Default Options

Functions

This section is empty.

Types

type DL

type DL struct {
	Client *http.Client
	Write  sync.Mutex
}

DL is the downloader.

func New

func New() *DL

New DL instance.

func (*DL) Chan

func (dl *DL) Chan(data Interface, ch chan FileBuffer, opt *Options) error

Chan will download data, and send results to a channel. The channel will be closed before returning.

func (*DL) Tar

func (dl *DL) Tar(data Interface, file *os.File, opt *Options) error

Tar downloads data to a tarball at file.

type File

type File struct {
	Path, Name, URL string
}

File to download. URL is where to get the data, path is where to store it.

type FileBuffer

type FileBuffer struct {
	File
	Buffer *bytes.Buffer
}

FileBuffer is a File with its data downloaded to Buffer.

type Interface

type Interface interface {
	URLs() []File
}

A type that satisfies download.Interface can be downloaded with download.Tar etc.

type Options

type Options struct {
	// Separator to use between files, eg you can use "_" for a flat
	// file structure, or leave the default "/" to have dirs.
	Separator string

	// Max attempts trying to download a file
	MaxAttempts int

	// Concurrent mode
	Concurrent bool
	// Max number of gorountines to spawn
	MaxGoroutines int
}

Options for the downloader.

Jump to

Keyboard shortcuts

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