# hashdir2
A fast, parallel, multi-algorithm directory hashing library and CLI.
`hashdir2` provides both a library and a command-line tool for hashing directories
recursively using multiple algorithms. It is designed to be efficient, deterministic,
and suitable for use in automated environments such as CI/CD pipelines.
## Overview
- Recursive directory traversal
- Parallel hashing using [rayon](https://github.com/rayon-rs/rayon)
- Multiple algorithms: SHA-2, BLAKE2, BLAKE3, MD5
- Memory-mapped I/O for large files
- Deterministic output
- Optional CLI with progress indication and verification
> [!IMPORTANT]
> This library is very raw and there are could be some critical bugs not found yet. Keep that in mind when working with it.
## Installation
### Library
Add to `Cargo.toml`:
```toml
[dependencies]
hashdir2 = "0.1"
````
### Command-line tool
To install the CLI binary:
```bash
cargo install hashdir2
```
After installation:
```bash
hashdir2 --help
```
## Example (library)
```rust
use hashdir2::hash::blake3::Blake3Hasher;
use hashdir2::walk::{DirHasher, WalkEvent};
fn main() -> std::io::Result<()> {
let hasher = DirHasher::new(Blake3Hasher::new());
let root_hash = hasher.walk("./target", |event| {
if let WalkEvent::File { path, .. } = event {
println!("hashed: {}", path.display());
}
}, None)?;
println!("root hash: {:x?}", root_hash);
Ok(())
}
```
## Example (CLI)
Hash a directory:
```bash
hashdir2 /path/to/dir
```
Select algorithm:
```bash
hashdir2 --algo blake3 /path/to/dir
```
Verify against a known hash:
```bash
hashdir2 --verify expected.txt /path/to/dir
```
Output in base64:
```bash
hashdir2 --format base64 /path/to/dir
```
## Feature flags
| `default` | Enables the `cli` feature |
| `cli` | Enables the command-line interface and dependencies (`clap`, `indicatif`, `hex`, `base64`) |
Example disabling the CLI:
```toml
[dependencies]
hashdir2 = { version = "0.1", default-features = false }
```
## Roadmap?
- [ ] Cover everything with unit-tests to make the library behaviour more predictable
- [ ] Add glob pattern matching
- [ ] Add symlink follow behaviour
## License
Licensed under MIT license ([LICENSE](LICENSE.TXT))