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_stream(
51 &self,
52 tn_id: TnId,
53 blob_id: &str,
54 offset: u64,
55 length: u64,
56 ) -> ClResult<Pin<Box<dyn Stream<Item = Result<Bytes, std::io::Error>> + Send>>>;
57
58 async fn read_blob_stream(
60 &self,
61 tn_id: TnId,
62 blob_id: &str,
63 ) -> ClResult<Pin<Box<dyn Stream<Item = Result<Bytes, std::io::Error>> + Send>>>;
64
65 async fn create_blob_from_path(
67 &self,
68 tn_id: TnId,
69 file_id: &str,
70 source: &std::path::Path,
71 opts: &CreateBlobOptions,
72 ) -> ClResult<()>;
73
74 async fn delete_tenant_blobs(&self, tn_id: TnId) -> ClResult<()>;
77
78 async fn delete_blob(&self, tn_id: TnId, blob_id: &str) -> ClResult<()>;
80
81 async fn list_blobs(
84 &self,
85 tn_id: TnId,
86 ) -> ClResult<Pin<Box<dyn Stream<Item = ClResult<String>> + Send>>>;
87
88 async fn cleanup_tmp_files(&self, tn_id: TnId, cutoff_secs: i64) -> ClResult<u64>;
94}
95
96