Skip to main content

cloudillo_types/
blob_adapter.rs

1//! Adapter that manages and stores blobs (immutable file data)
2use async_trait::async_trait;
3use axum::body::Bytes;
4use futures_core::Stream;
5use std::{fmt::Debug, pin::Pin};
6use tokio::io::AsyncRead;
7
8use crate::prelude::*;
9
10#[derive(Clone, Default)]
11pub struct CreateBlobOptions {}
12
13pub struct BlobStat {
14	pub size: u64,
15}
16
17#[async_trait]
18pub trait BlobAdapter: Debug + Send + Sync {
19	/// Creates a new blob from a buffer
20	async fn create_blob_buf(
21		&self,
22		tn_id: TnId,
23		file_id: &str,
24		data: &[u8],
25		opts: &CreateBlobOptions,
26	) -> ClResult<()>;
27
28	/// Creates a new blob using a stream
29	async fn create_blob_stream(
30		&self,
31		tn_id: TnId,
32		file_id: &str,
33		stream: &mut (dyn AsyncRead + Send + Unpin),
34	) -> ClResult<()>;
35
36	/// Stats a blob
37	async fn stat_blob(&self, tn_id: TnId, blob_id: &str) -> Option<u64>;
38
39	/// Reads a blob
40	async fn read_blob_buf(&self, tn_id: TnId, blob_id: &str) -> ClResult<Box<[u8]>>;
41
42	/// Reads a blob
43	async fn read_blob_stream(
44		&self,
45		tn_id: TnId,
46		blob_id: &str,
47	) -> ClResult<Pin<Box<dyn Stream<Item = Result<Bytes, std::io::Error>> + Send>>>;
48}
49
50// vim: ts=4