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 directory using a single function

The following code shows the simplest way to get the merkle hash of a directory:

```rust,norun use merklehash::merkleutils::getmerkle_hash;

let merklehash = getmerkle_hash("/root/to/get/paths/from"); ```

Example: Get the hash of a directory using a combination of the utility functions

The following code shows the more complicated way to get the merkle hash:

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

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

Example: Get the 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 blake3::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); ```

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

The following code uses a merkle item to find the merkle hash of a directory, you may want to use a merkle item if you want access to more of its functions such as getting all of its direct descendants and more:

```rust,norun use merklehash::merkle_item::MerkleItem;

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