Documentation
¶
Index ¶
- func SetDefaultConfig(newConfig Config)
- type Config
- type DownloadOptions
- type Downloader
- func Download(file string, reqURL string, options ...DownloadOptions) (*Downloader, error)
- func DownloadWithConfig(file string, reqURL string, config Config, options ...DownloadOptions) (*Downloader, error)
- func DownloadWithConfigAndContext(ctx context.Context, file string, reqURL string, config Config, ...) (*Downloader, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SetDefaultConfig ¶
func SetDefaultConfig(newConfig Config)
SetDefaultConfig sets the configuration that will be used by the Download function.
Types ¶
type Config ¶
Config contains the configuration for the downloader
func GetDefaultConfig ¶
func GetDefaultConfig() Config
GetDefaultConfig returns a copy of the default configuration. The default configuration can be changed using the SetDefaultConfig function.
type DownloadOptions ¶
type DownloadOptions int
DownloadOptions are optional flags that can be passed to Download function
const ( // NoResume will not try to resume a partial download NoResume DownloadOptions = iota )
type Downloader ¶
type Downloader struct { URL string Done chan bool Resp *http.Response // contains filtered or unexported fields }
Downloader is an asynchronous downloader
func Download ¶
func Download(file string, reqURL string, options ...DownloadOptions) (*Downloader, error)
Download returns an asynchronous downloader that will download the specified url in the specified file. A download resume is tried if a file shorter than the requested url is already present.
func DownloadWithConfig ¶
func DownloadWithConfig(file string, reqURL string, config Config, options ...DownloadOptions) (*Downloader, error)
DownloadWithConfig applies an additional configuration to the http client and returns an asynchronous downloader that will download the specified url in the specified file. A download resume is tried if a file shorter than the requested url is already present.
func DownloadWithConfigAndContext ¶ added in v2.2.0
func DownloadWithConfigAndContext(ctx context.Context, file string, reqURL string, config Config, options ...DownloadOptions) (*Downloader, error)
DownloadWithConfigAndContext applies an additional configuration to the http client and returns an asynchronous downloader that will download the specified url in the specified file. A download resume is tried if a file shorter than the requested url is already present. The download can be cancelled using the provided context.
func (*Downloader) AsyncRun ¶
func (d *Downloader) AsyncRun()
AsyncRun starts the downloader copy-loop. This function is supposed to be run on his own go routine because it sends a confirmation on the Done channel
func (*Downloader) Completed ¶
func (d *Downloader) Completed() int64
Completed returns the bytes read so far
func (*Downloader) Error ¶
func (d *Downloader) Error() error
Error returns the error during download or nil if no errors happened
func (*Downloader) Run ¶
func (d *Downloader) Run() error
Run starts the downloader and waits until it completes the download.
func (*Downloader) RunAndPoll ¶
func (d *Downloader) RunAndPoll(poll func(current int64), interval time.Duration) error
RunAndPoll starts the downloader copy-loop and calls the poll function every interval time to update progress.