1+ import parallel from 'it-parallel'
2+ import { pipe } from 'it-pipe'
3+ import map from 'it-map'
14import { decode , PBNode } from '@ipld/dag-pb'
25import type { Blockstore } from 'interface-blockstore'
36import type { ExporterOptions , Resolve , UnixfsV1DirectoryContent , UnixfsV1Resolver } from '../../../index.js'
@@ -22,22 +25,30 @@ const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path,
2225async function * listDirectory ( node : PBNode , path : string , resolve : Resolve , depth : number , blockstore : Blockstore , options : ExporterOptions ) : UnixfsV1DirectoryContent {
2326 const links = node . Links
2427
25- for ( const link of links ) {
26- const name = link . Name != null ? link . Name . substring ( 2 ) : null
28+ const results = pipe (
29+ links ,
30+ source => map ( source , link => {
31+ return async ( ) => {
32+ const name = link . Name != null ? link . Name . substring ( 2 ) : null
2733
28- if ( name != null && name !== '' ) {
29- const result = await resolve ( link . Hash , name , `${ path } /${ name } ` , [ ] , depth + 1 , blockstore , options )
34+ if ( name != null && name !== '' ) {
35+ const result = await resolve ( link . Hash , name , `${ path } /${ name } ` , [ ] , depth + 1 , blockstore , options )
3036
31- yield result . entry
32- } else {
33- // descend into subshard
34- const block = await blockstore . get ( link . Hash )
35- node = decode ( block )
37+ return { entries : result . entry == null ? [ ] : [ result . entry ] }
38+ } else {
39+ // descend into subshard
40+ const block = await blockstore . get ( link . Hash )
41+ node = decode ( block )
3642
37- for await ( const file of listDirectory ( node , path , resolve , depth , blockstore , options ) ) {
38- yield file
43+ return { entries : listDirectory ( node , path , resolve , depth , blockstore , options ) }
44+ }
3945 }
40- }
46+ } ) ,
47+ source => parallel ( source , { ordered : true } )
48+ )
49+
50+ for await ( const { entries } of results ) {
51+ yield * entries
4152 }
4253}
4354
0 commit comments