file_hashing/
lib.rs

1//! This crate will help you easily get hash from **files** or **folders**
2//!
3//! # Example
4//!
5//! ```no_run
6//! use std::path::PathBuf;
7//! use blake2::{Blake2s256, Digest};
8//! use file_hashing::get_hash_file;
9//!
10//! let path = PathBuf::from("/home/gladi/test-hashing.txt");
11//!
12//! let mut hash = Blake2s256::new();
13//! let result = get_hash_file(&path, &mut hash).unwrap();
14//!
15//! assert_eq!(result.len(), 64); // Blake2s256 len == 64
16//! ```
17//!
18//! P.S. If the examples from the documentation **do not work**, then you need to look at the **unit tests**
19
20pub(crate) mod encoding;
21pub mod file;
22pub mod folder;
23pub mod fs;
24
25use digest::DynDigest;
26use std::io::Error as IOError;
27use std::io::ErrorKind as IOErrorKind;
28use std::path::Path;
29
30pub use file::{get_hash_file, get_hash_files};
31pub use folder::{get_hash_folder, get_hash_folders};
32
33const PAGE_SIZE: usize = 4096;
34
35/// Information about progress
36///
37/// # Example
38///
39/// ```no_run
40/// use file_hashing::ProgressInfo;
41///
42/// let value_files = 300;
43/// let info = ProgressInfo::Yield(1); // Just use a function that accepts **progress**
44///
45/// match info {
46///     ProgressInfo::Yield(done_files) => println!("done files {}/{}", done_files, value_files),
47///     ProgressInfo::Error(error) => println!("error: {}", error),
48/// }
49/// ```
50pub enum ProgressInfo {
51    /// How many files have we processed
52    Yield(u64),
53
54    /// Runtime error log
55    Error(IOError),
56}