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