Skip to content

Commit 287965a

Browse files
author
Alan Shaw
committed
fix: use fanout
1 parent 4721879 commit 287965a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { UnixFS } from 'ipfs-unixfs'
2+
import errCode from 'err-code'
13
import { decode, type PBNode } from '@ipld/dag-pb'
24
import map from 'it-map'
35
import parallel from 'it-parallel'
@@ -20,11 +22,28 @@ const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path,
2022
async function * listDirectory (node: PBNode, path: string, resolve: Resolve, depth: number, blockstore: ReadableStorage, options: ExporterOptions): UnixfsV1DirectoryContent {
2123
const links = node.Links
2224

25+
if (node.Data == null) {
26+
throw errCode(new Error('no data in PBNode'), 'ERR_NOT_UNIXFS')
27+
}
28+
29+
let dir: UnixFS
30+
try {
31+
dir = UnixFS.unmarshal(node.Data)
32+
} catch (err: any) {
33+
throw errCode(err, 'ERR_NOT_UNIXFS')
34+
}
35+
36+
if (!dir.fanout) {
37+
throw errCode(new Error('missing fanout'), 'ERR_NOT_UNIXFS')
38+
}
39+
40+
const padLength = (dir.fanout - 1n).toString(16).length
41+
2342
const results = pipe(
2443
links,
2544
source => map(source, link => {
2645
return async () => {
27-
const name = link.Name != null ? link.Name.substring(2) : null
46+
const name = link.Name != null ? link.Name.substring(padLength) : null
2847

2948
if (name != null && name !== '') {
3049
const result = await resolve(link.Hash, name, `${path}/${name}`, [], depth + 1, blockstore, options)

packages/ipfs-unixfs/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class UnixFS {
5252
secs: message.mtime.Seconds ?? 0n,
5353
nsecs: message.mtime.FractionalNanoseconds
5454
}
55-
: undefined
55+
: undefined,
56+
fanout: message.fanout
5657
})
5758

5859
// make sure we honour the original mode

0 commit comments

Comments
 (0)