Crate chksum_writer

Source
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§

AsyncWriterasync-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_newasync-runtime-tokio
Creates new AsyncWriter.
async_with_hashasync-runtime-tokio
Creates new AsyncWriter with provided hash.
new
Creates new Writer.
with_hash
Creates new Writer with provided hash.