Crate chksum_reader

source ·
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.0.0"

Alternatively, you can use the cargo add subcommand:

cargo add chksum-reader

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

  • Wraps a reader and calculates the hash digest on the fly.

Functions