Implement hash() for S3
All checks were successful
CI / Typos (push) Successful in 20s
CI / Build and test (push) Successful in 2m32s
CI / Clippy (push) Successful in 6m3s
CI / Build and test (all features) (push) Successful in 15m23s

This commit is contained in:
2026-03-16 22:24:54 -07:00
parent 1c1c47f5b2
commit 915d10bd0e

View File

@@ -5,7 +5,7 @@ use std::{collections::HashMap, fs::File, path::PathBuf, sync::Arc};
use crate::{ use crate::{
source::{DirDataSource, S3DataSource}, source::{DirDataSource, S3DataSource},
value::{ItemReader, S3Reader}, value::{ItemReader, S3Reader, SyncReadBridge},
}; };
// //
@@ -74,7 +74,7 @@ impl Item {
match self { match self {
Self::File { source, path, .. } => path Self::File { source, path, .. } => path
.strip_prefix(&source.dir) .strip_prefix(&source.dir)
.unwrap() .expect("item must be inside source")
.to_str() .to_str()
.expect("path is not utf-8") .expect("path is not utf-8")
.into(), .into(),
@@ -82,17 +82,16 @@ impl Item {
} }
} }
pub fn hash(&self) -> Result<blake3::Hash, std::io::Error> { pub async fn hash(&self) -> Result<blake3::Hash, std::io::Error> {
match self { let read = self.read().await?;
Self::File { path, .. } => { let mut read = SyncReadBridge::new_current(read);
let mut hasher = blake3::Hasher::new(); let out = tokio::task::spawn_blocking(move || {
let mut file = std::fs::File::open(path)?; let mut hasher = blake3::Hasher::new();
std::io::copy(&mut file, &mut hasher)?; std::io::copy(&mut read, &mut hasher)?;
return Ok(hasher.finalize()); return Ok::<_, std::io::Error>(hasher.finalize());
} })
.await??;
Self::S3 { .. } => todo!(), return Ok(out);
}
} }
pub fn mime(&self) -> &Mime { pub fn mime(&self) -> &Mime {