@@ -6,12 +6,12 @@ Creates a temporary directory with [`tempfile::Builder`] and downloads
66a file over HTTP using [ ` reqwest::get ` ] asynchronously.
77
88Creates a target [ ` File ` ] with name obtained from [ ` Response::url ` ] within
9- [ ` tempdir() ` ] and copies downloaded data into it with [ ` io::copy ` ] .
9+ [ ` tempdir() ` ] and writes downloaded data into it with [ ` Writer::write_all ` ] .
1010The temporary directory is automatically removed on program exit.
1111
1212``` rust,edition2018,no_run
1313use error_chain::error_chain;
14- use std::io::copy ;
14+ use std::io::Write ;
1515use std::fs::File;
1616use tempfile::Builder;
1717
@@ -41,15 +41,15 @@ async fn main() -> Result<()> {
4141 println!("will be located under: '{:?}'", fname);
4242 File::create(fname)?
4343 };
44- let content = response.text ().await?;
45- copy(&mut content.as_bytes(), &mut dest )?;
44+ let content = response.bytes ().await?;
45+ dest.write_all(&content )?;
4646 Ok(())
4747}
4848```
4949
5050[ `File` ] : https://doc.rust-lang.org/std/fs/struct.File.html
51- [ `io::copy` ] : https://doc.rust-lang.org/std/io/fn.copy.html
5251[ `reqwest::get` ] : https://docs.rs/reqwest/*/reqwest/fn.get.html
5352[ `Response::url` ] : https://docs.rs/reqwest/*/reqwest/struct.Response.html#method.url
5453[ `tempfile::Builder` ] : https://docs.rs/tempfile/*/tempfile/struct.Builder.html
55- [ `tempdir()` ] : https://docs.rs/tempfile/3.1.0/tempfile/struct.Builder.html#method.tempdir
54+ [ `tempdir()` ] : https://docs.rs/tempfile/*/tempfile/struct.Builder.html#method.tempdir
55+ [ `Writer::write_all` ] : https://doc.rust-lang.org/std/io/trait.Write.html#method.write_all
0 commit comments