### ipld

`0.26.3`
Need help reading this?

## Intro

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

You can then `require()` ipld as normal:

    const ipld = require('ipld')

## In the Browser

`ipld` should work in any ECMAScript 2018 environment out of the box.

Usage:

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

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

- https://unpkg.com/ipld/dist/index.min.js
- https://unpkg.com/ipld/dist/index.js

### addFormat

src/index.js

Add support for an IPLD Format.

addFormat(format: Object): this
Parameters
format `(Object)` The implementation of an IPLD Format.
Returns
`this`:

### removeFormat

src/index.js

Remove support for an IPLD Format.

removeFormat(codec: number): this
Parameters
codec `(number)` The codec of the IPLD Format to remove.
Returns
`this`:

### resolve

src/index.js

Retrieves IPLD Nodes along the `path` that is rooted at `cid`.

resolve(cid: CID, path: string, options: Object?): Iterable<Promise<{remainderPath: string, value}>>
Parameters
cid `(CID)` the CID the resolving starts.
path `(string)` the path that should be resolved.
options `(Object?)` Options is an object with the following properties.

Name | Description
--- | ---
options.signal `AbortSignal?` | A signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns
`Iterable<Promise<{remainderPath: string, value}>>`: Returns an async iterator of all the IPLD Nodes that were traversed during the path resolving. Every element is an object with these fields:

- `remainderPath`: the part of the path that wasn’t resolved yet.
- `value`: the value where the resolved path points to. If further traversing is possible, then the value is a CID object linking to another IPLD Node. If it was possible to fully resolve the path, value is the value the path points to. So if you need the CID of the IPLD Node you’re currently at, just take the value of the previously returned IPLD Node.

### get

src/index.js

Get a node by CID.

get(cid: CID, options: Object?): Promise<Object>
Parameters
cid `(CID)` The CID of the IPLD Node that should be retrieved.
options `(Object?)` Options is an object with the following properties.

Name | Description
--- | ---
options.signal `AbortSignal?` | A signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns
`Promise<Object>`: Returns a Promise with the IPLD Node that correspond to the given `cid` .

### getMany

src/index.js

Get multiple nodes back from an array of CIDs.

getMany(cids: Iterable<CID>, options: Object?): Iterable<Promise<Object>>
Parameters
cids `(Iterable<CID>)` The CIDs of the IPLD Nodes that should be retrieved.
options `(Object?)` Options is an object with the following properties.

Name | Description
--- | ---
options.signal `AbortSignal?` | A signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns
`Iterable<Promise<Object>>`: Returns an async iterator with the IPLD Nodes that correspond to the given `cids` .

### put

src/index.js

Stores the given IPLD Node of a recognized IPLD Format.

put(node: Object, format: number, userOptions: Object?): Promise<CID>
Parameters
node `(Object)` The deserialized IPLD node that should be inserted.
format `(number)` The multicodec of the format that IPLD Node should be encoded in.
userOptions `(Object?)` Options is an object with the following properties.

Name | Description
--- | ---
userOptions.cidVersion `number` (default `1`) | The CID version to use.
userOptions.onlyHash `boolean` (default `false`) | If true the serialized form of the IPLD Node will not be passed to the underlying block store.
userOptions.signal `AbortSignal?` | A signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns
`Promise<CID>`: Returns the CID of the serialized IPLD Nodes.

### putMany

src/index.js

Stores the given IPLD Nodes of a recognized IPLD Format.

putMany(nodes: Iterable<Object>, format: number, userOptions: Object?): Iterable<Promise<CID>>
Parameters
nodes `(Iterable<Object>)` Deserialized IPLD nodes that should be inserted.
format `(number)` The multicodec of the format that IPLD Node should be encoded in.
userOptions `(Object?)` Options are applied to any of the `nodes` and is an object with the following properties.

Name | Description
--- | ---
userOptions.cidVersion `number` (default `1`) | The CID version to use.
userOptions.onlyHash `boolean` (default `false`) | If true the serialized form of the IPLD Node will not be passed to the underlying block store.
userOptions.signal `AbortSignal?` | A signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns
`Iterable<Promise<CID>>`: Returns an async iterator with the CIDs of the serialized IPLD Nodes.

### remove

src/index.js

Remove an IPLD Node by the given CID.

remove(cid: CID, options: Object?): Promise<CID>
Parameters
cid `(CID)` The CID of the IPLD Node that should be removed.
options `(Object?)` Options is an object with the following properties.

Name | Description
--- | ---
options.signal `AbortSignal?` | A signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns
`Promise<CID>`: The CID of the removed IPLD Node.

### removeMany

src/index.js

Remove IPLD Nodes by the given CIDs.

Throws an error if any of the Blocks can’t be removed. This operation is not atomic, some Blocks might have already been removed.

removeMany(cids: Iterable<CID>, options: Object?): Iterable<Promise<CID>>
Parameters
cids `(Iterable<CID>)` The CIDs of the IPLD Nodes that should be removed.
options `(Object?)` Options is an object with the following properties.

Name | Description
--- | ---
options.signal `AbortSignal?` | A signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns
`Iterable<Promise<CID>>`: Returns an async iterator with the CIDs of the removed IPLD Nodes.

### tree

src/index.js

Returns all the paths that can be resolved into.

tree(cid: Object, offsetPath: string, userOptions: Object?): Iterable<Promise<String>>
Parameters
cid `(Object)` The ID to get the paths from
offsetPath `(string = `''`)` the path to start to retrieve the other paths from.
userOptions `(Object?)`

Name | Description
--- | ---
userOptions.recursive `number` (default `false`) | whether to get the paths recursively or not. `false` resolves only the paths of the given CID.
userOptions.signal `AbortSignal?` | A signal that can be used to abort any long-lived operations that are started as a result of this operation.

Returns
`Iterable<Promise<String>>`: Returns an async iterator with paths that can be resolved into

### defaultOptions

src/index.js

Default options for IPLD.

defaultOptions