Class Downloader

Class Documentation

class Downloader

A tool to download things.

A Downloader manages Download using aria2 in the background. Downloader is threadsafe. However, the returned Downloads are NOT threadsafe.

Public Types

typedef std::vector<std::pair<std::string, std::string>> Options

Public Functions

explicit Downloader(std::string sessionFileDir)
virtual ~Downloader()
void close()
std::shared_ptr<Download> startDownload(const std::string &uri, const std::string &downloadDir, Options options = {})

Start a new download.

This method is thread safe and returns a pointer to a newly created Download or an existing one with a matching URI. In the latter case the options parameter is ignored, which can lead to surprising results. For example, if the old and new download requests (sharing the same URI) have different values for the download directory or output file name options, after the download is reported to be complete the downloaded file will be present only at the location specified for the first request.

User should call update on the returned Download to have an accurate status.

Parameters:
  • uri – The uri of the thing to download.

  • downloadDir – The download directory where the thing should be stored (takes precedence over any “dir” in options).

  • options – A series of pair <option_name, option_value> to pass to aria.

Returns:

: The newly created Download.

std::shared_ptr<Download> getDownload(const std::string &did)

Get a download corrsponding to a download id (did) User should call update on the returned Download to have an accurate status.

Parameters:

did – The download id to search for.

Throws :

Returns:

: The Download corresponding to did.

size_t getNbDownload() const

Get the number of downloads currently managed.

std::vector<std::string> getDownloadIds() const

Get the ids of the managed downloads.