Expand description
This crate provides a convenient interface for calculating hash digests on the fly while reading data from a reader. 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-reader = "0.1.0"
Alternatively, you can use the cargo add
subcommand:
cargo add chksum-reader
§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, Read};
use chksum_md5::MD5;
use chksum_reader::Reader;
fn main() -> io::Result<()> {
// Create a new reader with the MD5 hash algorithm
let mut reader = Reader::<_, MD5>::new(io::stdin());
// Read data from the reader
let mut buffer = Vec::new();
reader.read_to_end(&mut buffer)?;
// Get the calculated digest
let digest = reader.digest();
// Print the digest (hex representation)
println!("Digest: {}", digest.to_hex_lowercase());
Ok(())
}
§Implementations
This crate should be used along with a hash implementation crate.
Various crates implement their own Reader
, which can be enabled with the reader
Cargo feature.
§License
This crate is licensed under the MIT License.
Structs§
- Async
Reader async-runtime-tokio
- Wraps a reader and calculates the hash digest on the fly.
- Reader
- Wraps a reader and calculates the hash digest on the fly.
Functions§
- async_
new async-runtime-tokio
- Creates new
AsyncReader
. - async_
with_ hash async-runtime-tokio
- Creates new
AsyncReader
with provided hash. - new
- Creates new
Reader
. - with_
hash - Creates new
Reader
with provided hash.