Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
})
}
}
}
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
}