Giter VIP home page Giter VIP logo

node-cbor's Introduction

cbor

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

Installation:

$ npm install cbor

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.decode(encoded, function(error, obj) {
  // error != null if there was an error
  // obj is the unpacked object
  assert.ok(obj[0] === true);
});

Allows streaming as well:

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

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

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

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

And also a SAX-type mode (which the streaming mode wraps):

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

var parser = new cbor.Evented();

parser.on('value',function(val,tags) {
  // An atomic item (not a map or array) was detected
  // `val`: the value
  // `tags`: an array of tags that preceded the list
  console.log(val);
});

// See the [docs](http://hildjj.github.io/node-cbor/doc/class/Evented.html) for a list of all of the events.

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

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 BufferStream.test...............OK
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

node-cbor's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.