Sannis / node-ubjson

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

Add usage example to README #29

Closed donpdonp closed 9 years ago

donpdonp commented 11 years ago

The README could use an example. I'm having trouble with getting a hello-world going in node-ubjson. From reading the code I found packToBufferSync, but its buffer parameter requires a size during initialization. How am I to know the buffer size before the binary data (a string in this case) is ubjson-ified?

var ubj = require('ubjson')

var buffer = new Buffer() 
ubj.packToBufferSync("binary data", buffer)

Error: First argument needs to be a number (in buffer.js) Thanks!

Sannis commented 9 years ago

You should use pre-allocated buffer with synchronous methods. Otherwise you can use streaming interface.