blake 3 instead of blake 2
This commit is contained in:
parent
6966b141da
commit
0b41b34c45
@ -6,6 +6,7 @@ authors = ["Sam Hadow"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
blake2 = "0.10.6"
|
blake2 = "0.10.6"
|
||||||
|
blake3 = "1.8.1"
|
||||||
clap = { version = "4.4.6", features = ["derive"] }
|
clap = { version = "4.4.6", features = ["derive"] }
|
||||||
rayon = "1.8.0"
|
rayon = "1.8.0"
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ use std::fs;
|
|||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
// hash
|
// hash
|
||||||
use blake2::{Blake2b512, Digest};
|
use blake3::Hasher;
|
||||||
use std::io::{BufReader, Read};
|
use std::io::{BufReader, Read};
|
||||||
|
|
||||||
// parallelism
|
// parallelism
|
||||||
@ -18,7 +18,7 @@ use std::sync::{Arc, Mutex};
|
|||||||
impl FileTree {
|
impl FileTree {
|
||||||
/// Find duplicates in a directory (including sub-directories).
|
/// Find duplicates in a directory (including sub-directories).
|
||||||
///
|
///
|
||||||
/// If path exist in tree, find duplicates using Blake2b512. If 2 (or more) files have the same hash they're duplicates.
|
/// If path exist in tree, find duplicates using Blake3. If 2 (or more) files have the same hash they're duplicates.
|
||||||
///
|
///
|
||||||
/// returns a `Vec` containing a `Vec<PathBuf>` for each group of duplicates.
|
/// returns a `Vec` containing a `Vec<PathBuf>` for each group of duplicates.
|
||||||
///
|
///
|
||||||
@ -52,7 +52,7 @@ impl FileTree {
|
|||||||
// parallelized loop
|
// parallelized loop
|
||||||
intersection.par_iter().for_each(|item| {
|
intersection.par_iter().for_each(|item| {
|
||||||
if let Ok(file) = fs::File::open(item) {
|
if let Ok(file) = fs::File::open(item) {
|
||||||
let mut hasher = Blake2b512::new();
|
let mut hasher = Hasher::new();
|
||||||
|
|
||||||
// sizable buffer
|
// sizable buffer
|
||||||
let mut buffer = [0; 8192];
|
let mut buffer = [0; 8192];
|
||||||
@ -69,8 +69,9 @@ impl FileTree {
|
|||||||
hasher.update(&buffer[..count]);
|
hasher.update(&buffer[..count]);
|
||||||
}
|
}
|
||||||
|
|
||||||
let hash = hasher.finalize();
|
let mut hash = hasher.finalize_xof();
|
||||||
let hash_bytes: [u8; 32] = hash.as_slice()[..32].try_into().unwrap();
|
let mut hash_bytes: [u8; 32] = [0; 32];
|
||||||
|
hash.fill(&mut hash_bytes);
|
||||||
|
|
||||||
// Use a Mutex to update HashMap in parallel
|
// Use a Mutex to update HashMap in parallel
|
||||||
let mut locked_hashes = hashes.lock().unwrap();
|
let mut locked_hashes = hashes.lock().unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user