Skip to content

Commit ffacfd2

Browse files
authored
fix #644 (#645)
Nice. Good catch.
1 parent 9ef6cf4 commit ffacfd2

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/web/clients/download/basic.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ Creates a temporary directory with [`tempfile::Builder`] and downloads
66
a file over HTTP using [`reqwest::get`] asynchronously.
77

88
Creates 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`].
1010
The temporary directory is automatically removed on program exit.
1111

1212
```rust,edition2018,no_run
1313
use error_chain::error_chain;
14-
use std::io::copy;
14+
use std::io::Write;
1515
use std::fs::File;
1616
use 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

Comments
 (0)