Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Use BufReader and BufWriter 🤦
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Mackie committed Feb 8, 2023
1 parent 2060206 commit 741ca1a
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions crates/ditto-make/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn run_ast(build_dir: &str, inputs: Vec<String>, outputs: Vec<String>) -> Result
let path = Path::new(&input);
match full_extension(path) {
Some(common::EXTENSION_DITTO) => {
let mut file = File::open(path).into_diagnostic()?;
let mut file = std::io::BufReader::new(File::open(path).into_diagnostic()?);
let mut contents = String::new();
file.read_to_string(&mut contents).into_diagnostic()?;
ditto_input = Some((path.to_string_lossy().into_owned(), contents));
Expand Down Expand Up @@ -219,14 +219,17 @@ fn run_ast(build_dir: &str, inputs: Vec<String>, outputs: Vec<String>) -> Result
match full_extension(path) {
Some(common::EXTENSION_AST) => {
let file = File::create(path).into_diagnostic()?;
common::serialize(file, &(&ditto_input_name, &ast))?;
let writer = std::io::BufWriter::new(file);
common::serialize(writer, &(&ditto_input_name, &ast))?;
}
Some(common::EXTENSION_AST_EXPORTS) => {
let file = File::create(path).into_diagnostic()?;
common::serialize(file, &(&ast.module_name, &ast.exports))?;
let writer = std::io::BufWriter::new(file);
common::serialize(writer, &(&ast.module_name, &ast.exports))?;
}
Some(common::EXTENSION_CHECKER_WARNINGS) => {
let file = File::create(path).into_diagnostic()?;
let writer = std::io::BufWriter::new(file);
let warnings_bundle = if warnings.is_empty() {
None
} else {
Expand All @@ -236,7 +239,7 @@ fn run_ast(build_dir: &str, inputs: Vec<String>, outputs: Vec<String>) -> Result
warnings: warnings.clone(),
})
};
common::serialize(file, &warnings_bundle)?;
common::serialize(writer, &warnings_bundle)?;
print_warnings = false;
}
other => panic!("unexpected output extension: {:#?}", other),
Expand Down Expand Up @@ -336,7 +339,7 @@ fn run_js(inputs: Vec<String>, outputs: Vec<String>) -> Result<()> {
js::codegen(&codegen_config, ast)
};

let mut js_file = File::create(&js_output_path).into_diagnostic()?;
let mut js_file = std::io::BufWriter::new(File::create(&js_output_path).into_diagnostic()?);
js_file.write_all(js.as_bytes()).into_diagnostic()?;

Ok(())
Expand Down Expand Up @@ -372,7 +375,8 @@ fn run_package_json(input: &str, output: &str) -> Result<()> {
}

let file = File::create(output).into_diagnostic()?;
return serde_json::to_writer(file, &object).into_diagnostic();
let writer = std::io::BufWriter::new(file);
return serde_json::to_writer(writer, &object).into_diagnostic();

type Object = Map<String, Value>;
fn merge_objects(mut lhs: Object, mut rhs: Object) -> Object {
Expand Down

0 comments on commit 741ca1a

Please sign in to comment.