1
0
mirror of https://github.com/jht5945/buildj.git synced 2025-12-29 02:10:04 +08:00

first public version

This commit is contained in:
2019-07-28 01:05:34 +08:00
parent ea396a553b
commit 2d8373a1a2
9 changed files with 2553 additions and 4 deletions

22
src/http.rs Normal file
View File

@@ -0,0 +1,22 @@
use std::{
fs::File,
};
use super::rust_util::{
copy_io,
XResult,
};
pub fn download_url(url: &str, dest: &mut File) -> XResult<()> {
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(),
};
copy_io(&mut response, dest, header_content_length)?;
Ok(())
}
pub fn get_url(url: &str) -> XResult<String> {
Ok(reqwest::get(url)?.text()?)
}