Expand description
A simple downloader library designed to be used in Applications with support to cache downloaded assets.
§Features
- Async
- Cache downloaded file in a directory in filesystem.
- Check if a file is available in cache.
- Uses SHA256 for verifying cached files.
- Optional support to download files without caching.
§Sample Usage
#[tokio::main]
async fn main() {
let downloader = bb_downloader::Downloader::new("/tmp").unwrap();
let sha = [0u8; 32];
let url = "https://example.com/img.jpg";
// Download with just URL
downloader.download(url, None).await.unwrap();
// Check if the file is in cache
assert!(downloader.check_cache_from_url(url).is_some());
// Will fetch directly from cache instead of re-downloading
downloader.download(url, None).await.unwrap();
// Will fetch directly from cache instead of re-downloading
assert!(!downloader.check_cache_from_sha(sha).await.is_some());
// Will re-download the file
downloader.download_with_sha(url, sha, None).await.unwrap();
assert!(downloader.check_cache_from_sha(sha).await.is_some());
}Structs§
- Downloader
- Simple downloader that caches files in the provided directory. Uses SHA256 to determine if the file is already downloaded.
Traits§
- IntoUrl
- A trait to try to convert some type into a
Url.