曲线
将所有的 JavaScript 对象同化到简明二进制对象表示 (CBOR) 数据格式中 (RFC7049 (法语)(中文(简体) ) 尽可能快。 。 。 .
关于
这个图书馆是超级棒的叉子 节点-cbor。它借用了许多界面,但会降低所有流和Aync处理,有利于最小的合成物并尽可能快.
安装
$ npm install --save borc
基准
开始
示例
const cbor = require('borc')
const assert = require('assert')
const encoded = cbor.encode(true) // returns <Buffer f5>
const decoded = cbor.decodeFirst(encoded)
// decoded is the unpacked object
assert.ok(decoded === true)
// Use integers as keys
var m = new Map()
m.set(1, 2)
encoded = cbor.encode(m) // <Buffer a1 01 02>
API 密码
见 https://dcountaryquire.github.io/borc 页面存档备份,存于互联网档案馆 详情
同步编码和解码导出为 a
leveldb 编码,作为
cbor.leveldb。 。 。 .
支持类型
下列类型支持编码:
- 布尔
- 数字(包括-0、NaN和±无限)
- 字符串
- 阵列, 设定( 编码为阵列)
- 对象( 包括无效), 映射
- 未定义
- 缓冲
- 日期,
- 正则Exp
- 尔曰. 網址
- 大数
解码支持上述类型,包括以下CBOR标签编号:
| 标记 | 生成类型 |
|---|---|
| 0 个 | 日期 |
| 1个 | 日期 |
| 2个 | 大数 |
| 3个 | 大数 |
| 页:1 | 大数 |
| 页:1 | 大数 |
| 第32条 | 尔曰. 網址 |
| 35个 | 正则Exp |
自定义
Borc支持自定义标记以及自定义输入类型.
编码自定义类型
class MyType {
constructor (val) {
this.val = val
}
// Gets called when encoding this object
// gen - instance of the encoder
// obj - the object being encoded
//
// should return true on success and false otherwise
encodeCBOR (gen) {
return gen.pushAny('mytype:' + this.val)
}
}
cbor.encode([new MyType('hello')])
编码自定义标记
cbor.encode([new cbor.Tagged(42, 'hello')])
解码自定义标记
const decoder = new cbor.Decoder({
tags: {
42: (val) => val + ' world'
}
})
许可证
麻省理工学院