Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
barrowsys committed Apr 6, 2021
1 parent 752b035 commit 5518c16
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/web/clients/download/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Creates a temporary directory with [`tempfile::Builder`] and downloads
a file over HTTP using [`reqwest::get`] asynchronously.

Creates a target [`File`] with name obtained from [`Response::url`] within
[`tempdir()`] and copies downloaded data into it with [`io::copy`].
[`tempdir()`] and writes downloaded data into it with [`Writer::write_all`].
The temporary directory is automatically removed on program exit.

```rust,edition2018,no_run
use error_chain::error_chain;
use std::io::copy;
use std::io::Write;
use std::fs::File;
use tempfile::Builder;
Expand Down Expand Up @@ -41,15 +41,15 @@ async fn main() -> Result<()> {
println!("will be located under: '{:?}'", fname);
File::create(fname)?
};
let content = response.text().await?;
copy(&mut content.as_bytes(), &mut dest)?;
let content = response.bytes().await?;
dest.write_all(&content)?;
Ok(())
}
```

[`File`]: https://doc.rust-lang.org/std/fs/struct.File.html
[`io::copy`]: https://doc.rust-lang.org/std/io/fn.copy.html
[`reqwest::get`]: https://docs.rs/reqwest/*/reqwest/fn.get.html
[`Response::url`]: https://docs.rs/reqwest/*/reqwest/struct.Response.html#method.url
[`tempfile::Builder`]: https://docs.rs/tempfile/*/tempfile/struct.Builder.html
[`tempdir()`]: https://docs.rs/tempfile/3.1.0/tempfile/struct.Builder.html#method.tempdir
[`tempdir()`]: https://docs.rs/tempfile/*/tempfile/struct.Builder.html#method.tempdir
[`Writer::write_all`]: https://doc.rust-lang.org/std/io/trait.Write.html#method.write_all

0 comments on commit 5518c16

Please sign in to comment.