I'm trying to fetch a web page that has latin characters and encoding set to iso-8859-15 but it doesn't work.
I always get the error: "throw new Error('Unknown encoding');"
Is this a bug or I'm I doing something wrong?
Can you tell me which encodings does it support?
you probably just need to set the encoding paramater:
valid encoding options are defined in node.js, look at the docs for http.ClientResponse.setEncoding()
@Migrate: I'm confused about this issue. I tried to set encoding: 'iso-8859-15' in my get() call, but I'm getting an "Unknown encoding" exception. Did this work for you?
@mikeal: I found this list of supported encodings: https://github.com/joyent/node/blob/master/lib/buffer.js#L63, and it doesn't include any ISO encodings, just Unicode. In my case, I was able to get what I need by requesting a binary response, then converting that using iconv-lite. But wouldn't it make sense to integrate this, as an option (and based on meta tag sniffing) into your request module itself?
Specific ISO encodings are useful when you're parsing the response but, most of the time, when the encoding matters this much what you actually want to do is pass the data over without parsing it at all, which is best accomplished with the default buffers.
Thank you Mikael, that makes perfect sense to me. It's just that your module is being used in a "browser-like" fashion by some other modules - in my case, I'm using the spider module to extract information from a site and convert it to XML. Spider does not use your "encoding: null" feature, nor does it attempt to adapt to the encoding, so I guess that's where I should do my complaining.
Still, as the request module is being used by many others, wouldn't it make sense to provide some sort of solution as part of this package, where it would be easy to find?
Just my two cents. Thanks again,