-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathdirectory.js
34 lines (28 loc) · 975 Bytes
/
directory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
'use strict'
/**
* @typedef {import('../../../types').ExporterOptions} ExporterOptions
* @typedef {import('../../../types').UnixfsV1DirectoryContent} UnixfsV1DirectoryContent
* @typedef {import('../../../types').UnixfsV1Resolver} UnixfsV1Resolver
*/
/**
* @type {UnixfsV1Resolver}
*/
const directoryContent = (cid, node, unixfs, path, resolve, depth, blockstore) => {
/**
* @param {ExporterOptions} [options]
* @returns {UnixfsV1DirectoryContent}
*/
async function * yieldDirectoryContent (options = {}) {
const offset = options.offset || 0
const length = options.length || node.Links.length
const links = node.Links.slice(offset, length)
for (const link of links) {
const result = await resolve(link.Hash, link.Name || '', `${path}/${link.Name || ''}`, [], depth + 1, blockstore, options)
if (result.entry) {
yield result.entry
}
}
}
return yieldDirectoryContent
}
module.exports = directoryContent