> On Oct 19, 2015, at 12:03 AM, Brian Craft <craft.br...@gmail.com> wrote:
> 
> How would I pick one? Are the encodings documented? Or listed somewhere?
> 
> I eventually worked out with much pain that passing through Buffer and back 
> sometimes swaps byte order in the words, for reasons I don't understand. The 
> ucs2 encoding, which I only found by looking at the source code, avoids this.

Well, generally one avoids ever storing binary data in strings that can't carry 
the full range of things -- that's why things like Base64 were invented, to 
reduce arbitrary bytes down to a character set that's easy to manipulate as 
text.

Unicode's a tricky beast -- what's allowed and not is pretty lumpy and uneven 
in places -- surrogate characters, handling of nulls, replacement with the 
replacement character for things that are out of bounds. You don't want the 
mess of all human languages mixed with the exacting representation of binary 
data.

So it sounds like you found ucs2, which is a naive mapping of the basic plane 
of unicode into 16-bit codepoints -- two ways to map that to bytes, of course 
-- low first or high first -- so byte swapping can be an issue. It's not 
documented because it pretty much should never be used -- though it sounds like 
you've been forced into it since you're interfacing with a library that 
squishes binary data into strings that way.

Good luck! 

Aria

-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to nodejs+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/8886EE0E-8516-4D17-9DD0-94FD641E3F7D%40dinhe.net.
For more options, visit https://groups.google.com/d/optout.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to