#temporary-files #file-path #commit #final #create #staged #committed


Creates a temporary file which can then be committed to a final path

2 unstable releases

new 0.5.0 May 15, 2024
0.4.0 Aug 28, 2023
0.3.0 Aug 27, 2023
0.2.0 Oct 31, 2021
0.1.0 Mar 29, 2021

#436 in Filesystem

Download history 7/week @ 2024-02-24 5/week @ 2024-03-09 1/week @ 2024-03-16 72/week @ 2024-03-23 4/week @ 2024-03-30 111/week @ 2024-05-11

111 downloads per month


293 lines


StagedFile helps write data to a temporary file, and then gives the option to commit the temporary file to a desired final file path.

If a file exists at the desired final file path, the file will be overwritten during a commit function call currently.

Only UNIX is currently supported.


staged_file = "0.5.0"


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!";

    // The LineWriter code is in a block so that `&staged_file` is not considered
    // borrowed at the end of the block. Another way to get back the
    // `staged_file` is to call `line_writer.into_inner()`.
    let mut line_writer = LineWriter::new(&staged_file);


assert_eq!(std::fs::read(final_path)?, text);

If the commit() method is not called, then the staged file contents are discarded.

Other Libraries

The library is used as a dependency in this crate to create temporary directories.

A cross platform atomic file writes library.


Licensed under either of Apache License, Version 2.0 or MIT License at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~141K SLoC