summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fatcat-cli/src/download.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/fatcat-cli/src/download.rs b/fatcat-cli/src/download.rs
index cf520fe..2297652 100644
--- a/fatcat-cli/src/download.rs
+++ b/fatcat-cli/src/download.rs
@@ -1,6 +1,6 @@
use anyhow::{anyhow, Context, Result};
use fatcat_openapi::models::{FileEntity, ReleaseEntity};
-use indicatif::ProgressBar;
+use indicatif::{ProgressBar, ProgressStyle};
use log::info;
use reqwest::header::USER_AGENT;
use std::fmt;
@@ -155,15 +155,22 @@ pub fn download_file(fe: &FileEntity, specifier: &Specifier, output_path: Option
}
};
- // TODO: parse headers, eg size (?)
if !resp.status().is_success() {
std::fs::remove_file(download_path)?;
return Ok(DownloadStatus::HttpError(resp.status().as_u16()));
}
- // TODO: what if no filesize?
- // TODO: compare with resp.content_length(() -> Option<u64>
+ if let Some(content_bytes) = resp.content_length() {
+ if content_bytes != expected_size {
+ std::fs::remove_file(download_path)?;
+ return Ok(DownloadStatus::WrongSize);
+ }
+ }
+
let pb = ProgressBar::new(fe.size.unwrap() as u64);
+ pb.set_style(ProgressStyle::default_bar()
+ .template("{spinner:.green} [{elapsed_precise}] [{bar:40}] {bytes}/{total_bytes} ({eta})")
+ .progress_chars("#>-"));
let out_size = match resp.copy_to(&mut pb.wrap_write(download_file)) {
Ok(r) => r,
Err(e) => {