Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { decode, type PBNode } from '@ipld/dag-pb'
import errCode from 'err-code'
import { UnixFS } from 'ipfs-unixfs'
import map from 'it-map'
import parallel from 'it-parallel'
import { pipe } from 'it-pipe'
Expand All @@ -20,11 +22,28 @@ const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path,
async function * listDirectory (node: PBNode, path: string, resolve: Resolve, depth: number, blockstore: ReadableStorage, options: ExporterOptions): UnixfsV1DirectoryContent {
const links = node.Links

if (node.Data == null) {
throw errCode(new Error('no data in PBNode'), 'ERR_NOT_UNIXFS')
}

let dir: UnixFS
try {
dir = UnixFS.unmarshal(node.Data)
} catch (err: any) {
throw errCode(err, 'ERR_NOT_UNIXFS')
}

if (!dir.fanout) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix the linting error:

Suggested change
if (!dir.fanout) {
if (dir.fanout == null) {

throw errCode(new Error('missing fanout'), 'ERR_NOT_UNIXFS')
}

const padLength = (dir.fanout - 1n).toString(16).length

const results = pipe(
links,
source => map(source, link => {
return async () => {
const name = link.Name != null ? link.Name.substring(2) : null
const name = link.Name != null ? link.Name.substring(padLength) : null

if (name != null && name !== '') {
const result = await resolve(link.Hash, name, `${path}/${name}`, [], depth + 1, blockstore, options)
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-unixfs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class UnixFS {
secs: message.mtime.Seconds ?? 0n,
nsecs: message.mtime.FractionalNanoseconds
}
: undefined
: undefined,
fanout: message.fanout
})

// make sure we honour the original mode
Expand Down