0.9.8 • Published 3 years ago
cbor-codec v0.9.8
CBOR Codec
CBOR Codec for NodeJS and the Web.
Demo
Use
from NodejS,
import {cbor_encode, cbor_decode} from "cbor-codec"
const demo_data = {
demo_cbor_support: new Date('2018-11-16T12:23:57-0700'),
some_numbers: new Float32Array([
Math.PI, Math.SQRT2, Math.SQRT1_2,
Math.LN10, Math.LN2, Math.E, Math.LOG10E, Math.LOG2E ])}
let demo_u8 = cbor_encode(demo_data)
console.log(demo_u8)
console.log(cbor_decode(demo_data_u8))
or direclty from HTML,
<script type='module'>
import {cbor_encode, cbor_decode} from "//cdn.jsdelivr.net/npm/cbor-codec/esm/index.mjs"
const demo_data = {
demo_cbor_support: new Date('2018-11-16T12:23:57-0700'),
some_numbers: new Float32Array([
Math.PI, Math.SQRT2, Math.SQRT1_2,
Math.LN10, Math.LN2, Math.E, Math.LOG10E, Math.LOG2E ])}
let demo_u8 = cbor_encode(demo_data)
console.log(demo_u8)
console.log(cbor_decode(demo_data_u8))
</script>
Docs
See the API docs.
Overview
From NodeJS,
npm install cbor-codec
or in HTML,
<script type='module'>
import {cbor_encode, cbor_decode} from "//cdn.jsdelivr.net/npm/cbor-codec/esm/index.mjs"
import {cbor_encode} from "//cdn.jsdelivr.net/npm/cbor-codec/esm/encode.mjs"
import {cbor_decode} from "//cdn.jsdelivr.net/npm/cbor-codec/esm/decode.mjs"
// minified
import {cbor_encode, cbor_decode} from "//cdn.jsdelivr.net/npm/cbor-codec/esm/index.min.mjs"
import {cbor_encode} from "//cdn.jsdelivr.net/npm/cbor-codec/esm/encode.min.mjs"
import {cbor_decode} from "//cdn.jsdelivr.net/npm/cbor-codec/esm/decode.min.mjs"
</script>
Decoding CBOR
let demo_data_u8 = hex_to_u8(
'a27164656d6f5f63626f725f737570706f7274c1fb' +
'41d6fbc6534000006c736f6d655f6e756d62657273' +
'd8555820db0f4940f304b53ff304353f8e5d134018' +
'72313f54f82d40d95bde3e3baab83f')
console.log(cbor_decode(demo_data_u8))
See the API docs for async streaming and custom CBOR tag decodings.
Encoding CBOR
const demo_data = {
demo_cbor_support: new Date('2018-11-16T12:23:57-0700'),
some_numbers:
new Float32Array([
Math.PI, Math.SQRT2, Math.SQRT1_2,
Math.LN10, Math.LN2, Math.E, Math.LOG10E, Math.LOG2E ]),
}
let demo_u8 = cbor_encode(demo_data)
console.log('cbor_encoded[u8]:', demo_u8)
console.log('cbor_encoded[hex]:', u8_to_hex(demo_u8))
See the API docs for output streaming and custom CBOR tag encodings.
LevelDB / LevelDown CBOR Codec
Use CBOR for LevelDB/LevelDown codec.
Unit tests
Mocha-based unittests:
License
0.9.8
3 years ago
0.9.7
3 years ago
0.9.4
4 years ago
0.9.3
4 years ago
0.9.6
3 years ago
0.9.5
4 years ago
0.9.2
4 years ago
0.9.1
4 years ago
0.9.0
4 years ago
0.8.0
4 years ago
0.7.0
5 years ago
0.2.4
5 years ago
0.2.3
5 years ago
0.2.2
5 years ago
0.2.1
5 years ago
0.2.0
5 years ago
0.1.2
5 years ago
0.1.0
6 years ago
0.1.1
6 years ago
0.0.10
7 years ago
0.0.9
7 years ago
0.0.5
7 years ago
0.0.4
7 years ago
0.0.2
7 years ago
0.0.1
7 years ago