download

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteDownload added in v1.0.0

func DeleteDownload(downloadID string) error

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

func GetDownload(downloadID string) (*Download, error)

GetDownload gets a download by his id.

func ListDownloads added in v1.0.0

func ListDownloads() ([]*Download, error)

ListDownloads lists all the saved downloads.

func NewDownload added in v1.0.0

func NewDownload(downloadURL string, totalWorkers uint16) (*Download, error)

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

func (d *Download) Execute(ctx context.Context) error

Execute downloads the specified file. This operation blocks the execution until it finishes or is cancelled by the context.

func (*Download) FilePath added in v1.0.0

func (d *Download) FilePath() string

FilePath gets the path to the download TOML file.

func (*Download) FolderPath added in v1.0.0

func (d *Download) FolderPath() string

FolderPath gets the path to the download folder.

func (*Download) OutputFilePath added in v1.0.0

func (d *Download) OutputFilePath() string

OutputFilePath returns the path of the download output.

func (*Download) String added in v1.0.0

func (d *Download) String() string

String returns a pretty string with the download's information.

func (*Download) Writer added in v1.0.0

func (d *Download) Writer() (io.WriteCloser, error)

Writer opens the output file in write-only mode.

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

func (w *Worker) CurrentSize() uint64

CurrentSize returns the size of the worker file.

func (*Worker) DownloadSize added in v1.0.0

func (w *Worker) DownloadSize() uint64

DownloadSize calculates the difference between the maximum and minimum range.

func (*Worker) Execute added in v1.0.0

func (w *Worker) Execute(ctx context.Context, bar *pb.ProgressBar) error

Execute starts the download of the file slice. This operation is blocking and must be called inside a goroutine.

func (*Worker) FilePath added in v1.0.0

func (w *Worker) FilePath() string

FilePath returns the worker file path.

func (*Worker) Reader added in v1.0.0

func (w *Worker) Reader() (io.ReadCloser, error)

Reader opens the worker file in read-only mode.

func (*Worker) Writer added in v1.0.0

func (w *Worker) Writer() (io.WriteCloser, error)

Writer opens the worker file in append-write-only mode.

Jump to

Keyboard shortcuts

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