| Crates.io | dwutil |
| lib.rs | dwutil |
| version | 0.1.3 |
| created_at | 2025-08-02 11:25:39.062155+00 |
| updated_at | 2025-08-10 14:53:41.383475+00 |
| description | simple and easy use downloader |
| homepage | |
| repository | https://github.com/prefix63/dwutil |
| max_upload_size | |
| id | 1778751 |
| size | 87,463 |
A Rust library for downloading, verifying, decompressing, and storing files in a concurrent and customizable way.
Supports:
ureq)indicatif)| Feature | Purpose |
|---|---|
sha |
Add support to sha1 and sha2 hashing |
md5 |
Add support to md5 hashing |
zip |
Add support to zip decompression |
tar |
Add support to tar decompression |
targz |
Add support to tar gz decompression |
tarxz |
Add support to tar xz decompression |
gz |
Add support to gzip decompression |
xz |
Add support to xz decompression |
indicatif |
Add indicatif indicator bar |
# Cargo.toml
[dependencies]
dwutil = "0.0.1"
use dwutil::{Downloader, File, Decompression};
fn main() -> Result<(), String> {
let file = File::new("https://example.com/archive.tar.gz")
.with_path("downloads/archive.tar.gz")
.with_size(1024 * 1024) // Optional
.with_decompression(Decompression::new::<TarGzFactory>() // Your custom decoder type
.with_dst("extracted/")
.with_exclude("README.txt")
);
Downloader::new(MyIndicatorFactory::default())
.with_file(file)
.start()
}
The File struct represents a downloadable file.
use sha2::Sha256;
let file = File::new("https://example.com/file.zip")
.with_path("files/file.zip")
.with_size(1_000_000)
.with_hash(Hash::new::<Sha256>("expected_hash"))
.with_decompression(decompression)
.with_store(store);
.with_size(size) โ expected file size.with_hash(hash) โ expected hash for integrity check.with_decompression(...) โ automatically extract after download.with_store(...) โ store using content-addressable logicSet how to decompress the file and where to extract it:
let decompression = Decompression::new::<ZipDecoder>()
.with_dst("output/")
.with_exclude("docs/README.md");
.zip, .tar.gz, .xz, .gzYou can validate files using several hash types (e.g., SHA1, SHA256, MD5):
use dwutil::hash::Hash;
use sha2::Sha256;
let file = file.with_hash(Hash::new::<Sha256>("hex_hash_string"));
If the downloaded file doesn't match the hash, it will return an error.
Use a CAS to deduplicate and organize files by content:
use dwutil::cas::default::DefaultStore;
let store = Arc::new(DefaultStore::new("objects"));
let file = file.with_store(store.clone());
Files will be stored in the store instead of the provided path.
You can implement your own progress UI using the Indicator and IndicatorFactory traits.
Example using indicatif:
use dwutil::indicator::indicatif::IndicatifFactory;
// Use the default style bar
let factory = IndicatifFactory::new();
let dw = Downloader::new(factory);
By default the crate provides, a SilentFactory indicator and a LogFactory indicator
You can download several files at once with concurrency:
Downloader::new(SilentFactory::new())
.with_files(vec![file1, file2, file3])
.with_max_current_downloads(3)
.start()?;
Unit tests can be added inside the tests module and will run with:
cargo test
| Module | Purpose |
|---|---|
cas |
Store files using content-addressable methods |
decompress |
Decode and extract various archive types |
hash |
File hashing (SHA1, SHA256, MD5, etc.) |
indicator |
Progress bars, logging, error reporting |
utils |
Internal tools for copying, paths, etc. |
MIT