downloader

package module
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: BSD-3-Clause Imports: 7 Imported by: 4

README

go.bug.st/downloader/v2 build status codecov

A simple HTTP/S file downloader for golang.

Documentation

Index

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

type Config struct {
	HttpClient http.Client
}

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) Close

func (d *Downloader) Close() error

Close the download

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.

func (*Downloader) Size

func (d *Downloader) Size() int64

Size return the size of the download

Jump to

Keyboard shortcuts

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