Created
October 24, 2020 01:07
-
-
Save jayhuang75/064dc568e2378f9f6ac5b5dd4b330131 to your computer and use it in GitHub Desktop.
SMS Alert Rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub async fn fetch(url: &str, dir_name: &str, file_name: &str) -> Result<String, Box<dyn Error>> { | |
// application start time | |
let start = Instant::now(); | |
// create folder if not exist | |
fs::create_dir_all(dir_name)?; | |
// download the file | |
let resp = reqwest::get(url).await?; | |
// paser to context txt | |
let content = resp.text().await?; | |
// prepare the output dest | |
let mut out = File::create(format!("{}/{}", dir_name, file_name)).await?; | |
// ouput | |
io::copy(&mut content.as_bytes(), &mut out).await?; | |
// mesurement the elapsed time | |
let duration = start.elapsed(); | |
info!("[download] total download time: {:?}", duration); | |
Ok(format!("{}/{}", dir_name, file_name)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment