From 390a62d88b7e53441235aaa2504c33f66ae5f83c Mon Sep 17 00:00:00 2001 From: "Hatter Jiang@Pixelbook" Date: Wed, 7 Aug 2019 00:06:40 +0800 Subject: [PATCH] add copy_io_with_head --- src/util_io.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/util_io.rs b/src/util_io.rs index 812b528..dfd66ae 100644 --- a/src/util_io.rs +++ b/src/util_io.rs @@ -9,8 +9,14 @@ use super::util_msg::print_lastline; pub const DEFAULT_BUF_SIZE: usize = 8 * 1024; + pub fn copy_io(reader: &mut R, writer: &mut W, total: i64) -> io::Result where R: io::Read, W: io::Write { + copy_io_with_head(reader, writer, total, "Downloading") +} + +pub fn copy_io_with_head(reader: &mut R, writer: &mut W, total: i64, head: &str) -> io::Result + where R: io::Read, W: io::Write { //let written_cell = RefCell::new(0u64); let start = SystemTime::now(); let written = copy_io_callback(reader, writer, total, &|total, written, _len| { @@ -22,12 +28,14 @@ pub fn copy_io(reader: &mut R, writer: &mut W, total: i64) download_speed = format!("{}/s", get_display_size((written / cost) as i64)); } if total > 0 { - print_lastline(&format!("Downloading, Total: {}, Downloaded: {}, Speed: {}", + print_lastline(&format!("{}, Total: {}, Finished: {}, Speed: {}", + head, get_display_size(total), get_display_size(written as i64), download_speed)); } else { - print_lastline(&format!("Downloading, Downloaded: {}, Speed: {}", + print_lastline(&format!("{}, Finished: {}, Speed: {}", + head, get_display_size(written as i64), download_speed)); }