Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Latest commit

 

History

History
96 lines (73 loc) · 2.54 KB

REFS.md

File metadata and controls

96 lines (73 loc) · 2.54 KB

Refs API

refs

Get links (references) from an object.

ipfs.refs(ipfsPath, [options])

ipfsPath can be of type:

  • cid of type:
    • a CID instance
    • Buffer, the raw Buffer of the cid
    • String, the base58 encoded version of the cid
  • String, including the ipfs handler, a cid and a path to traverse to, ie:
    • '/ipfs/QmXEmhrMpbVvTh61FNAxP9nU7ygVtyvZA8HZDUaqQCAb66'
    • '/ipfs/QmXEmhrMpbVvTh61FNAxP9nU7ygVtyvZA8HZDUaqQCAb66/a.txt'
    • 'QmXEmhrMpbVvTh61FNAxP9nU7ygVtyvZA8HZDUaqQCAb66/a.txt'

options is an optional object that may contain the following keys:

  • recursive (false): recursively list references of child nodes
  • unique (false): omit duplicate references from output
  • format ("<dst>"): output edges with given format. Available tokens: <src>, <dst>, <linkname>
  • edges (false): output references in edge format: "<src> -> <dst>"
  • maxDepth (1): only for recursive refs, limits fetch and listing to the given depth
  • timeout (number|string): Throw an error if the request does not complete within the specified milliseconds timeout. If timeout is a string, the value is parsed as a human readable duration. There is no timeout by default.

Returns

Type Description
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"
  }
}

refs.local

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

ipfs.refs.local()

Returns

Type Description
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"
  }
}