down

package module
v0.0.0-...-5bd9e97 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2018 License: MIT Imports: 5 Imported by: 0

README

Down is a lightweight library for downloading files in Golang.

https://godoc.org/github.com/gsamokovarov/down

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Blob

type Blob interface {
	io.ReadCloser

	// Location is the location of the file. Can be an absolute path, can be a
	// remote URL or can be empty if it's not representable.
	Location() string

	// Release frees up the file. If it's stored on disk, this will mean removing
	// the file from it.
	Release() error
}

Blob is a downloaded file. It can be physically stored on disk or streamed remotely as being read.

Once done Read-ing the blob make sure to either Close or Release it. Close will close the file, while Release will clean it up (delete it) if its already stored.

type Downloader

type Downloader interface {
	Download(string) (Blob, error)
}

Downloader downloads an URL into a Blob.

func NewFileDownloader

func NewFileDownloader(dir string, client ...*http.Client) Downloader

NewFileDownloader downloads an URL to a file. A directory has to be specified for the file to be stored in. Can be used for temporary file downloads if dir is os.TempDir.

func NewStreamDownloader

func NewStreamDownloader(client ...*http.Client) Downloader

NewStreamDownloader downloads an URL on demand. This downloader won't save the file on disk, but will stream it directly as the blob is read. Can be used to download a remote file from one location and upload it to another remote one.

type Error

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

Error is a download error.

func (*Error) Error

func (e *Error) Error() string

Jump to

Keyboard shortcuts

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