How to use the ipfs-unixfs-exporter.recursive function in ipfs-unixfs-exporter

To help you get started, we’ve selected a few ipfs-unixfs-exporter examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ipfs / js-ipfs / src / core / components / get.js View on Github external
return async function * get (ipfsPath, options) {
    options = options || {}

    if (options.preload !== false) {
      let pathComponents

      try {
        pathComponents = normalizeCidPath(ipfsPath).split('/')
      } catch (err) {
        throw errCode(err, 'ERR_INVALID_PATH')
      }

      preload(pathComponents[0])
    }

    for await (const file of exporter.recursive(ipfsPath, ipld, options)) {
      yield mapFile(file, {
        ...options,
        includeContent: true
      })
    }
  }
}
github ipfs / js-ipfs / src / core / components / ls.js View on Github external
preload(pathComponents[0])
    }

    const file = await exporter(ipfsPath, ipld, options)

    if (!file.unixfs) {
      throw errCode(new Error('dag node was not a UnixFS node'), 'ERR_NOT_UNIXFS')
    }

    if (file.unixfs.type === 'file') {
      return mapFile(file, options)
    }

    if (file.unixfs.type.includes('dir')) {
      if (recursive) {
        for await (const child of exporter.recursive(file.cid, ipld, options)) {
          if (file.cid.toBaseEncodedString() === child.cid.toBaseEncodedString()) {
            continue
          }

          yield mapFile(child, options)
        }

        return
      }

      for await (let child of file.content()) {
        child = mapFile(child, options)
        child.depth--

        yield child
      }

ipfs-unixfs-exporter

JavaScript implementation of the UnixFs exporter used by IPFS

Apache-2.0 OR MIT
Latest version published 3 months ago

Package Health Score

78 / 100
Full package analysis

Popular ipfs-unixfs-exporter functions