Crates.io | write-hasher |
lib.rs | write-hasher |
version | 0.1.2 |
source | src |
created_at | 2023-04-27 10:15:49.651527 |
updated_at | 2023-05-24 09:39:24.473854 |
description | Transparently calculate hash on (asynchronously) writing to an type |
homepage | https://github.com/uttarayan21/write-hasher |
repository | https://github.com/uttarayan21/write-hasher |
max_upload_size | |
id | 850220 |
size | 18,976 |
Hash the data being written to a writer.
Supports tokio::io::AsyncWrite
, futures::io::AsyncWrite
, std::io::Write
.
extern crate sha2;
use sha2::Sha256;
use write_hasher::WriteHasher;
let mut file = std::fs::File::open("Cargo.toml").unwrap();
let dest = std::io::sink();
let dest = WriteHasher::<Sha256, _>::new(dest);
std::io::copy(&mut file, &mut dest).unwrap();
let hash = dest.finalize();
You can use async functions as well as std functions for this as well.