Skip to content

Commit 771bd4f

Browse files
committed
codegen: Tweak code around BufWriter
1 parent dd213e8 commit 771bd4f

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

tools/codegen/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ fn main() -> Result<()> {
319319

320320
if download_cache.is_file() {
321321
eprintln!("already downloaded");
322-
fs::File::open(download_cache)?.read_to_end(&mut buf)?;
322+
fs::File::open(download_cache)?.read_to_end(&mut buf)?; // Not buffered because it is read at once.
323323
} else {
324324
response.into_body().into_reader().read_to_end(&mut buf)?;
325325
eprintln!("download complete");

tools/codegen/src/tools-markdown.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// SPDX-License-Identifier: Apache-2.0 OR MIT
22

3-
use std::{env, fmt, io::Write as _, path::PathBuf};
3+
use std::{
4+
env, fmt,
5+
io::{BufWriter, Write as _},
6+
path::PathBuf,
7+
};
48

59
use anyhow::Result;
610
use fs_err as fs;
@@ -111,8 +115,7 @@ fn main() -> Result<()> {
111115
let mut markdown_file = workspace_root.clone();
112116
markdown_file.push("TOOLS.md");
113117

114-
let file = std::fs::File::create(markdown_file).expect("Unable to create file");
115-
let mut file = std::io::BufWriter::new(file);
118+
let mut file = BufWriter::new(fs::File::create(markdown_file).unwrap()); // Buffered because it is written many times.
116119

117120
file.write_all(HEADER.as_bytes()).expect("Unable to write header");
118121

@@ -121,6 +124,7 @@ fn main() -> Result<()> {
121124
}
122125

123126
file.write_all(FOOTER.as_bytes()).expect("Unable to write footer");
127+
file.flush()?;
124128

125129
Ok(())
126130
}

0 commit comments

Comments
 (0)