> On Oct 18, 2015, at 10:19 PM, Brian Craft <[email protected]> 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/A8AE9561-62CA-4460-9083-4B10321061A0%40dinhe.net.
For more options, visit https://groups.google.com/d/optout.

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

Reply via email to