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.

On Sunday, October 18, 2015 at 8:38:14 PM UTC-7, Aria Stewart wrote:
>
>
> > On Oct 18, 2015, at 10:19 PM, Brian Craft <[email protected] 
> <javascript:>> wrote: 
> > 
> > I'm trying to persist a string to disk, but every mechanism I've tried 
> loses bits. The string is holding binary data generated by a third-party 
> lib. 
> > 
> > Searching online has turned up lots of recommendations to use the Buffer 
> class, however I'm also unable to round-trip the data through Buffer 
> without losing bits. That is, in general 
> > 
> > str !== (new Buffer(str, 'binary')).toString('binary')) 
> > 
> > How can I persist a string without losing bits? 
> > 
> > Are there docs anywhere on how the String class encodings work, and how 
> to move data in and out of String without losing bits? 
>
>
> Well, strings are series of unicode codepoints, not unrestricted binary 
> data -- so you can't put arbitrary binary into it without already having 
> encoded it somehow. 
>
> Buffers are the 8-bit-clean array-of-bytes interface you're looking for -- 
> but knowing what this data is and how to get it out of a string is the key 
> part -- if they're encoding binary data in strings, it's a bit of a guess. 
>
> Why did you choose the 'binary' encoding above? It's a bit quirky -- only 
> one way to get binary data into and out of strings, and deprecated since 
> it's a hack. 
>
> 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/b670a970-8dbd-4a48-8502-629f7591c942%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to