Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/datastores/filesystem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{

use regex::Regex;
use sha2::{Digest, Sha256};
use tokio::{fs::File as TokioFile, io::AsyncWrite};
use tokio::{fs::File as TokioFile, io::{AsyncRead, AsyncWrite}};

use crate::{datastores::DatastoreTrait, utils::backup_manager::DatabaseMetadata};

Expand Down Expand Up @@ -164,6 +164,19 @@ impl DatastoreTrait for FilesystemDatastore {

Ok(Box::new(file))
}

async fn open_read_stream(
&self,
object_name: &str,
) -> Result<Box<dyn AsyncRead + Unpin + Send>, String> {
let full_path = self.base_path.join(object_name);

let file = TokioFile::open(full_path)
.await
.map_err(|e| format!("Failed to open file: {}", e))?;

Ok(Box::new(file))
}
}

#[cfg(test)]
Expand Down
16 changes: 15 additions & 1 deletion src/datastores/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{io::Error, path::Path};

use tokio::io::AsyncWrite;
use tokio::io::{AsyncRead, AsyncWrite};

mod filesystem;
mod s3;
Expand All @@ -27,6 +27,10 @@ pub trait DatastoreTrait {
&self,
object_name: &str,
) -> Result<Box<dyn AsyncWrite + Unpin + Send>, String>;
async fn open_read_stream(
&self,
object_name: &str,
) -> Result<Box<dyn AsyncRead + Unpin + Send>, String>;
}

#[derive(Debug, PartialEq, Clone)]
Expand Down Expand Up @@ -79,4 +83,14 @@ impl Datastore {
Datastore::S3(store) => store.open_write_stream(object_name).await,
}
}

pub async fn open_read_stream(
&self,
object_name: &str,
) -> Result<Box<dyn AsyncRead + Unpin + Send>, String> {
match self {
Datastore::FileSystem(store) => store.open_read_stream(object_name).await,
Datastore::S3(store) => store.open_read_stream(object_name).await,
}
}
}
9 changes: 8 additions & 1 deletion src/datastores/s3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
path::{Path, PathBuf},
};

use tokio::io::AsyncWrite;
use tokio::io::{AsyncRead, AsyncWrite};

use crate::datastores::DatastoreTrait;

Expand Down Expand Up @@ -52,4 +52,11 @@ impl DatastoreTrait for S3Datastore {
) -> Result<Box<dyn AsyncWrite + Unpin + Send>, String> {
todo!()
}

async fn open_read_stream(
&self,
object_name: &str,
) -> Result<Box<dyn AsyncRead + Unpin + Send>, String> {
todo!()
}
}
Loading
Loading