From e5c852291fc1368f9286310b55be22c2ee9e80e3 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 27 Jan 2021 11:13:34 +0100 Subject: Add bytes written/total bytes to status bar message Signed-off-by: Matthias Beyer --- src/commands/source.rs | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/commands/source.rs b/src/commands/source.rs index 5284678..8b1cf3e 100644 --- a/src/commands/source.rs +++ b/src/commands/source.rs @@ -271,10 +271,18 @@ pub async fn download( bar.set_length(len); } let mut stream = reqwest::get(source.url().as_ref()).await?.bytes_stream(); + let mut bytes_written = 0; while let Some(bytes) = stream.next().await { let bytes = bytes?; file.write_all(bytes.as_ref()).await?; + bytes_written += bytes.len(); + bar.inc(bytes.len() as u64); + if let Some(len) = response.content_length() { + bar.set_message(&format!("Downloading {} ({}/{} bytes)", source.url(), bytes_written, len)); + } else { + bar.set_message(&format!("Downloading {} ({} bytes)", source.url(), bytes_written)); + } } file.flush().await?; -- cgit v1.2.3