1
+ import parallel from 'it-parallel'
2
+ import { pipe } from 'it-pipe'
3
+ import map from 'it-map'
1
4
import { decode , PBNode } from '@ipld/dag-pb'
2
5
import type { Blockstore } from 'interface-blockstore'
3
6
import type { ExporterOptions , Resolve , UnixfsV1DirectoryContent , UnixfsV1Resolver } from '../../../index.js'
@@ -22,22 +25,30 @@ const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path,
22
25
async function * listDirectory ( node : PBNode , path : string , resolve : Resolve , depth : number , blockstore : Blockstore , options : ExporterOptions ) : UnixfsV1DirectoryContent {
23
26
const links = node . Links
24
27
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
27
33
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 )
30
36
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 )
36
42
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
+ }
39
45
}
40
- }
46
+ } ) ,
47
+ source => parallel ( source , { ordered : true } )
48
+ )
49
+
50
+ for await ( const { entries } of results ) {
51
+ yield * entries
41
52
}
42
53
}
43
54
0 commit comments