rust-cookbook icon indicating copy to clipboard operation
rust-cookbook copied to clipboard

web/clients/download/basic doesnt handle binary files

Open barrowsys opened this issue 4 years ago • 2 comments
trafficstars

https://github.com/rust-lang-nursery/rust-cookbook/blob/master/src/web/clients/download/basic.md doesnt work if trying to download a binary file (such as an image). Might want to either point this out or modify the example to handle all data.

Doesn't work:

    use std::io::copy;
    // ...
    let content =  response.text().await?;
    copy(&mut content.as_bytes(), &mut dest)?;

Does work:

    use std::io::Write;
    // ...
    let content = response.bytes().await()?;
    dest.write_all(&content)?;

barrowsys avatar Mar 22 '21 20:03 barrowsys

Looks good to me. Asking to @barrowsys to make a merge request. For the fame of being in the git commit log.

stappersg avatar Apr 06 '21 10:04 stappersg

git is painful but its #645

barrowsys avatar Apr 06 '21 18:04 barrowsys