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
:
toml
[dependencies]
merkle_hash = "3.5"
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.Get the master hash of a directory tree:
```rust,norun use merklehash::{Algorithm, MerkleTree};
let tree = MerkleTree::builder("/path/to/directory") .algorithm(Algorithm::Blake3) .hashnames(false) .build()?; let masterhash = tree.root.item.hash; ```
Iterate over a directory tree, getting the hash of each file and directory:
```rust,norun use merklehash::{bytestohex, MerkleTree};
let tree = MerkleTree::builder("/path/to/directory").build()?; for item in tree { println!("{}: {}", item.path.relative, bytestohex(item.hash)); } ```
Collapse the tree into any linear collection:
```rust,norun use std::collections::BTreeSet; use merklehash::{MerkleItem, MerkleTree};
let tree = MerkleTree::builder("/path/to/directory").build()?;
let btreeset: BTreeSet
Licensed under MIT license.