Skip to main content

Module hash

Module hash 

Source

Structs§

CheckOptions
Options for check mode.
CheckResult
Result of check mode verification.

Enums§

HashAlgorithm
Supported hash algorithms.

Functions§

blake2b_hash_data
Hash raw data with BLAKE2b variable output length. output_bytes is the output size in bytes (e.g., 32 for 256-bit).
blake2b_hash_file
Hash a file with BLAKE2b variable output length. Single open + fstat. Uses read() for small files, streaming read+hash for large.
blake2b_hash_reader
Hash a reader with BLAKE2b variable output length. Uses thread-local 1MB buffer for cache-friendly streaming.
blake2b_hash_stdin
Hash stdin with BLAKE2b variable output length. Tries fadvise if stdin is a regular file (shell redirect), then streams.
check_file
Verify checksums from a check file. Each line should be “hash filename” or “hash *filename” or “ALGO (filename) = hash”.
estimate_total_size
Estimate total file size for parallel/sequential decision. Uses a quick heuristic: samples first file and extrapolates. Returns 0 if estimation fails.
hash_bytes
Compute hash of a byte slice directly (zero-copy fast path).
hash_file
Hash a file by path. Single open + fstat to minimize syscalls. Uses read() for small files, streaming read+hash for large files. Replaced mmap with read()+fadvise for better cache behavior: read() keeps data hot in L2/L3 cache, while mmap suffers page table and TLB overhead for sequential single-pass workloads.
hash_reader
Compute hash of data from a reader, returning hex string.
hash_stdin
Hash stdin. Uses fadvise for file redirects, streaming for pipes.
parse_check_line
Parse a checksum line in any supported format.
parse_check_line_tag
Parse a BSD-style tag line: “ALGO (filename) = hash” Returns (expected_hash, filename, optional_bits). bits is the hash length parsed from the algo name (e.g., BLAKE2b-256 -> Some(256)).
print_hash
Print hash result in GNU format: “hash filename\n”
print_hash_tag
Print hash result in BSD tag format: “ALGO (filename) = hash\n”
print_hash_tag_b2sum
Print hash in BSD tag format with BLAKE2b length info: “BLAKE2b (filename) = hash” for 512-bit, or “BLAKE2b-256 (filename) = hash” for other lengths.
print_hash_tag_b2sum_zero
Print hash in BSD tag format with BLAKE2b length info and NUL terminator.
print_hash_tag_zero
Print hash in BSD tag format with NUL terminator.
print_hash_zero
Print hash in GNU format with NUL terminator instead of newline.
readahead_files
Issue readahead hints for a list of file paths to warm the page cache. Uses POSIX_FADV_WILLNEED which is non-blocking and batches efficiently.
should_use_parallel
Check if parallel hashing is worthwhile for the given file paths. Only uses rayon when files are individually large enough for the hash computation to dominate over rayon overhead (thread pool init + work stealing). For many small files (e.g., 100 × 100KB), sequential is much faster.