More debugging because apparently checksums are the bane of my existence. But it works and I was just an idiot

This commit is contained in:
quexeky
2024-10-26 23:23:43 +11:00
parent 706f525ae7
commit c9d9d2e94f

View File

@ -10,23 +10,28 @@ use urlencoding::encode;
pub struct FileWriter { pub struct FileWriter {
file: File, file: File,
hasher: Context hasher: Context,
data: Vec<u8>
} }
impl FileWriter { impl FileWriter {
fn new(path: PathBuf) -> Self { fn new(path: PathBuf) -> Self {
Self { Self {
file: OpenOptions::new().write(true).open(path).unwrap(), file: OpenOptions::new().write(true).open(path).unwrap(),
hasher: Context::new() hasher: Context::new(),
data: Vec::new()
} }
} }
fn finish(mut self) -> Digest { fn finish(mut self) -> Digest {
self.flush(); self.flush();
self.hasher.compute() let res = self.hasher.compute();
info!("Final calculated value hash: {:?}", hex::encode(res.0));
res
} }
} }
impl Write for FileWriter { impl Write for FileWriter {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> { fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
self.hasher.write(buf); self.hasher.write(buf);
self.data.extend_from_slice(buf);
self.file.write(buf) self.file.write(buf)
} }