Sannis / node-ubjson

Universal Binary JSON packer/unpacker for Node.js
http://sannis.github.com/node-ubjson
Other
35 stars 5 forks source link

example code issue #36

Open 4fthawaiian opened 8 years ago

4fthawaiian commented 8 years ago

In looking at the example code you show in the readme, it shows this:

                buffer = buffer.slice(0, offset);

This creates a buffer containing some binary characters near the beginning and then simply the JSON string following, which doesn't seem correct. If I change the line to this:

                buffer = buffer.slice(offset);

It then outputs a pure binary buffer, which still fails in the parser I'm working on. The second approach makes somewhat more sense to me, but I'm not convinced either is working correctly. I'm sending the result back in nodejs like this:

            UBJSON.packToBuffer(jsonString, buffer, function (error, offset) {
                if (error) {
                    throw error;
                }

                console.log(buffer);
                buffer = buffer.slice(0, offset);

                response.attachment();
                response.type('application/binary');
                response.send(buffer);
            });

Does this seem like a valid approach? Or, am I totally misunderstanding the example?

4fthawaiian commented 8 years ago

I should mention that I've used this exact method previously to send zipped JSON back to a consumer, so I know that the node methodology is sane.