summaryrefslogtreecommitdiff
path: root/src/install.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/install.rs')
-rw-r--r--src/install.rs31
1 files changed, 6 insertions, 25 deletions
diff --git a/src/install.rs b/src/install.rs
index e58735e..fae66fc 100644
--- a/src/install.rs
+++ b/src/install.rs
@@ -11,7 +11,7 @@ use std::collections::HashMap;
use std::os::unix::fs::{symlink, PermissionsExt};
use tempfile::{NamedTempFile, tempdir};
use crate::config;
-use crate::progress::{Spinner, format_bytes};
+use crate::progress::{Spinner, DownloadBar};
use crate::debug;
use tar::Archive as TarArchive;
use zstd::stream::read::Decoder as ZstdDecoder;
@@ -301,6 +301,9 @@ pub fn download_and_verify(url: &str, expected_sha: &str, _cfg: &config::Config)
.and_then(|v| v.to_str().ok())
.and_then(|s| s.parse::<u64>().ok());
+ let filename = url.rsplit('/').next().unwrap_or(url);
+ let mut bar = DownloadBar::new(filename, total_size);
+
let mut tmp_file = NamedTempFile::new()
.map_err(|e| format!("Failed to create temp file: {}", e))?;
let file_path = tmp_file.path().to_path_buf();
@@ -308,7 +311,6 @@ pub fn download_and_verify(url: &str, expected_sha: &str, _cfg: &config::Config)
let mut hasher = Sha256::new();
let mut reader = response;
let mut buf = [0u8; 65536];
- let mut downloaded: u64 = 0;
loop {
let n = reader
@@ -320,31 +322,10 @@ pub fn download_and_verify(url: &str, expected_sha: &str, _cfg: &config::Config)
hasher.update(&buf[..n]);
tmp_file.write_all(&buf[..n])
.map_err(|e| format!("Failed to write to temp file: {}", e))?;
- downloaded += n as u64;
-
- match total_size {
- Some(total) if total > 0 => {
- let pct = downloaded * 40 / total;
- let bar = format!(
- "{}>{}",
- "=".repeat(pct.saturating_sub(1) as usize),
- " ".repeat((40 - pct) as usize)
- );
- eprint!(
- "\r\x1b[K\x1b[36m[{}]\x1b[0m {} / {}",
- bar,
- format_bytes(downloaded),
- format_bytes(total)
- );
- }
- _ => {
- eprint!("\r\x1b[K{} downloaded", format_bytes(downloaded));
- }
- }
- std::io::stderr().flush().ok();
+ bar.update(n as u64);
}
- eprintln!("\r\x1b[K\x1b[32m✓\x1b[0m Downloaded {}", format_bytes(downloaded));
+ bar.finish();
if !expected_sha.is_empty() {
let hash = format!("{:x}", hasher.finalize());