Skip to content

Commit

Permalink
Use BufReader and BufWriter 馃う
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Mackie committed Feb 11, 2023
1 parent 98238cc commit 4ce3e82
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 @@ -188,14 +188,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 @@ -205,7 +208,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 @@ -321,7 +324,7 @@ fn run_js(inputs: Vec<String>, outputs: Vec<String>) -> Result<()> {

let js = generate_javascript(&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 @@ -363,7 +366,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 4ce3e82

Please sign in to comment.