Skip to main content

bitrouter_core/
blob.rs

1//! Blob storage abstraction.
2//!
3//! [`BlobStore`] defines a transport-agnostic interface for storing and
4//! retrieving opaque binary objects keyed by string paths. Concrete
5//! implementations (filesystem, S3, GCS, …) live in downstream crates
6//! behind feature flags.
7
8use dynosaur::dynosaur;
9
10use crate::errors::Result;
11
12/// Metadata about a stored blob.
13#[derive(Debug, Clone)]
14pub struct BlobMeta {
15    /// The key (path) of the blob.
16    pub key: String,
17    /// Size in bytes, if known.
18    pub size: Option<u64>,
19}
20
21/// A transport-agnostic blob storage interface.
22///
23/// Keys are `/`-separated logical paths (e.g. `"sessions/abc/file.png"`).
24/// Implementations map these to whatever physical layout they use.
25#[dynosaur(pub DynBlobStore = dyn(box) BlobStore)]
26pub trait BlobStore: Send + Sync {
27    /// Store `data` at `key`, overwriting any existing blob.
28    fn put(&self, key: &str, data: Vec<u8>) -> impl Future<Output = Result<()>> + Send;
29
30    /// Retrieve the blob at `key`.
31    fn get(&self, key: &str) -> impl Future<Output = Result<Vec<u8>>> + Send;
32
33    /// Delete the blob at `key`. No-op if the key does not exist.
34    fn delete(&self, key: &str) -> impl Future<Output = Result<()>> + Send;
35
36    /// Check whether a blob exists at `key`.
37    fn exists(&self, key: &str) -> impl Future<Output = Result<bool>> + Send;
38
39    /// List blobs whose keys start with `prefix`.
40    fn list(&self, prefix: &str) -> impl Future<Output = Result<Vec<BlobMeta>>> + Send;
41}