JSPM

  • Created
  • Published
  • Downloads 1217229
  • Score
    100M100P100Q206519F
  • License MIT

Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC7049).

Package Exports

  • cbor
  • cbor/lib/tagged
  • cbor/lib/utils

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (cbor) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

cbor

Encode and parse data in the Concise Binary Object Representation (CBOR) data format (RFC7049).

Installation:

$ npm install --save cbor

NOTE This package now requires node.js 4.1 or higher. If you want a version that works with older node.js versions, you can install like this:

npm install 'hildjj/node-cbor#node0' --save

Documentation:

See the full API documentation.

From the command line:

$ bin/json2cbor package.json > package.cbor
$ bin/cbor2json package.cbor
$ bin/cbor2diag package.cbor

Example:

var cbor = require('cbor');
var assert = require('assert');

var encoded = cbor.encode(true); // returns <Buffer f5>
cbor.decodeFirst(encoded, function(error, obj) {
  // error != null if there was an error
  // obj is the unpacked object
  assert.ok(obj[0] === true);
});

// Use integers as keys?
var m = new Map();
m.set(1, 2);
encoded = cbor.encode(m); // <Buffer a1 01 02>

Allows streaming as well:

var cbor = require('cbor');
var fs = require('fs');

var d = new cbor.Decoder();
d.on('data', function(obj){
  console.log(obj);
});

var s = fs.createReadStream('foo');
s.pipe(d);

var d2 = new cbor.Decoder({input: '00', encoding: 'hex'});
d.on('data', function(obj){
  console.log(obj);
});
d2.start(); // needed when you don't use the stream interface

Developers

For the moment, you'll need to manually install istanbul, nodeunit, and grunt-cli:

$ npm install -g grunt-cli nodeunit istanbul
$ grunt
Running "coffee:compile" (coffee) task

Running "nodeunit:all" (nodeunit) task
Testing decoder.test.....OK
Testing diagnose.test...OK
Testing encoder.test.......OK
Testing evented.test....OK
Testing simple.test.OK
Testing tagged.test..OK
Testing utils.test.......OK
>> 459 assertions passed (129ms)

Done, without errors.

Build Status Coverage Status Dependency Status