Skip to main content

stream_hash

Function stream_hash 

Source
pub fn stream_hash(path: &Path) -> Result<String>
Expand description

Hashes a file using streaming I/O with constant memory.

Reads in STREAM_BUFFER_SIZE chunks and feeds each chunk to a DefaultHasher. Never loads the entire file into memory.

Returns a 16-character hex fingerprint.

ยงExamples

use ssg::stream::stream_hash;
use tempfile::tempdir;
use std::fs;

let dir = tempdir().unwrap();
let p = dir.path().join("h.txt");
fs::write(&p, "hello").unwrap();
let h = stream_hash(&p).unwrap();
assert_eq!(h.len(), 16);