diff --git a/src/api/blobs.rs b/src/api/blobs.rs index cf7f5c1..e18188c 100644 --- a/src/api/blobs.rs +++ b/src/api/blobs.rs @@ -33,14 +33,7 @@ pub async fn pull_digest(path: web::Path<(String, String)>, state: web::Data anyhow::Result> { - let path = self.get_digest_path(digest); - - if self.has_digest(digest)? { - - - //tokio::spawn(async { - let s = async_stream::try_stream! { - let file = fs::File::open(&path).await.unwrap(); - - let mut s = ReaderStream::new(file); - - while let Some(item) = s.next().await { - if let Ok(bytes) = item { - yield bytes; - //sender.send((layer_uuid.clone(), bytes)).await.unwrap(); - } - } - //file.re - }; - //}); - - Ok(Some(ByteStream::new(s))) - } else { - Ok(None) - } - } } #[async_trait] impl StorageDriver for FilesystemDriver { + async fn stream_bytes(&self, digest: &str) -> anyhow::Result> { + let file = match fs::File::open(self.get_digest_path(digest)).await { + Ok(f) => f, + Err(e) => match e.kind() { + ErrorKind::NotFound => { + return Ok(None) + }, + _ => { + return Err(e).context("FilesystemDriver: Failure to open digest file"); + } + } + }; + + let s = ReaderStream::new(file); + Ok(Some(ByteStream::new(s))) + } async fn get_digest(&self, digest: &str) -> anyhow::Result> { let mut file = match fs::File::open(self.get_digest_path(digest)) diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 6282ab0..974a4ff 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -19,7 +19,7 @@ pub trait StorageDriverStreamer { fn supports_streaming(&self) -> bool; fn start_stream_channel(&self) -> mpsc::Sender<(String, Bytes)>; fn has_digest(&self, digest: &str) -> anyhow::Result; - fn stream_bytes(&self, digest: &str) -> anyhow::Result>; + //fn stream_bytes(&self, digest: &str) -> anyhow::Result>; } #[async_trait] @@ -31,5 +31,6 @@ pub trait StorageDriver: Send + StorageDriverStreamer/* : AsyncWrite + AsyncRead async fn delete_digest(&self, digest: &str) -> anyhow::Result<()>; async fn replace_digest(&self, uuid: &str, digest: &str) -> anyhow::Result<()>; + async fn stream_bytes(&self, digest: &str) -> anyhow::Result>; //async fn stream_bytes(&self, stream: Box>) -> anyhow::Result<()>; } \ No newline at end of file