cloudillo_types/
blob_adapter.rs1use async_trait::async_trait;
6use axum::body::Bytes;
7use futures_core::Stream;
8use std::{fmt::Debug, pin::Pin};
9use tokio::io::AsyncRead;
10
11use crate::prelude::*;
12
13#[derive(Clone, Default)]
14pub struct CreateBlobOptions {}
15
16pub struct BlobStat {
17 pub size: u64,
18}
19
20#[async_trait]
21pub trait BlobAdapter: Debug + Send + Sync {
22 async fn create_blob_buf(
24 &self,
25 tn_id: TnId,
26 file_id: &str,
27 data: &[u8],
28 opts: &CreateBlobOptions,
29 ) -> ClResult<()>;
30
31 async fn create_blob_stream(
33 &self,
34 tn_id: TnId,
35 file_id: &str,
36 stream: &mut (dyn AsyncRead + Send + Unpin),
37 ) -> ClResult<()>;
38
39 async fn stat_blob(&self, tn_id: TnId, blob_id: &str) -> Option<u64>;
41
42 async fn read_blob_buf(&self, tn_id: TnId, blob_id: &str) -> ClResult<Box<[u8]>>;
44
45 async fn read_blob_range(
47 &self,
48 tn_id: TnId,
49 blob_id: &str,
50 offset: u64,
51 length: u64,
52 ) -> ClResult<Box<[u8]>>;
53
54 async fn read_blob_stream(
56 &self,
57 tn_id: TnId,
58 blob_id: &str,
59 ) -> ClResult<Pin<Box<dyn Stream<Item = Result<Bytes, std::io::Error>> + Send>>>;
60}
61
62