| Crates.io | fileparthasher |
| lib.rs | fileparthasher |
| version | 0.0.4 |
| created_at | 2025-05-14 20:08:34.81836+00 |
| updated_at | 2025-05-20 16:01:18.588996+00 |
| description | File hasher to calculate the hash for a section of a file, the hash is `u64` size. The `Write` trait was implemented for it. |
| homepage | |
| repository | https://github.com/0xAA55-rs/fileparthasher |
| max_upload_size | |
| id | 1673925 |
| size | 31,632 |
A Rust library to compute a 64-bit unsigned integer (u64) hash for a specific section of a file. Implements the Write trait for incremental hashing.
The hash algorithm is std::hash::DefaultHasher.
Use FileHasher::new() to create an instance. Write data into it, and each write operation updates the hash value. Once all data is written, the final u64 hash is generated.
Key features:
Write trait.use std::fs::File;
use std::io::{Read, Seek};
use fileparthasher::FileHasher;
fn main() -> std::io::Result<()> {
let mut file = File::open("large_file.bin")?;
let mut hasher = FileHasher::new();
// Hash bytes 100 to 200 (inclusive)
let hash = hasher.hash(&mut file, 100, 100)?;
println!("Hash: {:x}", hash);
Ok(())
}
Write Traituse std::io::{Write, Read, Seek};
use fileparthasher::FileHasher;
let mut hasher = FileHasher::new();
hasher.write_all(b"Hello, ")?;
hasher.write_all(b"world!")?;
let hash = hasher.finish(); // Get the hash after all writes
hash()fn hash<R>(mut self, reader: &mut R, from_byte: u64, length: u64) -> io::Result<u64> where R: Read + Seek;
reader: A readable and seekable input source (e.g., file).from_byte: Starting byte offset (0-based).length: Number of bytes to hash.