refactor all write_alls to ensure flushing (#5567)

This commit is contained in:
Darren Schroeder
2022-05-17 13:28:18 -05:00
committed by GitHub
parent f26d3bf8d7
commit f0cb2f38df
14 changed files with 85 additions and 85 deletions

View File

@ -1,3 +1,5 @@
pub mod utils;
pub use utils::enable_vt_processing;
pub use utils::{
enable_vt_processing, stdout_write_all_and_flush, stdout_write_all_as_binary_and_flush,
};

View File

@ -1,4 +1,4 @@
use std::io::Result;
use std::io::{Result, Write};
pub fn enable_vt_processing() -> Result<()> {
#[cfg(windows)]
@ -23,3 +23,23 @@ pub fn enable_vt_processing() -> Result<()> {
}
Ok(())
}
pub fn stdout_write_all_and_flush(output: String) -> Result<()> {
let stdout = std::io::stdout();
let ret = match stdout.lock().write_all(output.as_bytes()) {
Ok(_) => Ok(stdout.lock().flush()?),
Err(err) => Err(err),
};
ret
}
pub fn stdout_write_all_as_binary_and_flush(output: &[u8]) -> Result<()> {
let stdout = std::io::stdout();
let ret = match stdout.lock().write_all(output) {
Ok(_) => Ok(stdout.lock().flush()?),
Err(err) => Err(err),
};
ret
}