pub struct FileStorage { /* private fields */ }Expand description
File storage using a pluggable backend
This struct wraps a StorageBackend implementation and provides
higher-level operations like index management.
Implementations§
Source§impl FileStorage
impl FileStorage
Sourcepub fn new(config: FileConfig) -> Self
pub fn new(config: FileConfig) -> Self
Create a new file storage with the default local backend
Sourcepub fn with_backend(
config: FileConfig,
backend: Box<dyn StorageBackend>,
) -> Self
pub fn with_backend( config: FileConfig, backend: Box<dyn StorageBackend>, ) -> Self
Create a file storage with a custom backend
This allows using different storage backends like S3, Azure Blob, etc.
§Example
use agent_diva_files::{FileStorage, FileConfig};
use agent_diva_files::backend::LocalStorageBackend;
use std::path::PathBuf;
let config = FileConfig::default();
let backend = LocalStorageBackend::new(PathBuf::from("/custom/path"));
let storage = FileStorage::with_backend(config, Box::new(backend));Sourcepub async fn initialize(&self) -> Result<()>
pub async fn initialize(&self) -> Result<()>
Initialize the storage backend
Sourcepub async fn store_data(&self, hash: &str, data: &[u8]) -> Result<PathBuf>
pub async fn store_data(&self, hash: &str, data: &[u8]) -> Result<PathBuf>
Store file data and return the relative path
The hash is used as the key for content-addressed storage.
Sourcepub async fn read_data(&self, relative_path: &Path) -> Result<Vec<u8>>
pub async fn read_data(&self, relative_path: &Path) -> Result<Vec<u8>>
Read file data by relative path
Sourcepub async fn delete_data(&self, relative_path: &Path) -> Result<()>
pub async fn delete_data(&self, relative_path: &Path) -> Result<()>
Delete file data by relative path
Sourcepub async fn stats(&self) -> Result<StorageStats>
pub async fn stats(&self) -> Result<StorageStats>
Get storage statistics
Sourcepub fn backend(&self) -> &dyn StorageBackend
pub fn backend(&self) -> &dyn StorageBackend
Get a reference to the underlying backend
Auto Trait Implementations§
impl Freeze for FileStorage
impl !RefUnwindSafe for FileStorage
impl Send for FileStorage
impl Sync for FileStorage
impl Unpin for FileStorage
impl UnsafeUnpin for FileStorage
impl !UnwindSafe for FileStorage
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more