| Crates.io | bb-downloader |
| lib.rs | bb-downloader |
| version | 0.2.0 |
| created_at | 2025-03-18 11:09:38.663982+00 |
| updated_at | 2025-03-29 10:33:37.24362+00 |
| description | A simple async downloader for applications |
| homepage | |
| repository | https://openbeagle.org/ayush1325/bb-imager-rs |
| max_upload_size | |
| id | 1596503 |
| size | 59,972 |
A simple downloader library with support for caching. It is designed to be used with applications requiring the downloaded assets to be cached in file system.
#[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();
// Since it was cached by URL, will fail with SHA256.
assert!(!downloader.check_cache_from_sha(sha).is_some());
// Will re-download the file
downloader.download_with_sha(url, sha, None).await.unwrap();
assert!(downloader.check_cache_from_sha(sha).is_some());
}