pub fn generate_stream<T: Read + ?Sized>(
context: &Context,
from: &mut T,
) -> Result<(usize, String), Error>Expand description
Generate kana hash from a stream of bytes with this digest.
ยงExample
To generate a hash from a file with the default digest
fn hash_file(file_name: impl AsRef<Path>) -> String
{
let mut file = OpenOptions::new()
.read(true)
.open(file_name).expect("Failed to open file");
let file_size = file.metadata().expect("Failed to stat file").len();
let (bytes_read, hash) = generate_stream(&Default::default(), &mut file).expect("Failed to generate hash from file");
assert_eq!(bytes_read as u64, file_size, "Failed to read whole file");
hash
}