From 191cd2c9705b144248525f0ea9d7e0070a079827 Mon Sep 17 00:00:00 2001 From: WindSoilder Date: Sat, 10 Jun 2023 16:07:26 +0800 Subject: [PATCH] `save` command: Don't use BufWriter to write external strem to a file (#9377) # Description Fixes: #9293 The problem is caused by `save` makes a `BufferWriter` for output file, when external commands redirect it's output to a file, the content is bufferred first... To fix the issue, I'd like to introduce a `--no-buf` flag for `save` command, and it's only used in redirection scenario. Sorry it's hard to test against it in test, because it requires external command to sleep or pause... # User-Facing Changes # Tests + Formatting # After Submitting --------- Co-authored-by: Darren Schroeder <343840+fdncred@users.noreply.github.com> --- crates/nu-command/src/filesystem/save.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/crates/nu-command/src/filesystem/save.rs b/crates/nu-command/src/filesystem/save.rs index eb9664f36e..5b73a6d2ff 100644 --- a/crates/nu-command/src/filesystem/save.rs +++ b/crates/nu-command/src/filesystem/save.rs @@ -6,7 +6,7 @@ use nu_protocol::{ Type, Value, }; use std::fs::File; -use std::io::{BufWriter, Write}; +use std::io::Write; use std::path::Path; use std::thread; @@ -349,7 +349,9 @@ fn stream_to_file( span: Span, progress: bool, ) -> Result { - let mut writer = BufWriter::new(file); + // https://github.com/nushell/nushell/pull/9377 contains the reason + // for not using BufWriter + let mut writer = file; let mut bytes_processed: u64 = 0; let bytes_processed_p = &mut bytes_processed;