Skip to content

Commit

Permalink
Fast, buffered writes to file
Browse files Browse the repository at this point in the history
  • Loading branch information
YodaEmbedding committed Jun 7, 2019
1 parent 77e21c8 commit af1ad52
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,17 @@ fn write_fields(
filename: &str
) -> Result<()> {
let tmp_filename = format!("{}{}", filename, ".tmp");
let mut tmp_file = OpenOptions::new()
.create_new(true)
.write(true)
.open(&tmp_filename)?;
let mut tmp_file = BufWriter::new(
OpenOptions::new()
.create_new(true)
.write(true)
.open(&tmp_filename)?);

for field in fields {
writeln!(&mut tmp_file, "{}", field)?;
}

tmp_file.flush()?;
drop(tmp_file);
fs::rename(tmp_filename, filename)?;
Ok(())
Expand Down

0 comments on commit af1ad52

Please sign in to comment.