Refs API

May 16, 2022 ยท View on GitHub

ipfs.refs(ipfsPath, [options])

Get links (references) from an object.

Parameters

NameTypeDescription
ipfsPathCID or StringThe object to search for references

Options

An optional object which may have the following keys:

NameTypeDefaultDescription
recursivebooleanfalseRecursively list references of child nodes
uniquebooleanfalseOmit duplicate references from output
formatString'<dst>'output edges with given format. Available tokens: <src>, <dst>, <linkname>
edgesbooleanfalseoutput references in edge format: "<src> -> <dst>"
maxDepthNumber1only for recursive refs, limits fetch and listing to the given depth
timeoutNumberundefinedA timeout in ms
signalAbortSignalundefinedCan be used to cancel any long running requests started as a result of this call

Returns

TypeDescription
AsyncIterable<Object>An async iterable that yields objects representing the links (references)

Each yielded object is of the form:

{
  ref: string,
  err: Error | null
}

Example

for await (const ref of ipfs.refs(ipfsPath, { recursive: true })) {
  if (ref.err) {
    console.error(ref.err)
  } else {
    console.log(ref.ref)
    // output: "QmHash"
  }
}

ipfs.refs.local([options])

Output all local references (CIDs of all blocks in the blockstore)

Blocks in the blockstore are stored by multihash and not CID so yielded CIDs are v1 CIDs with the 'raw' codec. These may not match the CID originally used to store a given block, though the multihash contained within the CID will.

Parameters

None

Options

An optional object which may have the following keys:

NameTypeDefaultDescription
timeoutNumberundefinedA timeout in ms
signalAbortSignalundefinedCan be used to cancel any long running requests started as a result of this call

Returns

TypeDescription
AsyncIterable<Object>An async iterable that yields objects representing the links (references)

Each yielded object is of the form:

{
  ref: string,
  err: Error | null
}

Example

for await (const ref of ipfs.refs.local()) {
  if (ref.err) {
    console.error(ref.err)
  } else {
    console.log(ref.ref)
    // output: "QmHash"
  }
}