From aeefa694bff18f66d8aaab53c4a4eb917e456e48 Mon Sep 17 00:00:00 2001 From: Pascal Hertleif Date: Wed, 12 Feb 2025 13:53:49 +0100 Subject: [PATCH] fix: Use BufWriter for list output Also replaces one `print` call with `write`. Fixes #702 --- CHANGELOG.md | 1 + src/list.rs | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe884ab..e44b061 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Categories Used: - Fix logging IO bottleneck [\#642](https://github.com/ouch-org/ouch/pull/642) ([AntoniosBarotsis](https://github.com/AntoniosBarotsis)) - Support decompression over stdin [\#692](https://github.com/ouch-org/ouch/pull/692) ([rcorre](https://github.com/rcorre)) - Make `--format` more forgiving with the formatting of the provided format [\#519](https://github.com/ouch-org/ouch/pull/519) ([marcospb19](https://github.com/marcospb19)) +- Use buffered writer for list output [\#764](https://github.com/ouch-org/ouch/pull/764) ([killercup](https://github.com/killercup)) ## [0.5.1](https://github.com/ouch-org/ouch/compare/0.5.0...0.5.1) diff --git a/src/list.rs b/src/list.rs index c065925..8491798 100644 --- a/src/list.rs +++ b/src/list.rs @@ -1,7 +1,7 @@ //! Some implementation helpers related to the 'list' command. use std::{ - io::{stdout, Write}, + io::{stdout, BufWriter, Write}, path::{Path, PathBuf}, }; @@ -32,16 +32,16 @@ pub fn list_files( files: impl IntoIterator>, list_options: ListOptions, ) -> crate::Result<()> { - let out = &mut stdout().lock(); + let mut out = BufWriter::new(stdout().lock()); let _ = writeln!(out, "Archive: {}", EscapedPathDisplay::new(archive)); if list_options.tree { let tree = files.into_iter().collect::>()?; - tree.print(out); + tree.print(&mut out); } else { for file in files { let FileInArchive { path, is_dir } = file?; - print_entry(out, EscapedPathDisplay::new(&path), is_dir); + print_entry(&mut out, EscapedPathDisplay::new(&path), is_dir); } } Ok(()) @@ -143,7 +143,7 @@ mod tree { false => draw::FINAL_BRANCH, }; - print!("{prefix}{final_part}"); + let _ = write!(out, "{prefix}{final_part}"); let is_dir = match self.file { Some(FileInArchive { is_dir, .. }) => is_dir, None => true,