Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
chore: dedupe load
  • Loading branch information
achingbrain committed Jul 30, 2025
commit b0e61ed9524c6188ab3632d5065ebf5cb2b14587
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,23 @@ const directoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, de
const linkName = link.Name ?? ''
const linkPath = `${path}/${linkName}`

const load = async (options = {}) => {
const result = await resolve(link.Hash, linkName, linkPath, [], depth + 1, blockstore, options)
return result.entry
}

if (isBasicExporterOptions(options)) {
const basic: UnixfsV1BasicContent = {
cid: link.Hash,
name: linkName,
path: linkPath,
resolve: async (options = {}) => {
const result = await resolve(link.Hash, linkName, linkPath, [], depth + 1, blockstore, options)
return result.entry
}
resolve: load
}

return basic
}

const result = await resolve(link.Hash, linkName, linkPath, [], depth + 1, blockstore, options)
return result.entry
return load(options)
}
}),
source => parallel(source, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { pipe } from 'it-pipe'
import { CustomProgressEvent } from 'progress-events'
import { NotUnixFSError } from '../../../errors.js'
import { isBasicExporterOptions } from '../../../utils/is-basic-exporter-options.ts'
import type { ExporterOptions, Resolve, UnixfsV1DirectoryContent, UnixfsV1Resolver, ReadableStorage, ExportWalk, BasicExporterOptions, UnixfsV1BasicContent } from '../../../index.js'
import type { ExporterOptions, Resolve, UnixfsV1DirectoryContent, UnixfsV1Resolver, ReadableStorage, ExportWalk, BasicExporterOptions } from '../../../index.js'
import type { PBNode } from '@ipld/dag-pb'

const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth, blockstore) => {
Expand Down Expand Up @@ -49,24 +49,27 @@ async function * listDirectory (node: PBNode, path: string, resolve: Resolve, de

if (name != null && name !== '') {
const linkPath = `${path}/${name}`
const load = async (options = {}) => {
const result = await resolve(link.Hash, name, linkPath, [], depth + 1, blockstore, options)
return result.entry
}

if (isBasicExporterOptions(options)) {
const basic: UnixfsV1BasicContent = {
cid: link.Hash,
name,
path: linkPath,
resolve: async (options = {}) => {
const result = await resolve(link.Hash, name, linkPath, [], depth + 1, blockstore, options)
return result.entry
}
return {
entries: [{
cid: link.Hash,
name,
path: linkPath,
resolve: load
}]
}

return { entries: [basic] }
}

const result = await resolve(link.Hash, name, linkPath, [], depth + 1, blockstore, options)

return { entries: result.entry == null ? [] : [result.entry] }
return {
entries: [
await load()
].filter(Boolean)
}
} else {
// descend into subshard
const block = await blockstore.get(link.Hash, options)
Expand All @@ -76,7 +79,9 @@ async function * listDirectory (node: PBNode, path: string, resolve: Resolve, de
cid: link.Hash
}))

return { entries: listDirectory(node, path, resolve, depth, blockstore, options) }
return {
entries: listDirectory(node, path, resolve, depth, blockstore, options)
}
}
}
}),
Expand Down
Loading