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
16#[derive(Debug, Clone)]
17pub struct BlobStat {
18 pub size: u64,
19 pub modified_at: i64,
21}
22
23#[async_trait]
24pub trait BlobAdapter: Debug + Send + Sync {
25 async fn create_blob_buf(
27 &self,
28 tn_id: TnId,
29 file_id: &str,
30 data: &[u8],
31 opts: &CreateBlobOptions,
32 ) -> ClResult<()>;
33
34 async fn create_blob_stream(
36 &self,
37 tn_id: TnId,
38 file_id: &str,
39 stream: &mut (dyn AsyncRead + Send + Unpin),
40 ) -> ClResult<()>;
41
42 async fn stat_blob(&self, tn_id: TnId, blob_id: &str) -> Option<BlobStat>;
44
45 async fn read_blob_buf(&self, tn_id: TnId, blob_id: &str) -> ClResult<Box<[u8]>>;
47
48 async fn read_blob_range(
50 &self,
51 tn_id: TnId,
52 blob_id: &str,
53 offset: u64,
54 length: u64,
55 ) -> ClResult<Box<[u8]>>;
56
57 async fn read_blob_stream(
59 &self,
60 tn_id: TnId,
61 blob_id: &str,
62 ) -> ClResult<Pin<Box<dyn Stream<Item = Result<Bytes, std::io::Error>> + Send>>>;
63
64 async fn create_blob_from_path(
66 &self,
67 tn_id: TnId,
68 file_id: &str,
69 source: &std::path::Path,
70 opts: &CreateBlobOptions,
71 ) -> ClResult<()>;
72
73 async fn delete_tenant_blobs(&self, tn_id: TnId) -> ClResult<()>;
76
77 async fn delete_blob(&self, tn_id: TnId, blob_id: &str) -> ClResult<()>;
79
80 async fn list_blobs(
83 &self,
84 tn_id: TnId,
85 ) -> ClResult<Pin<Box<dyn Stream<Item = ClResult<String>> + Send>>>;
86
87 async fn cleanup_tmp_files(&self, tn_id: TnId, cutoff_secs: i64) -> ClResult<u64>;
93}
94
95