Skip to content

Commit

Permalink
Merge pull request #89 from cgwalters/bufio-json
Browse files Browse the repository at this point in the history
Use buffered I/O for JSON by default
  • Loading branch information
Furisto authored Jan 14, 2022
2 parents 2440343 + cb4a733 commit ced72f4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub use error::*;

fn from_file<P: AsRef<Path>, T: DeserializeOwned>(path: P) -> Result<T> {
let path = path.as_ref();
let manifest_file = fs::File::open(path)?;
let manifest = serde_json::from_reader(&manifest_file)?;
let manifest_file = std::io::BufReader::new(fs::File::open(path)?);
let manifest = serde_json::from_reader(manifest_file)?;
Ok(manifest)
}

Expand All @@ -38,6 +38,7 @@ fn to_file<P: AsRef<Path>, T: Serialize>(item: &T, path: P, pretty: bool) -> Res
.create(true)
.truncate(true)
.open(path)?;
let file = std::io::BufWriter::new(file);

match pretty {
true => serde_json::to_writer_pretty(file, item)?,
Expand Down

0 comments on commit ced72f4

Please sign in to comment.