Unpacking a buffer produces string #45

Closed
jacwright opened this Issue May 13, 2013 · 3 comments

Projects

None yet

2 participants

@jacwright

A buffer goes into msgpack, a string comes back out. It should be a buffer object when it is unpacked.

Example:
var buffer = fs.readFileSync("avatar.png")
var person = {
name: "Bob",
avatar: buffer
}

person = msgpack.unpack(msgpack.pack(person))

console.log(typeof person.avatar) // you get "string", should be a Buffer

The line in msgpack.cc that does this is:

case MSGPACK_OBJECT_RAW:
return String::New(mo->via.raw.ptr, mo->via.raw.size);

I'm not a C coder nor do I know anything about c-lib bindings with v8, otherwise this would be a pull request instead. Could you please fix this?

@godsflaw
Collaborator

You may want to attach this to:
#6

At some point we need to just go a direction.

@jacwright

Ah, didn't even realize MSGPACK_OBJECT_RAW was being used for multiple types. I'll go comment on the other issue, but definitely stick with string and don't purport to support buffers, since really you can't. That will allow the developer a choice of encoding and decoding with base64 instead of having them find out the hard way that buffers aren't really supported.

@godsflaw
Collaborator

Going to close this issue so that we just have issue #6 on the topic.

@godsflaw godsflaw closed this Jun 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment