From f1596d87b3ea9ebf556ee6495fcaeab75158b28d Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 29 Jul 2025 13:57:51 +0200 Subject: [PATCH 1/4] feat: add 'extended' option to exporter To list directories without resolving the root node of each directory entry, add an `extended` option to the exporter. Defaults to `true` to preserve backwards compatibility. --- packages/ipfs-unixfs-exporter/src/index.ts | 52 ++++++++++++++++++- .../resolvers/unixfs-v1/content/directory.ts | 20 ++++++- .../content/hamt-sharded-directory.ts | 25 +++++++-- .../src/utils/is-basic-exporter-options.ts | 5 ++ .../test/exporter-sharded.spec.ts | 52 +++++++++++++++++++ .../test/exporter.spec.ts | 50 ++++++++++++++++++ 6 files changed, 196 insertions(+), 8 deletions(-) create mode 100644 packages/ipfs-unixfs-exporter/src/utils/is-basic-exporter-options.ts diff --git a/packages/ipfs-unixfs-exporter/src/index.ts b/packages/ipfs-unixfs-exporter/src/index.ts index e8b06f59..4a3c7b99 100644 --- a/packages/ipfs-unixfs-exporter/src/index.ts +++ b/packages/ipfs-unixfs-exporter/src/index.ts @@ -58,6 +58,7 @@ import type { Bucket } from 'hamt-sharding' import type { Blockstore } from 'interface-blockstore' import type { UnixFS } from 'ipfs-unixfs' import type { ProgressOptions, ProgressEvent } from 'progress-events' +import type { AbortOptions } from 'it-pushable' export * from './errors.js' @@ -136,6 +137,21 @@ export interface ExporterOptions extends ProgressOptions blockReadConcurrency?: number } +export interface BasicExporterOptions extends ExporterOptions { + /** + * When directory contents are listed, by default the root node of each entry + * is fetched to decode the UnixFS metadata and know if the entry is a file or + * a directory. This can result in fetching extra data which may not be + * desirable, depending on your application. + * + * Pass false here to only return the CID and the name of the entry and not + * any extended metadata. + * + * @default true + */ + extended: false +} + export interface Exportable { /** * A disambiguator to allow TypeScript to work out the type of the entry. @@ -218,7 +234,7 @@ export interface Exportable { * // `entries` contains the first 5 files/directories in the directory * ``` */ - content(options?: ExporterOptions): AsyncGenerator + content(options?: ExporterOptions | BasicExporterOptions): AsyncGenerator } /** @@ -316,7 +332,39 @@ export interface Resolver { (cid: CID, name: string, path: string, toResolve: st export type UnixfsV1FileContent = AsyncIterable | Iterable export type UnixfsV1DirectoryContent = AsyncIterable | Iterable export type UnixfsV1Content = UnixfsV1FileContent | UnixfsV1DirectoryContent -export interface UnixfsV1Resolver { (cid: CID, node: PBNode, unixfs: UnixFS, path: string, resolve: Resolve, depth: number, blockstore: ReadableStorage): (options: ExporterOptions) => UnixfsV1Content } + +export interface UnixfsV1BasicContent { + /** + * The name of the entry + */ + name: string + + /** + * The path of the entry within the DAG in which it was encountered + */ + path: string + + /** + * The CID of the entry + */ + cid: CID + + /** + * Resolve the root node of the entry to parse the UnixFS metadata contained + * there. The metadata will contain what kind of node it is (e.g. file, + * directory, etc), the file size, and more. + */ + resolve: (options?: AbortOptions) => Promise +} + +export interface UnixFsV1ContentResolver { + (options: ExporterOptions): UnixfsV1Content + (options: BasicExporterOptions): UnixfsV1BasicContent +} + +export interface UnixfsV1Resolver { + (cid: CID, node: PBNode, unixfs: UnixFS, path: string, resolve: Resolve, depth: number, blockstore: ReadableStorage): (options: ExporterOptions) => UnixfsV1Content +} export interface ShardTraversalContext { hamtDepth: number diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts index afab2634..6794a452 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts @@ -3,10 +3,11 @@ import map from 'it-map' import parallel from 'it-parallel' import { pipe } from 'it-pipe' import { CustomProgressEvent } from 'progress-events' -import type { ExporterOptions, ExportWalk, UnixfsV1DirectoryContent, UnixfsV1Resolver } from '../../../index.js' +import type { BasicExporterOptions, ExporterOptions, ExportWalk, UnixfsV1BasicContent, UnixfsV1DirectoryContent, UnixfsV1Resolver } from '../../../index.js' +import { isBasicExporterOptions } from '../../../utils/is-basic-exporter-options.ts' const directoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth, blockstore) => { - async function * yieldDirectoryContent (options: ExporterOptions = {}): UnixfsV1DirectoryContent { + async function * yieldDirectoryContent (options: ExporterOptions | BasicExporterOptions = {}): any { const offset = options.offset ?? 0 const length = options.length ?? node.Links.length const links = node.Links.slice(offset, length) @@ -21,6 +22,21 @@ const directoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, de return async () => { const linkName = link.Name ?? '' const linkPath = `${path}/${linkName}` + + 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 + } + } + + return basic + } + const result = await resolve(link.Hash, linkName, linkPath, [], depth + 1, blockstore, options) return result.entry } diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts index b08255a2..44d11acb 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts @@ -5,11 +5,12 @@ import parallel from 'it-parallel' import { pipe } from 'it-pipe' import { CustomProgressEvent } from 'progress-events' import { NotUnixFSError } from '../../../errors.js' -import type { ExporterOptions, Resolve, UnixfsV1DirectoryContent, UnixfsV1Resolver, ReadableStorage, ExportWalk } from '../../../index.js' +import type { ExporterOptions, Resolve, UnixfsV1DirectoryContent, UnixfsV1Resolver, ReadableStorage, ExportWalk, BasicExporterOptions, UnixfsV1BasicContent } from '../../../index.js' import type { PBNode } from '@ipld/dag-pb' +import { isBasicExporterOptions } from '../../../utils/is-basic-exporter-options.ts' const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth, blockstore) => { - function yieldHamtDirectoryContent (options: ExporterOptions = {}): UnixfsV1DirectoryContent { + function yieldHamtDirectoryContent (options: ExporterOptions | BasicExporterOptions = {}): UnixfsV1DirectoryContent { options.onProgress?.(new CustomProgressEvent('unixfs:exporter:walk:hamt-sharded-directory', { cid })) @@ -20,7 +21,7 @@ const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, return yieldHamtDirectoryContent } -async function * listDirectory (node: PBNode, path: string, resolve: Resolve, depth: number, blockstore: ReadableStorage, options: ExporterOptions): UnixfsV1DirectoryContent { +async function * listDirectory (node: PBNode, path: string, resolve: Resolve, depth: number, blockstore: ReadableStorage, options: ExporterOptions | BasicExporterOptions): any { const links = node.Links if (node.Data == null) { @@ -47,7 +48,23 @@ async function * listDirectory (node: PBNode, path: string, resolve: Resolve, de 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) + const linkPath = `${path}/${name}` + + if (isBasicExporterOptions(options)) { + const basic: UnixfsV1BasicContent = { + cid: link.Hash, + name: name, + path: linkPath, + resolve: async (options = {}) => { + const result = await resolve(link.Hash, name, linkPath, [], depth + 1, blockstore, options) + return result.entry + } + } + + return { entries: [basic] } + } + + const result = await resolve(link.Hash, name, linkPath, [], depth + 1, blockstore, options) return { entries: result.entry == null ? [] : [result.entry] } } else { diff --git a/packages/ipfs-unixfs-exporter/src/utils/is-basic-exporter-options.ts b/packages/ipfs-unixfs-exporter/src/utils/is-basic-exporter-options.ts new file mode 100644 index 00000000..95190ea5 --- /dev/null +++ b/packages/ipfs-unixfs-exporter/src/utils/is-basic-exporter-options.ts @@ -0,0 +1,5 @@ +import type { BasicExporterOptions } from '../index.js' + +export function isBasicExporterOptions (obj?: any): obj is BasicExporterOptions { + return obj?.extended === false +} diff --git a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.ts b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.ts index dd2354c5..7d7026d8 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.ts +++ b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.ts @@ -363,4 +363,56 @@ describe('exporter sharded', function () { content: file?.node }]).to.deep.equal(files) }) + + it('exports basic sharded directory', async () => { + const files: Record = {} + + // needs to result in a block that is larger than SHARD_SPLIT_THRESHOLD bytes + for (let i = 0; i < 100; i++) { + files[`file-${Math.random()}.txt`] = { + content: uint8ArrayConcat(await all(randomBytes(100))) + } + } + + const imported = await all(importer(Object.keys(files).map(path => ({ + path, + content: asAsyncIterable(files[path].content) + })), block, { + wrapWithDirectory: true, + shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD, + rawLeaves: false + })) + + const dirCid = imported.pop()?.cid + + if (dirCid == null) { + throw new Error('No directory CID found') + } + + const exported = await exporter(dirCid, block) + const dirFiles = await all(exported.content()) + + // delete shard contents + for await (const entry of dirFiles) { + block.delete(entry.cid) + } + + // list the contents again, this time just the basic version + const basicDirFiles = await all(exported.content({ + extended: false + })) + expect(basicDirFiles.length).to.equal(dirFiles.length) + + for (let i = 0; i < basicDirFiles.length; i++) { + const dirFile = basicDirFiles[i] + + expect(dirFile).to.have.property('name') + expect(dirFile).to.have.property('path') + expect(dirFile).to.have.property('cid') + expect(dirFile).to.have.property('resolve') + + // should fail because we have deleted this block + await expect(dirFile.resolve()).to.eventually.be.rejected() + } + }) }) diff --git a/packages/ipfs-unixfs-exporter/test/exporter.spec.ts b/packages/ipfs-unixfs-exporter/test/exporter.spec.ts index 67326ec4..f6f7dc2f 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter.spec.ts +++ b/packages/ipfs-unixfs-exporter/test/exporter.spec.ts @@ -1605,4 +1605,54 @@ describe('exporter', () => { expect(actualInvocations).to.deep.equal(expectedInvocations) }) + + it('exports basic directory', async () => { + const files: Record = {} + + for (let i = 0; i < 10; i++) { + files[`file-${Math.random()}.txt`] = { + content: uint8ArrayConcat(await all(randomBytes(100))) + } + } + + const imported = await all(importer(Object.keys(files).map(path => ({ + path, + content: asAsyncIterable(files[path].content) + })), block, { + wrapWithDirectory: true, + rawLeaves: false + })) + + const dirCid = imported.pop()?.cid + + if (dirCid == null) { + throw new Error('No directory CID found') + } + + const exported = await exporter(dirCid, block) + const dirFiles = await all(exported.content()) + + // delete shard contents + for await (const entry of dirFiles) { + block.delete(entry.cid) + } + + // list the contents again, this time just the basic version + const basicDirFiles = await all(exported.content({ + extended: false + })) + expect(basicDirFiles.length).to.equal(dirFiles.length) + + for (let i = 0; i < basicDirFiles.length; i++) { + const dirFile = basicDirFiles[i] + + expect(dirFile).to.have.property('name') + expect(dirFile).to.have.property('path') + expect(dirFile).to.have.property('cid') + expect(dirFile).to.have.property('resolve') + + // should fail because we have deleted this block + await expect(dirFile.resolve()).to.eventually.be.rejected() + } + }) }) From 4e5937263b73867b0949ddf52f37a3dfceeda784 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 29 Jul 2025 15:12:13 +0200 Subject: [PATCH 2/4] chore: linting --- packages/ipfs-unixfs-exporter/src/index.ts | 4 ++-- .../src/resolvers/unixfs-v1/content/directory.ts | 2 +- .../src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts | 4 ++-- packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.ts | 4 ++-- packages/ipfs-unixfs-exporter/test/exporter.spec.ts | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/src/index.ts b/packages/ipfs-unixfs-exporter/src/index.ts index 4a3c7b99..ee6c2e9e 100644 --- a/packages/ipfs-unixfs-exporter/src/index.ts +++ b/packages/ipfs-unixfs-exporter/src/index.ts @@ -57,8 +57,8 @@ import type { PBNode } from '@ipld/dag-pb' import type { Bucket } from 'hamt-sharding' import type { Blockstore } from 'interface-blockstore' import type { UnixFS } from 'ipfs-unixfs' -import type { ProgressOptions, ProgressEvent } from 'progress-events' import type { AbortOptions } from 'it-pushable' +import type { ProgressOptions, ProgressEvent } from 'progress-events' export * from './errors.js' @@ -354,7 +354,7 @@ export interface UnixfsV1BasicContent { * there. The metadata will contain what kind of node it is (e.g. file, * directory, etc), the file size, and more. */ - resolve: (options?: AbortOptions) => Promise + resolve(options?: AbortOptions): Promise } export interface UnixFsV1ContentResolver { diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts index 6794a452..03313f4c 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts @@ -3,8 +3,8 @@ import map from 'it-map' import parallel from 'it-parallel' import { pipe } from 'it-pipe' import { CustomProgressEvent } from 'progress-events' -import type { BasicExporterOptions, ExporterOptions, ExportWalk, UnixfsV1BasicContent, UnixfsV1DirectoryContent, UnixfsV1Resolver } from '../../../index.js' import { isBasicExporterOptions } from '../../../utils/is-basic-exporter-options.ts' +import type { BasicExporterOptions, ExporterOptions, ExportWalk, UnixfsV1BasicContent, UnixfsV1Resolver } from '../../../index.js' const directoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth, blockstore) => { async function * yieldDirectoryContent (options: ExporterOptions | BasicExporterOptions = {}): any { diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts index 44d11acb..0dcbb0cd 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts @@ -5,9 +5,9 @@ import parallel from 'it-parallel' 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 { PBNode } from '@ipld/dag-pb' -import { isBasicExporterOptions } from '../../../utils/is-basic-exporter-options.ts' const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth, blockstore) => { function yieldHamtDirectoryContent (options: ExporterOptions | BasicExporterOptions = {}): UnixfsV1DirectoryContent { @@ -53,7 +53,7 @@ async function * listDirectory (node: PBNode, path: string, resolve: Resolve, de if (isBasicExporterOptions(options)) { const basic: UnixfsV1BasicContent = { cid: link.Hash, - name: name, + name, path: linkPath, resolve: async (options = {}) => { const result = await resolve(link.Hash, name, linkPath, [], depth + 1, blockstore, options) diff --git a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.ts b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.ts index 7d7026d8..fe16201e 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.ts +++ b/packages/ipfs-unixfs-exporter/test/exporter-sharded.spec.ts @@ -393,8 +393,8 @@ describe('exporter sharded', function () { const dirFiles = await all(exported.content()) // delete shard contents - for await (const entry of dirFiles) { - block.delete(entry.cid) + for (const entry of dirFiles) { + await block.delete(entry.cid) } // list the contents again, this time just the basic version diff --git a/packages/ipfs-unixfs-exporter/test/exporter.spec.ts b/packages/ipfs-unixfs-exporter/test/exporter.spec.ts index f6f7dc2f..9ce3056e 100644 --- a/packages/ipfs-unixfs-exporter/test/exporter.spec.ts +++ b/packages/ipfs-unixfs-exporter/test/exporter.spec.ts @@ -1633,8 +1633,8 @@ describe('exporter', () => { const dirFiles = await all(exported.content()) // delete shard contents - for await (const entry of dirFiles) { - block.delete(entry.cid) + for (const entry of dirFiles) { + await block.delete(entry.cid) } // list the contents again, this time just the basic version From b0e61ed9524c6188ab3632d5065ebf5cb2b14587 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 30 Jul 2025 09:01:27 +0200 Subject: [PATCH 3/4] chore: dedupe load --- .../resolvers/unixfs-v1/content/directory.ts | 13 +++---- .../content/hamt-sharded-directory.ts | 35 +++++++++++-------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts index 03313f4c..ca7d59f9 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts @@ -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, { diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts index 0dcbb0cd..16aa0d64 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts @@ -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) => { @@ -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) @@ -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) + } } } }), From 0aaab76fc4c55cb2be2bad29971cc478632d1b4c Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 30 Jul 2025 09:12:02 +0200 Subject: [PATCH 4/4] chore: linting --- .../src/resolvers/unixfs-v1/content/directory.ts | 4 ++-- .../src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts index ca7d59f9..614b33ca 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/directory.ts @@ -4,7 +4,7 @@ import parallel from 'it-parallel' import { pipe } from 'it-pipe' import { CustomProgressEvent } from 'progress-events' import { isBasicExporterOptions } from '../../../utils/is-basic-exporter-options.ts' -import type { BasicExporterOptions, ExporterOptions, ExportWalk, UnixfsV1BasicContent, UnixfsV1Resolver } from '../../../index.js' +import type { BasicExporterOptions, ExporterOptions, ExportWalk, UnixFSEntry, UnixfsV1BasicContent, UnixfsV1Resolver } from '../../../index.js' const directoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth, blockstore) => { async function * yieldDirectoryContent (options: ExporterOptions | BasicExporterOptions = {}): any { @@ -23,7 +23,7 @@ const directoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, de const linkName = link.Name ?? '' const linkPath = `${path}/${linkName}` - const load = async (options = {}) => { + const load = async (options = {}): Promise => { const result = await resolve(link.Hash, linkName, linkPath, [], depth + 1, blockstore, options) return result.entry } diff --git a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts index 16aa0d64..a3f56189 100644 --- a/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts +++ b/packages/ipfs-unixfs-exporter/src/resolvers/unixfs-v1/content/hamt-sharded-directory.ts @@ -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 } from '../../../index.js' +import type { ExporterOptions, Resolve, UnixfsV1DirectoryContent, UnixfsV1Resolver, ReadableStorage, ExportWalk, BasicExporterOptions, UnixFSEntry } from '../../../index.js' import type { PBNode } from '@ipld/dag-pb' const hamtShardedDirectoryContent: UnixfsV1Resolver = (cid, node, unixfs, path, resolve, depth, blockstore) => { @@ -49,7 +49,7 @@ async function * listDirectory (node: PBNode, path: string, resolve: Resolve, de if (name != null && name !== '') { const linkPath = `${path}/${name}` - const load = async (options = {}) => { + const load = async (options = {}): Promise => { const result = await resolve(link.Hash, name, linkPath, [], depth + 1, blockstore, options) return result.entry }