Skip to main content

atrg_blob/
lib.rs

1#![deny(unsafe_code)]
2#![warn(missing_docs)]
3//! Content-addressed blob storage for at-rust-go.
4//! Provides S3 and filesystem backends.
5
6pub mod cid;
7pub mod file;
8#[cfg(feature = "s3")]
9pub mod s3;
10
11pub use cid::compute_cid;
12
13use async_trait::async_trait;
14
15/// Errors from blob store operations.
16#[derive(Debug, thiserror::Error)]
17pub enum BlobError {
18    /// The requested blob was not found.
19    #[error("blob not found: {0}")]
20    NotFound(String),
21    /// An error occurred in the underlying storage backend.
22    #[error("blob store error: {0}")]
23    Storage(#[from] anyhow::Error),
24}
25
26/// Trait for content-addressed blob storage backends.
27#[async_trait]
28pub trait BlobStore: Send + Sync + 'static {
29    /// Store a blob, returning its content-addressed identifier (CID).
30    async fn put(&self, data: &[u8]) -> Result<String, BlobError>;
31    /// Retrieve a blob by CID.
32    async fn get(&self, cid: &str) -> Result<Vec<u8>, BlobError>;
33    /// Check if a blob exists.
34    async fn exists(&self, cid: &str) -> Result<bool, BlobError>;
35    /// Delete a blob by CID.
36    async fn delete(&self, cid: &str) -> Result<(), BlobError>;
37}