1
0
mirror of https://github.com/jht5945/buildj.git synced 2025-12-28 17:50:05 +08:00

add verbose

This commit is contained in:
2019-08-08 00:41:57 +08:00
parent 853a237c7a
commit 438fcd66a6
2 changed files with 24 additions and 0 deletions

View File

@@ -4,19 +4,35 @@ use std::{
use rust_util::{
util_io::copy_io,
util_msg::{
print_message,
MessageType,
},
XResult,
};
use super::misc::*;
pub fn download_url(url: &str, dest: &mut File) -> XResult<()> {
let verbose = is_verbose();
if verbose {
print_message(MessageType::INFO, &format!("Download URL: {}", url));
}
let mut response = reqwest::get(url)?;
let header_content_length: i64 = match response.headers().get("content-length") {
None => -1,
Some(len_value) => len_value.to_str().unwrap().parse::<i64>().unwrap(),
};
if verbose {
print_message(MessageType::INFO, &format!("Content-Length: {}", header_content_length));
}
copy_io(&mut response, dest, header_content_length)?;
Ok(())
}
pub fn get_url(url: &str) -> XResult<String> {
if is_verbose() {
print_message(MessageType::INFO, &format!("Get URL: {}", url));
}
Ok(reqwest::get(url)?.text()?)
}