2022-03-27 01:45:12 +00:00
|
|
|
use crate::error::Error;
|
2021-10-23 04:48:56 +00:00
|
|
|
use actix_web::web::Bytes;
|
|
|
|
use futures_util::stream::Stream;
|
2022-03-27 01:45:12 +00:00
|
|
|
use std::fmt::Debug;
|
2021-10-23 04:48:56 +00:00
|
|
|
use tokio::io::{AsyncRead, AsyncWrite};
|
|
|
|
|
|
|
|
pub(crate) mod file_store;
|
2021-10-28 04:06:03 +00:00
|
|
|
pub(crate) mod object_store;
|
2021-10-23 04:48:56 +00:00
|
|
|
|
|
|
|
pub(crate) trait Identifier: Send + Sync + Clone + Debug {
|
2022-03-27 01:45:12 +00:00
|
|
|
fn to_bytes(&self) -> Result<Vec<u8>, Error>;
|
2021-10-23 04:48:56 +00:00
|
|
|
|
2022-03-27 01:45:12 +00:00
|
|
|
fn from_bytes(bytes: Vec<u8>) -> Result<Self, Error>
|
2021-10-23 04:48:56 +00:00
|
|
|
where
|
|
|
|
Self: Sized;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[async_trait::async_trait(?Send)]
|
|
|
|
pub(crate) trait Store: Send + Sync + Clone + Debug + 'static {
|
2022-03-27 01:45:12 +00:00
|
|
|
type Identifier: Identifier;
|
2021-10-23 04:48:56 +00:00
|
|
|
type Stream: Stream<Item = std::io::Result<Bytes>>;
|
|
|
|
|
2022-03-27 01:45:12 +00:00
|
|
|
async fn save_async_read<Reader>(&self, reader: &mut Reader) -> Result<Self::Identifier, Error>
|
2021-10-23 04:48:56 +00:00
|
|
|
where
|
|
|
|
Reader: AsyncRead + Unpin;
|
|
|
|
|
2022-03-27 01:45:12 +00:00
|
|
|
async fn save_bytes(&self, bytes: Bytes) -> Result<Self::Identifier, Error>;
|
2021-10-23 04:48:56 +00:00
|
|
|
|
|
|
|
async fn to_stream(
|
|
|
|
&self,
|
|
|
|
identifier: &Self::Identifier,
|
|
|
|
from_start: Option<u64>,
|
|
|
|
len: Option<u64>,
|
2022-03-27 01:45:12 +00:00
|
|
|
) -> Result<Self::Stream, Error>;
|
2021-10-23 04:48:56 +00:00
|
|
|
|
|
|
|
async fn read_into<Writer>(
|
|
|
|
&self,
|
|
|
|
identifier: &Self::Identifier,
|
|
|
|
writer: &mut Writer,
|
|
|
|
) -> Result<(), std::io::Error>
|
|
|
|
where
|
2021-10-31 17:35:11 +00:00
|
|
|
Writer: AsyncWrite + Send + Unpin;
|
2021-10-23 04:48:56 +00:00
|
|
|
|
2022-03-27 01:45:12 +00:00
|
|
|
async fn len(&self, identifier: &Self::Identifier) -> Result<u64, Error>;
|
2021-10-23 04:48:56 +00:00
|
|
|
|
2022-03-27 01:45:12 +00:00
|
|
|
async fn remove(&self, identifier: &Self::Identifier) -> Result<(), Error>;
|
2021-10-23 04:48:56 +00:00
|
|
|
}
|