20
\brief Destroys the downloader.
22
The destructor implicitly calls close() if it has not been called already.
26
Downloader(Downloader const&) = delete;
27
Downloader& operator=(Downloader const&) = delete;
28
Downloader(Downloader&&);
29
Downloader& operator=(Downloader&&);
31
typedef std::unique_ptr<Downloader> UPtr;
34
\brief Returns a file descriptor that is open for reading.
36
To download the file contents, read from the returned file descriptor. The descriptor
37
may not be able to deliver arbitrarily large amounts of data without blocking. If the
38
code that reads from the descriptor cannot block, use non-blocking reads. Once the
39
descriptor indicates EOF, call close() to check for errors.
41
\return A file descriptor open for reading. If fd() is called after close() or cancel()
42
have been called, the return value is `-1`.
43
\throws TODO: All sorts of exceptions when things go wrong, list them.
48
\brief Finalizes the download.
50
Once the descriptor returned by fd() indicates EOF, you must call close(). The runtime
51
closes the descriptor and calls close_callback once the state of the download has been verified.
52
Call DownloadResult::check_error() from the callback to verify whether the download completed successfully.
54
If a read on the descriptor returns an error, this indicates a fatal error condition, and further
55
reads on the descriptor will fail as well. In this case, a call to close() results in close_callback()
56
being invoked as usual, and DownloadResult::check_error() will return the error details
59
\param close_callback The functor called by the runtime once the download is finalized.
60
The passed value must not be `nullptr`.
61
\warning Do not assume that a download completed successfully once you detect EOF on the file descriptor.
62
If something goes wrong during a download on the server side, the file descriptor will return EOF
63
for a partially-downloaded file.
65
void close(std::function<void(DownloadResult const&)> close_callback);
68
\brief Cancels a download.
70
Calling cancel() informs the provider that the download is no longer needed. The provider
71
will make a best-effort attempt to cancel the download from the remote service.
73
Calling cancel() more than once, or calling cancel() after a call to close() is safe and does nothing.
74
\throws TODO: All sorts of things.
84
} // namespace storage