Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download example using response.bytes() instead of response.text() #670

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

frantufro
Copy link

The current example for downloading files interprets the response as text, and then turns it into bytes.

let content = response.text().await?;
copy(&mut content.as_bytes(), &mut dest)?;

This is fine if you're downloading text files, but it will corrupt binary files (I found this issue when downloading PNGs).

In order to fix this I suggest using response.bytes() directly.

let content = response.bytes().await?;
dest.write(&content)?;

This is how I ended up implementing it and it works great.

@frantufro frantufro changed the title Download example using bytes instead of text Download example using response.bytes() instead of response.text() Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant