pub fn get_hash_files<HashType, P>(
paths: &Vec<P>,
hash: &mut HashType,
num_threads: usize,
progress: impl Fn(ProgressInfo),
) -> Result<String, Error>
Expand description
Get hash from files
§Warning
if you want to get the hash from a folder then it’s better to use this function
If you can get all files from a folder with this function
§Example
use std::path::PathBuf;
use blake2::{Blake2s256, Digest};
use file_hashing::{get_hash_files, ProgressInfo};
use walkdir::WalkDir;
let walkdir = WalkDir::new("/home/gladi/Pictures");
let mut paths: Vec<PathBuf> = Vec::new();
for file in walkdir.into_iter().filter_map(|file| file.ok()) {
if file.metadata().unwrap().is_file() {
paths.push(file.into_path());
}
}
let mut hash = Blake2s256::new();
let result = get_hash_files(&paths, &mut hash, 4, |info| match info {
ProgressInfo::Yield(done_files) => {
println!("done files {}/{}", done_files, paths.len())
}
ProgressInfo::Error(error) => println!("error: {}", error),
})
.unwrap();
println!("result: {}", result);
assert_eq!(result.len(), 64); // Blake2s256 len == 64
§Error
- if the path variable is empty, the error IOErrorKind::InvalidInput will be returned