themasch/node-bencode — pull request #27 by jhermsmeier (2014-05-09 02:02:01+00:00)
Title: Implement binary-safe dictionary

After having a look at the recent binary-key dictionary implementation, I came to the realization that it is actually exactly the same as it was before: `.binarySet( key, value )` behaves in the exact same way as setting a buffer on a regular object does, except that it stores the keys in a seperate array. Just calling `.toString()` on a buffer is not safe (as mentioned in #24) and even was the reason for #24 to happen. Why didn't we notice this?

So, here's a binary-safe implementation of a dictionary, which isn't too unperformant, but still not what I'd like to see as an API. I also couldn't find any record of binary keys in the specifications or anywhere else, but apparently it is used. Where is this documented? The spec only defined UTF8 encoded keys.

This is just a proof of concept for now, tests haven't been adjusted and it is **not** ready to merge.
I'd like to see a discussion around the general issue with binary keys, when and where they appear for what reason and how to solve access and iteration on an eventual binary-safe implementation of a dictionary.