Crate staged_file[−][src]
StagedFile
helps write data to a temporary file, and then gives the option
to commit the temporary file to a desired final file path.
First, a staged file is created with the desired final path of the file. The staged file starts as a newly created temporary file.
Then, data is written out by using the StagedFile
as a File
ref.
Finally, the file is commited by calling StagedFile::commit()
. If the
temporary file contents are not to be committed, then let the StagedFile
be
dropped without calling commit
.
use staged_file::StagedFile; use std::fs::File; use std::io::{prelude::*, LineWriter}; use std::path::Path; let final_path = Path::new("/a/file/path"); let staged_file = StagedFile::with_final_path(&final_path)?; let text = b"Hello World!"; { let mut line_writer = LineWriter::new(&staged_file); line_writer.write_all(text)?; line_writer.flush()?; } staged_file.commit()?; assert_eq!(std::fs::read(final_path)?, text);
Structs
StagedFile | Creates a temporary file which can then be committed to a final path. |
Enums
Error | Possible errors when creating and committing the staged file. |