use std::future::Future;
use std::path::Path;
use aws_sdk_s3::primitives::ByteStream;
use aws_sdk_s3::types::Object;
use multihash::Multihash;
use tokio::io::AsyncRead;
use tokio_stream::Stream;
use crate::uri::S3Uri;
use crate::Res;
mod client;
mod s3;
pub use client::get_client_for_bucket;
pub use s3::RemoteS3;
#[cfg(test)]
pub mod mocks;
pub struct S3Attributes {
pub listing_uri: S3Uri,
pub object_uri: S3Uri,
pub hash: Multihash<256>,
pub size: u64,
}
pub struct RemoteObjectStream {
pub body: ByteStream,
pub uri: S3Uri,
}
pub type StreamObjectChunk = Vec<Res<Object>>;
pub type StreamItem = Res<StreamObjectChunk>;
pub trait ObjectsStream: Stream<Item = StreamItem> {}
impl<T: Stream<Item = StreamItem>> ObjectsStream for T {}
pub trait Remote {
fn exists(&self, s3_uri: &S3Uri) -> impl Future<Output = Res<bool>> + Send;
fn get_object(
&self,
s3_uri: &S3Uri,
) -> impl Future<Output = Res<impl AsyncRead + Send + Unpin>> + Send;
fn get_object_attributes(
&self,
listing_uri: &S3Uri,
object: &Object,
) -> impl Future<Output = Res<S3Attributes>>;
fn get_object_stream(
&self,
s3_uri: &S3Uri,
) -> impl Future<Output = Res<RemoteObjectStream>> + Send;
fn list_objects(&self, listing_uri: S3Uri) -> impl Future<Output = impl ObjectsStream> + Send;
fn put_object(
&self,
s3_uri: &S3Uri,
contents: impl Into<ByteStream>,
) -> impl Future<Output = Res>;
fn upload_file(
&self,
source_path: impl AsRef<Path>,
dest_uri: &S3Uri,
size: u64,
) -> impl Future<Output = Res<(S3Uri, Multihash<256>)>>;
}