Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jprochazk/cbor

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jprochazk/cbor

Partial implementation of RFC 7049 (CBOR)

  • 0.4.4
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

cbor

JavaScript implementation of the CBOR RFC 7049.

Build Status David GitHub

Usage

> npm install cbor@npm:jprochazk/cbor

The above command will install the library under the cbor alias.

The API is self-explanatory:

import CBOR from "cbor";

// Initialize some data
const json = {
    "key": "value",
    "another key": [
        1, 2, 3
    ],
    "number": 3.141592653589793
    "nulls are also encoded": null
};

const encoded = CBOR.encode(json); // ArrayBuffer
const decoded = CBOR.decode(encoded); // { ... }

// You can also encode into a pre-allocated buffer
const buffer = new ArrayBuffer(4096);
const encoded = CBOR.encodeInto(data, buffer);

Benchmarks

Speed was one of my main concerns when writing this library. Benchmark is available here.

BrowserCBOR.decodeCBOR.encodeCBOR.encodeInto
Chrome5225 ops/s8998 ops/s9268 ops/s
Firefox20454 ops/s22323 ops/s22900 ops/s

Results are on a i5-8600k intel processor. The JSON data used in the test is 2 KB decoded and 1.8 KB encoded. This means the library can decode at 13 MB/s and encode at 10 MB/s in Chrome, and around 2.5~4x as much in Firefox.

You can squeeze out a bit more performance if you use CBOR.encodeInto with a sufficiently large buffer. the CBOR.encode default is 1024 bytes, which should be enough for the vast majority of uses, but if you ever find yourself using more than that, utilize CBOR.encodeInto.

Notes

This library is meant for use in both Node & browsers. Minimum supported Node version is 11.

There are a few things from the specification which are currently unimplemented:

  • Byte strings
  • Tags, and the items they represent:
    • date/time, bignum/bigfloat as byte string, and others
  • 16-bit float (IEEE754 binary16)
  • Integers larger than 32 bit (BigInt)

If you need one or more of these features, submit an issue.

Keywords

FAQs

Package last updated on 11 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc