This is interesting. this is a problem with my testing code, looks like
UTF8 is the default encoding when writing to a file. :/
i need to tweak to get a better example. thanks.
On Wednesday, April 23, 2014 12:15:17 PM UTC-7, Rebecca Turner wrote:
> ok, let's try to reproduce this:
>
> > var buf = new Buffer([ -108, 1, 72, 116, 104, 105, 115, 32, 105, 115,
> 32, 116, 104, 101, 32, 115, 116, 114, 105, 110, 103, 32, 70, 19, 0, 70, 18,
> 0, -2, 37, 0, 114, 37, 0 ]);
>
> Results in:
>
> <Buffer 94 01 48 74 68 69 73 20 69 73 20 74 68 65 20 73 74 72 69 6e 67 20
> 46 13 00 46 12 00 fe 25 00 72 25 00>
>
> > var str = buf.toString('binary');
>
> '”\u0001Hthis is the string F\u0013\u0000F\u0012\u0000þ%\u0000r%\u0000'
>
> If we want to see it's content, we can turn it back into a buffer with:
>
> > new Buffer(str, 'binary');
>
> <Buffer 94 01 48 74 68 69 73 20 69 73 20 74 68 65 20 73 74 72 69 6e 67 20
> 46 13 00 46 12 00 fe 25 00 72 25 00>
>
> But I notice that if you leave the encoding off of the second one it'll
> encode the whole thing as UTF8 and you get:
>
> > new Buffer(str);
>
> <Buffer c2 94 01 48 74 68 69 73 20 69 73 20 74 68 65 20 73 74 72 69 6e 67
> 20 46 13 00 46 12 00 c3 be 25 00 72 25 00>
>
> Which matches your:
>
> enc.toString('binary') [ -62 -108 1 72 116 104 105 115 32 105 115 32 116
> 104 101 32 115 116 114 105 110 103 32 70 19 0 70 18 0 -61 -66 37 0 114 37 0
> ]
>
> So that's your problem, when you go to convert the "binary" string back
> into a buffer, you're doing it with a utf8 encoding. You need to keep the
> same encoding throughout.
>
> -- Rebecca
>
>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.