Skip to content

Instantly share code, notes, and snippets.

@viniciusd
Created September 12, 2019 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viniciusd/4c38744c0e2512e0e8244cf88728a0f1 to your computer and use it in GitHub Desktop.
Save viniciusd/4c38744c0e2512e0e8244cf88728a0f1 to your computer and use it in GitHub Desktop.
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