pub struct File<Database, Config = BonsaiFiles>where
Database: Clone,
Config: FileConfig,{ /* 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<File<Blocking<Database>, Config>>, Error>
pub fn children(&self) -> Result<Vec<File<Blocking<Database>, Config>>, Error>
Return all direct descendants 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<LimitedResolutionTimestamp<Nanoseconds, BonsaiEpoch>>, Error>
pub fn last_appended_at( &mut self ) -> Result<Option<LimitedResolutionTimestamp<Nanoseconds, BonsaiEpoch>>, 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<Async<Database>, Config>
impl<Database, Config> File<Async<Database>, Config>
sourcepub async fn children(
&self
) -> Result<Vec<File<Async<Database>, Config>>, Error>
pub async fn children( &self ) -> Result<Vec<File<Async<Database>, Config>>, Error>
Return all direct descendants 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 async fn move_to(&mut self, new_path: &str) -> Result<(), Error>
pub async 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 async fn rename(&mut self, new_name: String) -> Result<(), Error>
pub async fn rename(&mut self, new_name: String) -> Result<(), Error>
Renames this file to the new name.
sourcepub async fn is_empty(&mut self) -> Result<bool, Error>
pub async fn is_empty(&mut self) -> Result<bool, Error>
Returns true if this file contains no data.
sourcepub async fn last_appended_at(
&mut self
) -> Result<Option<LimitedResolutionTimestamp<Nanoseconds, BonsaiEpoch>>, Error>
pub async fn last_appended_at( &mut self ) -> Result<Option<LimitedResolutionTimestamp<Nanoseconds, BonsaiEpoch>>, 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 async fn contents(&self) -> Result<Contents<Async<Database>, Config>, Error>
pub async fn contents(&self) -> Result<Contents<Async<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 async fn truncate(
&self,
new_length: u64,
from: Truncate
) -> Result<(), Error>
pub async 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 async fn append(&self, data: &[u8]) -> Result<(), Error>
pub async 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) -> AsyncBufferedAppend<'_, Config, Database>
pub fn append_buffered(&mut self) -> AsyncBufferedAppend<'_, Config, Database>
Returns a writer that will buffer writes to the end of the file.
sourcepub async fn update_metadata(&mut self) -> Result<(), Error>
pub async 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) -> LimitedResolutionTimestamp<Nanoseconds, BonsaiEpoch>
pub fn created_at(&self) -> LimitedResolutionTimestamp<Nanoseconds, BonsaiEpoch>
Returns the timestamp the file was created at.
sourcepub fn metadata(&self) -> &<Config as FileConfig>::Metadata
pub fn metadata(&self) -> &<Config as FileConfig>::Metadata
Returns the metadata for this file.
sourcepub fn metadata_mut(&mut self) -> &mut <Config as FileConfig>::Metadata
pub fn metadata_mut(&mut self) -> &mut <Config as FileConfig>::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.