pub mod local;
use std::fmt::Debug;
use std::io::Read;
use std::pin::Pin;
use std::sync::Arc;
use async_trait::async_trait;
use futures::{AsyncRead, Stream};
use crate::{FileMeta, ListEntry, Result, SizedFile};
pub type FileMetaStream =
Pin<Box<dyn Stream<Item = Result<FileMeta>> + Send + Sync + 'static>>;
pub type ListEntryStream =
Pin<Box<dyn Stream<Item = Result<ListEntry>> + Send + Sync + 'static>>;
pub type ObjectReaderStream =
Pin<Box<dyn Stream<Item = Result<Arc<dyn ObjectReader>>> + Send + Sync>>;
#[async_trait]
pub trait ObjectReader: Send + Sync {
async fn chunk_reader(&self, start: u64, length: usize)
-> Result<Box<dyn AsyncRead>>;
fn sync_chunk_reader(
&self,
start: u64,
length: usize,
) -> Result<Box<dyn Read + Send + Sync>>;
fn sync_reader(&self) -> Result<Box<dyn Read + Send + Sync>> {
self.sync_chunk_reader(0, self.length() as usize)
}
fn length(&self) -> u64;
}
#[async_trait]
pub trait ObjectStore: Sync + Send + Debug {
async fn list_file(&self, prefix: &str) -> Result<FileMetaStream>;
async fn list_dir(
&self,
prefix: &str,
delimiter: Option<String>,
) -> Result<ListEntryStream>;
fn file_reader(&self, file: SizedFile) -> Result<Arc<dyn ObjectReader>>;
}