Created
September 12, 2019 21:23
-
-
Save viniciusd/4c38744c0e2512e0e8244cf88728a0f1 to your computer and use it in GitHub Desktop.
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
use hyper::{self,Client}; | |
use hyper::rt::{self,Future,Stream}; | |
use hyper_tls::HttpsConnector; | |
use std::fs::File; | |
use std::io::prelude::*; | |
use futures::future; | |
fn main() { | |
let tls = HttpsConnector::new(4).unwrap(); | |
let client = Client::builder().build::<_,hyper::Body>(tls); | |
let uri = "https://www.7-zip.org/a/7za920.zip".parse().unwrap(); | |
let c = client | |
.get(uri) | |
.map(|data|{ | |
println!("{:?}", data.status()); | |
let mut file = File::create("./t.zip").unwrap(); | |
data | |
.into_body() | |
.for_each(move |chunk|{ | |
file.write_all(chunk.as_ref()).map_err(|e| panic!("{}", e)) | |
}) | |
}) | |
.and_then(|_|{ | |
println!("Arquivo criado"); | |
future::ok(()) | |
}) | |
.map_err(|err|{ | |
println!("{:?}",err) | |
}); | |
rt::run(c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment