merkle_hash

Finds the blake3 hash of files or entire directories using a multithreaded merkle tree algorithm.

Documentation

docs.rs/merkle_hash

Usage

To use this crate, add merkle_hash as a dependency to your project's Cargo.toml:

toml [dependencies] merkle_hash = "1"

Example: Get the hash of a root directory using a merkle item

The following code creates a new merkle item with a given root directory path and then uses it to find the hash of that root:

```rust,norun use std::path::PathBuf; use merklehash::merkle_item::MerkleItem;

let path = PathBuf::from("/root/to/get/paths/from"); let merkleitem = MerkleItem::new(path); let merklehash = merkleitem.gethash(); ```

Example: Get the hash of a root directory using the merkle hashing functions

Using the utility functions instead of a merkle item to find the single hash of a root directory:

```rust,norun use std::path::Path; use merklehash::{getpaths,gethashes,findmerklehash};

let root = Path::new("/root/to/get/paths/from"); let paths = getpaths(root); let hashes = gethashes(&paths); let merklehash = findmerkle_hash(&hashes); ```

Example: Get the merkle hash of a collection of blake3 hashes

The following code demonstrates how to use the merkle hash function to get the single merkle hash from a few blake3 hashes:

```rust,norun use std::str::FromStr; use blake3::{hash,Hash}; use merklehash::merkleutils::findmerkle_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 = findmerkle_hash(&hashes); ```