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

'encoding' option doesn't change output #268

Closed
rightaway opened this issue Jan 23, 2017 · 4 comments
Closed

'encoding' option doesn't change output #268

rightaway opened this issue Jan 23, 2017 · 4 comments

Comments

@rightaway
Copy link

rightaway commented Jan 23, 2017

If I set the like this got.stream(url, { encoding: 'latin1' }), it doesn't seem to change the output as I would have expected for the file contents. I then tried changing the encoding string to a random string, and got didn't report any error. Is the encoding option being used? I'm using version 6.6.3.

Same with setting the option to null, it should return a Buffer but doesn't seem to change anything.

@floatdrop
Copy link
Contributor

@rightaway can you post code snippet, that reproduces error?

@sindresorhus
Copy link
Owner

From the Node.js docs:

Note: Today's browsers follow the WHATWG spec which aliases both 'latin1' and ISO-8859-1 to win-1252. This means that while doing something like http.get(), if the returned charset is one of those listed in the WHATWG spec it's possible that the server actually returned win-1252-encoded data, and using 'latin1' encoding may incorrectly decode the characters. - https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings

@rightaway
Copy link
Author

Does it mean I need to change 'latin1' to 'win-1252' in the code sample above? I've tried it but still the same result. How can I get it to output the file as expected?

@sindresorhus
Copy link
Owner

I don't know. The Node.js docs are unclear about what you should do. I guess the safest thing to do would be to manually convert using something like https://github.com/ashtuchkin/iconv-lite

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

No branches or pull requests

3 participants