Finds the hashes of all files and directories in a directory tree.
To use this crate, add merkle_hash
as a dependency to your project's Cargo.toml
:
[dependencies]
merkle_hash = "3.7"
sha
- Add this cargo feature to include SHA-256
and SHA-512
as hashing algorithms.parallel
- Enabled by default, this feature makes the crate utilize all available threads.encode
- Enabled by default, this feature adds the bytes_to_hex
and to_hex_string
functions.retain
- Disabled by default, this feature duplicates the children paths of directories upon traversal.Get the master hash of a directory tree:
use merkle_hash::{Algorithm, MerkleTree};
let tree = MerkleTree::builder("/path/to/directory")
.algorithm(Algorithm::Blake3)
.hash_names(false)
.build()?;
let master_hash = tree.root.item.hash;
Iterate over a directory tree, getting the hash of each file and directory:
use merkle_hash::{Encodable, MerkleTree};
let tree = MerkleTree::builder("/path/to/directory").build()?;
for item in tree {
println!("{}: {}", item.path.relative, item.hash.to_hex_string());
}
Collapse the tree into any linear collection:
use std::collections::BTreeSet;
use merkle_hash::{MerkleItem, MerkleTree};
let tree = MerkleTree::builder("/path/to/directory").build()?;
let btree_set: BTreeSet<MerkleItem> = tree.into_iter().collect();
IndexingError
type.Licensed under MIT license.