ipld-dag-pb
0.17.4

Intro

Installable via npm install --save ipld-dag-pb, 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-pb

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

const ipldDagPb = require('ipld-dag-pb')

In the Browser

Ipld-dag-pb 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-pb, including index.js and index.min.js, are included in the /dist folder. Ipld-dag-pb can also be found on unpkg.com under

addNamedLink

Adds a link with its name as property to an object.

The link won't be added if its name is empty or matches one of the existing properties.

Parameters

  1. object: Object:  
    The object that contains an array of links
  2. name: string:  
    The name of the link to add
  3. position: numner:  
    The position within the array of links

addEnumerableGetters

Make certain getters enumnerable

This can be used to add additional getters that are enumerable and hence show up on an Object.keys() call.

Parameters

  1. object: Object:  
    The object it should be applied to
  2. fields: Array<String>:  
    The fields that should be made enumnerable

hidePrivateFields

Makes all properties with a leading underscore non-enumerable.

Parameters

  1. object: Object:  
    The object it should be applied to

resolve

Resolves a path within a PB 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.

Parameters

  1. binaryBlob: Buffer:  
    Binary representation of a PB block
  2. path: string (='/'):  
    Path that should be resolved

Returns

Object result - Result of the path it it was resolved successfully
any result.value - Value the path resolves to
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

tree

Return all available paths of a block.

Parameters

  1. binaryBlob: Buffer:  
    Binary representation of a PB block

cid

Calculate the CID of the binary blob.

Parameters

  1. binaryBlob: Object:  
    Encoded IPLD Node
  2. userOptions: Object?:  
    Options to create the CID
  3. userOptions.cidVersion: number (=1):  
    CID version number

Returns

Promise<CID>

serialize

Serialize internal representation into a binary PB block.

Parameters

  1. node: Object:  
    Internal representation of a CBOR block

Returns

Buffer The encoded binary representation

deserialize

Deserialize PB block into the internal representation.

Parameters

  1. buffer: Buffer:  
    Binary representation of a PB block

Returns

Object An object that conforms to the IPLD Data Model