//! Streaming file digests used by downloads, transfers and backups. use sha2::{Digest, Sha256, Sha512}; use std::io::Read; use std::path::Path; fn digest_file(path: &Path) -> std::io::Result { let mut file = std::fs::File::open(path)?; let mut hasher = D::new(); let mut buffer = vec![0u8; 256 * 1024]; loop { let n = file.read(&mut buffer)?; if n == 0 { break; } hasher.update(&buffer[..n]); } Ok(hex::encode(hasher.finalize())) } pub fn sha256_file(path: &Path) -> std::io::Result { digest_file::(path) } pub fn sha512_file(path: &Path) -> std::io::Result { digest_file::(path) }