Use an external crate for fetching files
To reduce the burden of development on this project, I'm declaring an opportunity to offload the podcast-downloader
functionality to an external crate dedicated to fetching files, async-fetcher. It's a crate that provides a state machine API for constructing futures to fetch files using a provided reqwest::async::Client
.
The API is still an early work in progress, though it has integration tests to test out various aspects of the current API against a static Actix-based HTTP server. It's being created to be used as the foundation for an apt
replacement for Pop!_OS, and any other project which we may want to use it in to optionally and asynchronously fetch and validate files from HTTP/s servers.
I believe usage here would be as simple as:
let future = AsyncFetcher::new(&client, url)
// If the file exists and the mtime + len is the
// same as the server, then it will not be
// downloaded.
.request_to_path(final_destination)
// Commits the download to the given partial dest.
.then_download(partial_destination)
// On success, rename to final destination.
.then_rename()
// Get the future for the state machine at this point.
.into_future();
let result = runtime.block_on(future);
The API can be tweaked for any missing functionality. Progress callbacks aren't yet supported, but should be trivial to implement.
It would be possible to have an external thread receiving file-fetching requests via a tokio-channel
channel, and then handling these requests asynchronously, or asynchronously and in parallel.