use indicatif::{ProgressBar, ProgressStyle};
pub fn fetch_bytes(url: &str) -> Result<Vec<u8>, reqwest::Error> {
let response = reqwest::blocking::Client::builder()
.timeout(std::time::Duration::from_secs(30))
.build()?
.get(url)
.send()?
.error_for_status()?;
let total = response.content_length().unwrap_or(0);
let pb = ProgressBar::new(total);
pb.set_style(
ProgressStyle::with_template(" [{bar:40.cyan/blue}] {bytes}/{total_bytes} ({eta})")
.expect("valid progress template")
.progress_chars("=> "),
);
let bytes = response.bytes()?;
pb.set_length(bytes.len() as u64);
pb.finish_and_clear();
Ok(bytes.to_vec())
}