Intro

Installable via npm install --save ipld-dag-cbor, it can also be used directly in the browser.

Download

The source is available for download from GitHub. Alternatively, you can install using npm:

$ npm install --save ipld-dag-cbor

You can then require() ipld-dag-cbor as normal:

const ipldDagCbor = require('ipld-dag-cbor')

In the Browser

Ipld-dag-cbor should work in any ES2015 environment out of the box.

Usage:

<script type="text/javascript" src="index.js"></script>

The portable versions of ipld-dag-cbor, including index.js and index.min.js, are included in the /dist folder. Ipld-dag-cbor can also be found on unpkg.com under

configureDecoder

src/util.js

Configure the underlying CBOR decoder.

configureDecoder(options: Object?)
Parameters
options (Object?) The options the decoder takes. The decoder will reset to the defaul values if no options are given.
Name Description
options.size number (default 65536) The current heap size used in CBOR parsing, this may grow automatically as larger blocks are encountered up to maxSize
options.maxSize number (default 67108864) The maximum size the CBOR parsing heap is allowed to grow to before dagCBOR.util.deserialize() returns an error
options.tags Object? An object whose keys are CBOR tag numbers and values are transform functions that accept a value and return a decoded representation of that value

serialize

src/util.js

Serialize internal representation into a binary CBOR block.

serialize(node: Object): Buffer
Parameters
node (Object) Internal representation of a CBOR block
Returns
Buffer: The encoded binary representation

deserialize

src/util.js

Deserialize CBOR block into the internal representation.

deserialize(data: Buffer): Object
Parameters
data (Buffer) Binary representation of a CBOR block
Returns
Object: An object that conforms to the IPLD Data Model

Calculate the CID of the binary blob.

cid(binaryBlob: Object, userOptions: Object?): Promise<CID>
Parameters
binaryBlob (Object) Encoded IPLD Node
userOptions (Object?) Options to create the CID
Name Description
userOptions.cidVersion number (default 1) CID version number
Returns
Promise<CID>:

Resolves a path within a CBOR block.

Returns the value or a link and the partial mising path. This way the IPLD Resolver can fetch the link and continue to resolve.

resolve(binaryBlob: Buffer, path: string): Object
Parameters
binaryBlob (Buffer) Binary representation of a CBOR block
path (string = '/') Path that should be resolved
Returns
Object: result - Result of the path it it was resolved successfully
Returns
any: result.value - Value the path resolves to
Returns
string: result.remainderPath - If the path resolves half-way to a link, then the remainderPath is the part after the link that can be used for further resolving

Return all available paths of a block.

tree(binaryBlob: Buffer)
Parameters
binaryBlob (Buffer) Binary representation of a CBOR block