Implement hash() for S3
This commit is contained in:
@@ -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 out = tokio::task::spawn_blocking(move || {
|
||||||
let mut hasher = blake3::Hasher::new();
|
let mut hasher = blake3::Hasher::new();
|
||||||
let mut file = std::fs::File::open(path)?;
|
std::io::copy(&mut read, &mut hasher)?;
|
||||||
std::io::copy(&mut file, &mut hasher)?;
|
return Ok::<_, std::io::Error>(hasher.finalize());
|
||||||
return Ok(hasher.finalize());
|
})
|
||||||
}
|
.await??;
|
||||||
|
return Ok(out);
|
||||||
Self::S3 { .. } => todo!(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mime(&self) -> &Mime {
|
pub fn mime(&self) -> &Mime {
|
||||||
|
|||||||
Reference in New Issue
Block a user