Skip to content

Repository files navigation

This is an up-to-date fork of the paroga/cbor-js by Patrick Gansterer. In early 2020, we were searching for a Javascript CBOR library, and found the excellent paroga/cbor-js, which sadly had not been updated for several years. Because we really needed a CBOR library in our projects, we decided to fork the repository and bring it up-to-date.

Goals of this fork:

  • Merge all open pull requests of the original paroga/cbor-js (DONE)
  • Resolve open issues of the original paroga/cbor-js (PARTLY DONE)
  • Optimize for speed (TBD)
  • Add more tests and benchamrking (TBD)
  • Add support for tagging (TBD)
  • Publish on npm (TBD)

cbor-js

The Concise Binary Object Representation (CBOR) data format (RFC 7049) implemented in pure JavaScript.

Build StatusCoverage StatusDependency statusDev Dependency StatusSelenium Test Status

Selenium Test Status

API

The CBOR-object provides the following two functions:

CBOR.decode(data)

Take the ArrayBuffer object data and return it decoded as a JavaScript object.

CBOR.encode(data)

Take the JavaScript object data and return it encoded as a ArrayBuffer object.

Usage

Include cbor.js in your or HTML page:

<scriptsrc="path/to/cbor.js" type="text/javascript"></script>

Then you can use it via the CBOR-object in your code:

varinitial={Hello: "World"};varencoded=CBOR.encode(initial);vardecoded=CBOR.decode(encoded);

After running this example initial and decoded represent the same value.

Combination with WebSocket

The API was designed to play well with the WebSocket object in the browser:

varwebsocket=newWebSocket(url);websocket.binaryType="arraybuffer";
...
websocket.onmessage=function(event){varmessage=CBOR.decode(event.data);};
...
websocket.send(CBOR.encode(message));

About

An up-to-date (2020) fork of paroga/cbor-js that merges the open pull requests of the original and aims to resolve remaining open issues. Concise Binary Object Representation (CBOR) data format (RFC7049) implemented in pure JavaScript.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages