From b6393783d07405d0a13e03f6e752428974703754 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Tue, 28 Apr 2026 13:41:11 +0200 Subject: nasm: use buffered writing for full ROMs as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This was already implemented for the --split-segments option. Not let's bring this when building full ROM files, as writing things byte by byte is slow. Signed-off-by: Miquel Sabaté Solà --- crates/nasm/src/main.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'crates') diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs index 2668556..12ac887 100644 --- a/crates/nasm/src/main.rs +++ b/crates/nasm/src/main.rs @@ -308,14 +308,14 @@ fn main() { }; // Select the output stream. - let (mut output, output_name): (Box, &str) = if args.stdout { - (Box::new(io::stdout()), "") + let (mut output, output_name): (BufWriter>, &str) = if args.stdout { + (BufWriter::new(Box::new(io::stdout())), "") } else if args.split { - (Box::new(io::stdout()), "") + (BufWriter::new(Box::new(io::stdout())), "") } else { let name = args.out.unwrap_or(String::from("out.nes")); match File::create(&name) { - Ok(f) => (Box::new(f), args.file.as_str()), + Ok(f) => (BufWriter::new(Box::new(f)), args.file.as_str()), Err(_) => { die(format!("could not create file '{name}'")); return; @@ -419,6 +419,10 @@ fn main() { eprintln!("error: could not write result in '{output_name}': {e}"); std::process::exit(1); } + if let Err(e) = output.flush() { + eprintln!("error: could not write to '{output_name}': {e}"); + std::process::exit(1); + } } } -- cgit v1.2.3