Expand description
This crate provides a convenient interface for calculating hash digests on the fly while writing data to a writer. It supports various hash algorithms, and the library is designed to be easy to use.
§Setup
To use this crate, add the following entry to your Cargo.toml file in the dependencies section:
[dependencies]
chksum-writer = "0.1.0"Alternatively, you can use the cargo add subcommand:
cargo add chksum-writer§Features
§Asynchronous Runtime
async-runtime-tokio: Enables async interface for Tokio runtime.
By default, neither of these features is enabled.
§Usage
ⓘ
use std::io::{self, Write};
use chksum_md5::MD5;
use chksum_writer::Writer;
fn main() -> io::Result<()> {
// Create a new writer with the MD5 hash algorithm
let mut writer = Writer::<_, MD5>::new(io::stdout());
// Write data to the writer
writer.write_all(b"example data")?;
// Get the calculated digest
let digest = writer.digest();
// Print the digest (hex representation)
println!("Digest: {}", digest);
Ok(())
}§Implementations
This crate should be used along with a hash implementation crate.
Various crates implement their own Writer, which can be enabled with the writer Cargo feature.
§License
This crate is licensed under the MIT License.
Structs§
- Async
Writer async-runtime-tokio - Wraps a reader and calculates the hash digest on the fly.
- Writer
- Wraps a writer and calculates the hash digest on the fly.
Functions§
- async_
new async-runtime-tokio - Creates new
AsyncWriter. - async_
with_ hash async-runtime-tokio - Creates new
AsyncWriterwith provided hash. - new
- Creates new
Writer. - with_
hash - Creates new
Writerwith provided hash.