pub struct FilesStore { /* private fields */ }Expand description
Disk-backed store for uploaded files.
All methods are synchronous and intended to be called from within a
tokio::task::spawn_blocking context (see the route handlers).
Implementations§
Source§impl FilesStore
impl FilesStore
Sourcepub fn new(root: PathBuf) -> FilesStoreResult<Self>
pub fn new(root: PathBuf) -> FilesStoreResult<Self>
Open (or create) the files store root directory.
Creates the directory tree if it does not exist.
Sourcepub fn create(
&self,
filename: &str,
purpose: FilePurpose,
data: &[u8],
) -> FilesStoreResult<OxiFile>
pub fn create( &self, filename: &str, purpose: FilePurpose, data: &[u8], ) -> FilesStoreResult<OxiFile>
Upload a new file and persist it atomically.
Returns the OxiFile metadata record. Fails with FileTooLarge if
data.len() exceeds MAX_FILE_BYTES.
Sourcepub fn create_with_limit(
&self,
filename: &str,
purpose: FilePurpose,
data: &[u8],
limit: usize,
) -> FilesStoreResult<OxiFile>
pub fn create_with_limit( &self, filename: &str, purpose: FilePurpose, data: &[u8], limit: usize, ) -> FilesStoreResult<OxiFile>
Like create but with a caller-supplied byte limit.
Useful in tests where the 512 MiB default is impractical.
Sourcepub fn get(&self, file_id: &str) -> FilesStoreResult<OxiFile>
pub fn get(&self, file_id: &str) -> FilesStoreResult<OxiFile>
Retrieve metadata for a single file by ID.
Returns FileNotFound if no entry with this ID exists.
Sourcepub fn list(&self) -> FilesStoreResult<Vec<OxiFile>>
pub fn list(&self) -> FilesStoreResult<Vec<OxiFile>>
List all files stored in the root directory.
Returns them in an unspecified order. Entries whose meta.json cannot
be parsed are silently skipped so a single corrupt entry does not block
the listing.
Sourcepub fn get_content(&self, file_id: &str) -> FilesStoreResult<Vec<u8>>
pub fn get_content(&self, file_id: &str) -> FilesStoreResult<Vec<u8>>
Read the raw bytes for a file.
Returns FileNotFound if the file does not exist.
Sourcepub fn delete(&self, file_id: &str) -> FilesStoreResult<()>
pub fn delete(&self, file_id: &str) -> FilesStoreResult<()>
Delete a file and all associated data.
Returns FileNotFound if no such file exists.
Auto Trait Implementations§
impl Freeze for FilesStore
impl RefUnwindSafe for FilesStore
impl Send for FilesStore
impl Sync for FilesStore
impl Unpin for FilesStore
impl UnsafeUnpin for FilesStore
impl UnwindSafe for FilesStore
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> 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>
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