pub struct CDBWriter { /* private fields */ }
Expand description
A CDB file writer which handles atomic updating.
Using this type, a CDB file is safely written by first creating a temporary file, building the CDB structure into that temporary file, and finally renaming that temporary file over the final file name. If the temporary file is not properly finished (ie due to an error), the temporary file is deleted when this writer is dropped.
Example
use cdb::CDBWriter;
fn main() -> std::io::Result<()> {
let mut cdb = CDBWriter::create("temporary.cdb")?;
cdb.add(b"one", b"Hello")?;
cdb.finish()?;
Ok(())
}
Implementations
sourceimpl CDBWriter
impl CDBWriter
sourcepub fn create<P: AsRef<Path> + ToString>(filename: P) -> Result<CDBWriter>
pub fn create<P: AsRef<Path> + ToString>(filename: P) -> Result<CDBWriter>
Safely create a new CDB file.
The suffix for the temporary file defaults to ".tmp"
.
sourcepub fn with_suffix<P: AsRef<Path> + ToString>(
filename: P,
suffix: &str
) -> Result<CDBWriter>
pub fn with_suffix<P: AsRef<Path> + ToString>(
filename: P,
suffix: &str
) -> Result<CDBWriter>
Safely create a new CDB file, using a specific suffix for the temporary file.
sourcepub fn with_filenames<P: AsRef<Path> + ToString, Q: AsRef<Path> + ToString>(
filename: P,
tmpname: Q
) -> Result<CDBWriter>
pub fn with_filenames<P: AsRef<Path> + ToString, Q: AsRef<Path> + ToString>(
filename: P,
tmpname: Q
) -> Result<CDBWriter>
Safely create a new CDB file, using two specific file names.
Note that the temporary file name must be on the same filesystem as the destination, or else the final rename will fail.
sourcepub fn set_permissions(&self, perm: Permissions) -> Result<()>
pub fn set_permissions(&self, perm: Permissions) -> Result<()>
Set permissions on the temporary file.
This must be done before the file is finished, as the temporary file will no longer exist at that point.