Finds the blake3 hash of files or entire directories using a multithreaded merkle tree algorithm.
To use this crate, add merkle_hash
as a dependency to your project's Cargo.toml
:
toml
[dependencies]
merkle_hash = "2"
The following code demonstrates how to create a merkle tree of paths and hashes and then traverse it, executing a closure for each path and hash:
```rust,norun use merklehash::merkle_tree::MerkleTree;
let merkletree=MerkleTree::new("/provided/path").unwrap(); let traverseresult=merkletree.traverse(&|path,hash|{ println!("{}: {}",path.absolutepath,hash); Ok(()) }); ```
The following code demonstrates how to create a merkle tree of paths and hashes and then collapse it into a BTreeSet or a HashSet which can then be traversed linearly:
```rust,norun use merklehash::merkle_tree::MerkleTree;
let merkletree=MerkleTree::new("/provided/path").unwrap(); let converttobtreeset=true; if converttobtreeset{ let btreeset=merkletree.collapseintotreeset(); }else{ let hashset=merkletree.collapseintohash_set(); } ```
The following code demonstrates how to use the merkle hash function to get a single merkle hash from a few blake3 hashes:
```rust,norun use blake3::hash; use merklehash::merkleutils::computemerkle_hash;
let firsthash = hash(b"foo"); let secondhash = hash(b"bar"); let thirdhash = hash(b"baz"); let fourthhash = hash(b"cow"); let hashes = vec![firsthash, secondhash, thirdhash, fourthhash];
let merklehash = computemerkle_hash(&hashes); ```