Open ErQrYfkrju opened 4 years ago
https://stackoverflow.com/questions/48533445/proper-way-to-hash-a-reader-in-rust I know there is a question here.. Could you, please, point the right way to get hash from this wrapper
Sorry, I missed this the first time around!
use std::fs::File;
use twox_hash::XxHash64;
fn main() {
let mut f = File::open("/etc/hosts").expect("Unable to open file");
let hasher = XxHash64::with_seed(0);
let mut hw = HashWriter(hasher);
io::copy(&mut f, &mut hw).expect("Unable to copy data");
let hasher = hw.0;
println!("{}", hasher.finish());
}
See also https://github.com/shepmaster/twox-hash/blob/master/src/bin/hash_file.rs
I've updated the SO answer as well.
use hasher as writer to calculate hash