Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteDownload ¶ added in v1.0.0
DeleteDownload removes the download folder.
Types ¶
type Download ¶
type Download struct { // ID is the task unique identifier. // It is used to allow the download of many files with the same name from different sources. // This field will be initialized on runtime. ID string `toml:"-"` // URL represents the url from which the manager will download the file. URL string `toml:"url"` // Name is the original filename. Name string `toml:"name"` // Size is the total file size in bytes. Size uint64 `toml:"size"` // IsResumable flags a download as resumable. // If false, the download will be automatically removed on cancellation. // This field will be initialized on runtime. IsResumable bool `toml:"-"` // Workers is the number of parallel connections configured for the manager. // Initially it is set by the user, but falls to 1 if the server does not accept range or does not provide a // content length. Workers []*Worker `toml:"workers"` }
Download stores the information relative to a download, including the workers.
func GetDownload ¶ added in v1.0.0
GetDownload gets a download by his id.
func ListDownloads ¶ added in v1.0.0
ListDownloads lists all the saved downloads.
func NewDownload ¶ added in v1.0.0
NewDownload fetches the download url, obtains all the information required to start a download and finally returns the download struct.
func (*Download) Execute ¶ added in v1.0.0
Execute downloads the specified file. This operation blocks the execution until it finishes or is cancelled by the context.
func (*Download) FolderPath ¶ added in v1.0.0
FolderPath gets the path to the download folder.
func (*Download) OutputFilePath ¶ added in v1.0.0
OutputFilePath returns the path of the download output.
type Worker ¶ added in v1.0.0
type Worker struct { // Index is the index of the worker. // During the merge process, the worker downloads will be concatenated using this index. Index uint16 `toml:"index"` // DownloadID stores the id of the download. DownloadID string `toml:"download_id"` // DownloadURL stores the url of the download. DownloadURL string `toml:"download_url"` // RangeFrom is the start point of the worker download. RangeFrom uint64 `toml:"range_from"` // RangeTo is the end position of the worker download. RangeTo uint64 `toml:"range_to"` }
Worker represents a goroutine in charge of downloading a file part/segment.
func NewWorker ¶ added in v1.0.0
func NewWorker(workerIndex uint16, totalWorkers uint16, downloadId string, downloadURL string, downloadSize uint64) *Worker
NewWorker computes the start & end point of the worker download and returns a new worker.
func (*Worker) CurrentSize ¶ added in v1.0.0
CurrentSize returns the size of the worker file.
func (*Worker) DownloadSize ¶ added in v1.0.0
DownloadSize calculates the difference between the maximum and minimum range.
func (*Worker) Execute ¶ added in v1.0.0
Execute starts the download of the file slice. This operation is blocking and must be called inside a goroutine.