JSPM

  • Created
  • Published
  • Downloads 1155534
  • Score
    100M100P100Q200169F
  • License MIT

NPM package for encoding and decoding CBOR (Concise Binary Object Representation) data.

Package Exports

  • cbor

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 Build Status

NPM package for encoding and decoding CBOR (Concise Binary Object Representation) data. This package implements CBOR as described in RFC 7049.

Not ready for production

Installation

If you have npm installed, you can simply type:

  npm install cbor

Or you can clone this repository using the git command:

  git clone git://github.com/dotCypress/cbor.git

Usage

Some examples how to use cbor module.

Encode

cbor.encode(value, writableStream, callback);

Arguments:

Semantic encode

cbor.encodeSemantic(tag, value, writableStream, callback);

Arguments:

Samples

  var cbor = require("cbor");
  
  var writableStream = ...; 
  var cb = ...;             

  // simple encoding
  cbor.encode(1, writableStream, cb);                     // integers
  cbor.encode(-50, writableStream, cb);                   // integers
  cbor.encode(1.1, writableStream, cb);                   // floats
  cbor.encode([123, 567, 'hello'], writableStream, cb);   // arrays
  cbor.encode({'a': 1, 'b': 2}, writableStream, cb);      // hashes
  cbor.encode(new Buffer([1,2,3,4]), writableStream, cb); // binary data
  
  // semantic encode
  cbor.encodeSemantic(0, "2013-03-21T20:04:00Z", writableStream, cb);

Known issues

  • All floats will be serialized only as IEEE 754 Double-Precision Float (64 bits follow)
  • Encode does't support indefinite-length values.

License

MIT