hristogochev / merkle_hash

Finds the hashes of all files and directories in a directory tree
https://crates.io/crates/merkle_hash
MIT License
16 stars 2 forks source link

merkle_hash

Finds the hashes of all files and directories in a directory tree.

Usage

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

[dependencies]
merkle_hash = "3.7"

Features

Limitations

Optional

Examples

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();

Release notes for 3.7

Versioning

Used technologies

License

Licensed under MIT license.