ISO charset

1,087 views
Skip to first unread message

Rodrigo Gregorio

unread,
Jan 1, 2011, 10:00:08 PM1/1/11
to nodejs
Hi Ninjas,

How to solve the problem with ISO charset on response data in node.js?

sample code

request({uri:url}, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
});

get body data: a?ai
expected: açai

Mikeal Rogers

unread,
Jan 1, 2011, 11:08:39 PM1/1/11
to nod...@googlegroups.com
request just appends each buffer it gets to a string which it sends to the final callback. That means that the default .toString() is getting called.

I can add support for an encoding being sent to toString() if there is a need for it. Alternatively you can pass a stream that the body will get piped to so you'll have the raw buffer objects.

-Mikeal



Rodrigo Gregorio
January 1, 2011 January 1, 20117:00 PM

WebDeveloper

unread,
Jan 2, 2011, 8:12:51 AM1/2/11
to nod...@googlegroups.com
thks man,

I solve this,fork main.js into package request /usr/local/lib/node/.npm/request/0.10.0/package/lib/main.js

options.request.addListener("response", function (response) {
    var buffer;

    //fix charset
    response.setEncoding('binary');
    //end fix

              if (options.responseBodyStream) {...

sry my very bad english

Saudações do Brasil!

2011/1/2 Mikeal Rogers <mikeal...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com.
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nodejs?hl=en.

compose-unknown-contact.jpg

cwolves

unread,
Jan 2, 2011, 2:50:54 PM1/2/11
to nodejs
set it to utf8, not binary:

response.setEncoding('utf8');

-Mark

On Jan 2, 5:12 am, WebDeveloper <emailforte...@gmail.com> wrote:
> thks man,
>
> I solve this,fork main.js into package
> request /usr/local/lib/node/.npm/request/0.10.0/package/lib/main.js
>
> options.request.addListener("response", function (response) {
>     var buffer;
>
>     //fix charset
>     response.setEncoding('binary');
>     //end fix
>
>               if (options.responseBodyStream) {...
>
> sry my very bad english
>
> Saudações do Brasil!
>
> 2011/1/2 Mikeal Rogers <mikeal.rog...@gmail.com>
>
>
>
>
>
>
>
> >  request just appends each buffer it gets to a string which it sends to the
> > final callback. That means that the default .toString() is getting called.
>
> > I can add support for an encoding being sent to toString() if there is a
> > need for it. Alternatively you can pass a stream that the body will get
> > piped to so you'll have the raw buffer objects.
>
> > -Mikeal
>
> >  ------------------------------
>
> >    Rodrigo Gregorio <emailforte...@gmail.com>
> > January 1, 2011 January 1, 20117:00 PM
>
> > Hi Ninjas,
>
> > How to solve the problem with ISO charset on response data in node.js?
>
> > sample code
>
> > request({uri:url}, function (error, response, body) {
> > if (!error && response.statusCode == 200) {
> > console.log(body);
> > }
> > });
>
> > get body data: a?ai
> > expected: açai
>
> >    --
> > You received this message because you are subscribed to the Google Groups
> > "nodejs" group.
> > To post to this group, send email to nod...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > nodejs+un...@googlegroups.com<nodejs%2Bunsu...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/nodejs?hl=en.
>
>
>
>  compose-unknown-contact.jpg
> 1KViewDownload

WebDeveloper

unread,
Jan 2, 2011, 2:54:50 PM1/2/11
to nod...@googlegroups.com
utf8 dont work for me... my fisrt try :)

2011/1/2 cwolves <cwo...@gmail.com>
To unsubscribe from this group, send email to nodejs+un...@googlegroups.com.

Rodrigo Gregorio

unread,
Jan 13, 2011, 5:02:59 PM1/13/11
to nodejs
nodejs not know how it works with the charset hours
response.setEncoding ('utf8'); work hours
response.setEncoding('binary'); is what works to fit the characters

On 2 jan, 17:54, WebDeveloper <emailforte...@gmail.com> wrote:
> utf8 dont work for me... my fisrt try :)
>
> 2011/1/2 cwolves <cwol...@gmail.com>
> > <nodejs%2Bunsu...@googlegroups.com<nodejs%252Bunsubscribe@googlegroups. com>
Reply all
Reply to author
Forward
0 new messages