pub struct Service { /* private fields */ }Expand description
The high-level interface to the storage vault.
Service is the entry point for all filesystem operations in this application.
It owns the path to the vault directory and exposes a small, focused API for
saving, retrieving, and deleting blobs.
Internally, writes go through an internal transaction which guarantees atomicity: a failed write can never leave a corrupted or partial file in the vault.
Implementations§
Source§impl Service
impl Service
Sourcepub fn new<P>(vault_path: P) -> Self
pub fn new<P>(vault_path: P) -> Self
Creates a new Service rooted at the given vault directory.
The path is not validated here — if the directory does not exist when
a transaction is attempted, a crate::storage::Error::VaultNotFound will be
returned at that point.
Sourcepub async fn try_save<S, E>(
&self,
file_name: &str,
payload: Payload<S, E>,
) -> Result<Metadata>
pub async fn try_save<S, E>( &self, file_name: &str, payload: Payload<S, E>, ) -> Result<Metadata>
Streams a payload to disk and commits it atomically to the vault.
This is the main entry point for all uploads. Internally it creates an
internal transaction, streams all bytes to a temporary staging file, then
performs an atomic rename(2) to the final CAS path (the BLAKE3 hash
of the content). Returns the file Metadata on success.
If anything fails mid-stream, the temporary file is cleaned up before the error is returned.
§Errors
- Returns
crate::storage::Error::InvalidFileNameiffile_namecontains/,\, or is empty. - Returns
crate::storage::Error::FileAlreadyExistsif a file with that name already exists in the vault. - Returns
crate::storage::Errorif a disk I/O failure occurs during streaming or the atomic rename.
Source§impl Service
impl Service
Sourcepub async fn delete_blob(&self, hash_str: &str) -> Result<()>
pub async fn delete_blob(&self, hash_str: &str) -> Result<()>
Deletes the blob at the given hash string from the vault.
This is intentionally idempotent: if the file does not exist, Ok(()) is
returned without error. This makes it safe to call even when the physical
file has already been removed or was never committed.
§Errors
- Returns
crate::storage::Error::Internalif the filesystem returns any error other thanNotFound(e.g., permission denied).
Sourcepub async fn get_blob(&self, hash_str: &str) -> Result<File>
pub async fn get_blob(&self, hash_str: &str) -> Result<File>
Opens and returns the blob file at the given hash string for reading.
The returned [tokio::fs::File] handle can be wrapped in a ReaderStream
for direct streaming to an HTTP response body without loading the file into memory.
§Errors
- Returns
crate::storage::Error::NotFoundif no blob with that hash exists in the vault.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Service
impl RefUnwindSafe for Service
impl Send for Service
impl Sync for Service
impl Unpin for Service
impl UnsafeUnpin for Service
impl UnwindSafe for Service
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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