fix: loading of data from the database seems to do something

This commit is contained in:
2026-04-04 21:46:56 +02:00
parent a7cc12ffb8
commit 989efeaf25
12 changed files with 303 additions and 55 deletions

View File

@@ -1,4 +1,6 @@
use sha2::{Digest, Sha256};
use std::io::Read;
use std::path::Path;
/// Compute a hex-encoded SHA-256 hash of the given content.
pub fn content_hash(content: &[u8]) -> String {
@@ -8,6 +10,21 @@ pub fn content_hash(content: &[u8]) -> String {
hex::encode(result)
}
/// Compute a hex-encoded SHA-256 hash of a file by streaming (8 KB chunks).
pub fn file_hash(path: &Path) -> std::io::Result<String> {
let mut file = std::fs::File::open(path)?;
let mut hasher = Sha256::new();
let mut buf = [0u8; 8192];
loop {
let n = file.read(&mut buf)?;
if n == 0 {
break;
}
hasher.update(&buf[..n]);
}
Ok(hex::encode(hasher.finalize()))
}
// sha2 doesn't include hex encoding, so we use a tiny inline helper.
mod hex {
const HEX_CHARS: &[u8; 16] = b"0123456789abcdef";