pub struct File<Database: Clone, Config: FileConfig = BonsaiFiles> { /* private fields */ }Expand description
A handle to a file stored in a database.
Implementations§
Source§impl<Database, Config> File<Blocking<Database>, Config>
impl<Database, Config> File<Blocking<Database>, Config>
Sourcepub fn children(&self) -> Result<Vec<Self>, Error>
pub fn children(&self) -> Result<Vec<Self>, Error>
Return all direct descendents of this file. For example, consider this list of files:
- /top-level
- /top-level/sub-level
- /top-level/sub-level/file.txt
If this instance were /top-level, this function would return
sub-level but not sub-level/file.txt.
Sourcepub fn move_to(&mut self, new_path: &str) -> Result<(), Error>
pub fn move_to(&mut self, new_path: &str) -> Result<(), Error>
Moves this file to a new location. If new_path ends with a /, the
file will be moved to that path with its name preserved. Otherwise, the
file will be renamed as part of the move.
For example, moving /a/file.txt to /b/ will result in the full path
being /b/file.txt. Moving /a/file.txt to /b/new-name.txt will
result in the full path being /b/new-name.txt.
Sourcepub fn rename(&mut self, new_name: String) -> Result<(), Error>
pub fn rename(&mut self, new_name: String) -> Result<(), Error>
Renames this file to the new name.
Sourcepub fn last_appended_at(
&mut self,
) -> Result<Option<TimestampAsNanoseconds>, Error>
pub fn last_appended_at( &mut self, ) -> Result<Option<TimestampAsNanoseconds>, Error>
Returns the timestamp of the last append to the file. This function returns 0 when the file is empty, even if the file was previously written to.
Sourcepub fn contents(&self) -> Result<Contents<Blocking<Database>, Config>, Error>
pub fn contents(&self) -> Result<Contents<Blocking<Database>, Config>, Error>
Returns the contents of the file, which allows random and buffered access to the file stored in the database.
The default buffer size is ten times
Config::BLOCK_SIZE.
Sourcepub fn truncate(&self, new_length: u64, from: Truncate) -> Result<(), Error>
pub fn truncate(&self, new_length: u64, from: Truncate) -> Result<(), Error>
Truncates the file, removing data from either the start or end of the
file until the file is within
Config::BLOCK_SIZE of new_length.
Truncating currently will not split a block, causing the resulting
length to not always match the length requested.
If new_length is 0 and this call succeeds, the file’s length is
guaranteed to be 0.
Sourcepub fn append(&self, data: &[u8]) -> Result<(), Error>
pub fn append(&self, data: &[u8]) -> Result<(), Error>
Appends data to the end of the file. The data will be split into
chunks no larger than Config::BLOCK_SIZE
when stored in the database.
Sourcepub fn append_buffered(&mut self) -> BufferedAppend<'_, Config, Database> ⓘ
pub fn append_buffered(&mut self) -> BufferedAppend<'_, Config, Database> ⓘ
Returns a writer that will buffer writes to the end of the file.
Sourcepub fn update_metadata(&mut self) -> Result<(), Error>
pub fn update_metadata(&mut self) -> Result<(), Error>
Stores changes to the metadata of this document.
Source§impl<Database, Config> File<Database, Config>where
Database: Clone,
Config: FileConfig,
impl<Database, Config> File<Database, Config>where
Database: Clone,
Config: FileConfig,
Sourcepub fn id(&self) -> u32
pub fn id(&self) -> u32
Returns the unique id of this file. The file id is only unique within a
single database and FileConfig.
Sourcepub fn containing_path(&self) -> &str
pub fn containing_path(&self) -> &str
Returns the path containing this file. For example, if the full path to
the file is /some-path/file.txt, this function will return
/some-path/.
Sourcepub fn created_at(&self) -> TimestampAsNanoseconds
pub fn created_at(&self) -> TimestampAsNanoseconds
Returns the timestamp the file was created at.
Sourcepub fn metadata_mut(&mut self) -> &mut Config::Metadata
pub fn metadata_mut(&mut self) -> &mut Config::Metadata
Returns mutable access metadata for this file. Modifying the metadata
will not update it in the database. Be sure to call update_metadata()
or another operation that persists the file.
Trait Implementations§
Auto Trait Implementations§
impl<Database, Config> Freeze for File<Database, Config>
impl<Database, Config> RefUnwindSafe for File<Database, Config>where
Database: RefUnwindSafe,
<Config as FileConfig>::Metadata: RefUnwindSafe,
Config: RefUnwindSafe,
impl<Database, Config> Send for File<Database, Config>where
Database: Send,
impl<Database, Config> Sync for File<Database, Config>where
Database: Sync,
impl<Database, Config> Unpin for File<Database, Config>
impl<Database, Config> UnwindSafe for File<Database, Config>
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,
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