Crates.io | merkle_hash |
lib.rs | merkle_hash |
version | 3.7.0 |
source | src |
created_at | 2022-03-18 21:56:07.542912 |
updated_at | 2024-08-02 03:43:50.677869 |
description | Finds the hashes of all files and directories in a directory tree. |
homepage | https://github.com/hristogochev/merkle_hash |
repository | https://github.com/hristogochev/merkle_hash |
max_upload_size | |
id | 552922 |
size | 27,795 |
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
:
[dependencies]
merkle_hash = "3.7"
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.encode
- Enabled by default, this feature adds the bytes_to_hex
and to_hex_string
functions.retain
- Disabled by default, this feature duplicates the children paths of directories upon traversal.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();
IndexingError
type.Licensed under MIT license.