codegen: Tweak code around BufWriter

This commit is contained in:
Taiki Endo
2025-02-11 18:40:20 +09:00
parent dd213e8db4
commit 771bd4fef9
2 changed files with 8 additions and 4 deletions

View File

@@ -319,7 +319,7 @@ fn main() -> Result<()> {
if download_cache.is_file() {
eprintln!("already downloaded");
fs::File::open(download_cache)?.read_to_end(&mut buf)?;
fs::File::open(download_cache)?.read_to_end(&mut buf)?; // Not buffered because it is read at once.
} else {
response.into_body().into_reader().read_to_end(&mut buf)?;
eprintln!("download complete");

View File

@@ -1,6 +1,10 @@
// SPDX-License-Identifier: Apache-2.0 OR MIT
use std::{env, fmt, io::Write as _, path::PathBuf};
use std::{
env, fmt,
io::{BufWriter, Write as _},
path::PathBuf,
};
use anyhow::Result;
use fs_err as fs;
@@ -111,8 +115,7 @@ fn main() -> Result<()> {
let mut markdown_file = workspace_root.clone();
markdown_file.push("TOOLS.md");
let file = std::fs::File::create(markdown_file).expect("Unable to create file");
let mut file = std::io::BufWriter::new(file);
let mut file = BufWriter::new(fs::File::create(markdown_file).unwrap()); // Buffered because it is written many times.
file.write_all(HEADER.as_bytes()).expect("Unable to write header");
@@ -121,6 +124,7 @@ fn main() -> Result<()> {
}
file.write_all(FOOTER.as_bytes()).expect("Unable to write footer");
file.flush()?;
Ok(())
}