3232 */
3333
3434import type { CID , Version } from 'multiformats/cid'
35- import type { Blocks } from '@helia/interface/blocks'
35+ import type { Blocks , GetBlockProgressEvents , PutBlockProgressEvents } from '@helia/interface/blocks'
3636import type { AbortOptions } from '@libp2p/interfaces'
3737import { addAll , addBytes , addByteStream , addDirectory , addFile } from './commands/add.js'
3838import { cat } from './commands/cat.js'
@@ -45,16 +45,24 @@ import { touch } from './commands/touch.js'
4545import { chmod } from './commands/chmod.js'
4646import type { UnixFSEntry } from 'ipfs-unixfs-exporter'
4747import { ls } from './commands/ls.js'
48- import type { ByteStream , DirectoryCandidate , FileCandidate , ImportCandidateStream , ImporterOptions , ImportResult } from 'ipfs-unixfs-importer'
48+ import type { ByteStream , DirectoryCandidate , FileCandidate , ImportCandidateStream , ImporterOptions , ImportProgressEvents , ImportResult } from 'ipfs-unixfs-importer'
49+ import type { ProgressOptions } from 'progress-events'
4950
5051export interface UnixFSComponents {
5152 blockstore : Blocks
5253}
5354
55+ export type AddEvents = PutBlockProgressEvents
56+ | ImportProgressEvents
57+
58+ export interface AddOptions extends AbortOptions , Omit < ImporterOptions , 'onProgress' > , ProgressOptions < AddEvents > {
59+
60+ }
61+
5462/**
5563 * Options to pass to the cat command
5664 */
57- export interface CatOptions extends AbortOptions {
65+ export interface CatOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents > {
5866 /**
5967 * Start reading the file at this offset
6068 */
@@ -74,7 +82,7 @@ export interface CatOptions extends AbortOptions {
7482/**
7583 * Options to pass to the chmod command
7684 */
77- export interface ChmodOptions extends AbortOptions {
85+ export interface ChmodOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents | PutBlockProgressEvents > {
7886 /**
7987 * If the target of the operation is a directory and this is true,
8088 * apply the new mode to all directory contents
@@ -96,7 +104,7 @@ export interface ChmodOptions extends AbortOptions {
96104/**
97105 * Options to pass to the cp command
98106 */
99- export interface CpOptions extends AbortOptions {
107+ export interface CpOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents | PutBlockProgressEvents > {
100108 /**
101109 * If true, allow overwriting existing directory entries (default: false)
102110 */
@@ -112,7 +120,7 @@ export interface CpOptions extends AbortOptions {
112120/**
113121 * Options to pass to the ls command
114122 */
115- export interface LsOptions extends AbortOptions {
123+ export interface LsOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents > {
116124 /**
117125 * Optional path to list subdirectory contents if the target CID resolves to
118126 * a directory
@@ -133,7 +141,7 @@ export interface LsOptions extends AbortOptions {
133141/**
134142 * Options to pass to the mkdir command
135143 */
136- export interface MkdirOptions extends AbortOptions {
144+ export interface MkdirOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents | PutBlockProgressEvents > {
137145 /**
138146 * The CID version to create the new directory with - defaults to the same
139147 * version as the containing directory
@@ -165,7 +173,7 @@ export interface MkdirOptions extends AbortOptions {
165173/**
166174 * Options to pass to the rm command
167175 */
168- export interface RmOptions extends AbortOptions {
176+ export interface RmOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents | PutBlockProgressEvents > {
169177 /**
170178 * DAGs with a root block larger than this value will be sharded. Blocks
171179 * smaller than this value will be regular UnixFS directories.
@@ -176,7 +184,7 @@ export interface RmOptions extends AbortOptions {
176184/**
177185 * Options to pass to the stat command
178186 */
179- export interface StatOptions extends AbortOptions {
187+ export interface StatOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents > {
180188 /**
181189 * An optional path to allow statting paths inside directories
182190 */
@@ -292,7 +300,7 @@ export interface UnixFS {
292300 * }
293301 * ```
294302 */
295- addAll : ( source : ImportCandidateStream , options ?: Partial < ImporterOptions > ) => AsyncIterable < ImportResult >
303+ addAll : ( source : ImportCandidateStream , options ?: Partial < AddOptions > ) => AsyncIterable < ImportResult >
296304
297305 /**
298306 * Add a single `Uint8Array` to your Helia node as a file.
@@ -305,7 +313,7 @@ export interface UnixFS {
305313 * console.info(cid)
306314 * ```
307315 */
308- addBytes : ( bytes : Uint8Array , options ?: Partial < ImporterOptions > ) => Promise < CID >
316+ addBytes : ( bytes : Uint8Array , options ?: Partial < AddOptions > ) => Promise < CID >
309317
310318 /**
311319 * Add a stream of `Uint8Array` to your Helia node as a file.
@@ -321,7 +329,7 @@ export interface UnixFS {
321329 * console.info(cid)
322330 * ```
323331 */
324- addByteStream : ( bytes : ByteStream , options ?: Partial < ImporterOptions > ) => Promise < CID >
332+ addByteStream : ( bytes : ByteStream , options ?: Partial < AddOptions > ) => Promise < CID >
325333
326334 /**
327335 * Add a file to your Helia node with optional metadata.
@@ -342,7 +350,7 @@ export interface UnixFS {
342350 * console.info(cid)
343351 * ```
344352 */
345- addFile : ( file : FileCandidate , options ?: Partial < ImporterOptions > ) => Promise < CID >
353+ addFile : ( file : FileCandidate , options ?: Partial < AddOptions > ) => Promise < CID >
346354
347355 /**
348356 * Add a directory to your Helia node.
@@ -355,7 +363,7 @@ export interface UnixFS {
355363 * console.info(cid)
356364 * ```
357365 */
358- addDirectory : ( dir ?: Partial < DirectoryCandidate > , options ?: Partial < ImporterOptions > ) => Promise < CID >
366+ addDirectory : ( dir ?: Partial < DirectoryCandidate > , options ?: Partial < AddOptions > ) => Promise < CID >
359367
360368 /**
361369 * Retrieve the contents of a file from your Helia node.
@@ -368,7 +376,7 @@ export interface UnixFS {
368376 * }
369377 * ```
370378 */
371- cat : ( cid : CID , options ?: Partial < CatOptions > ) => AsyncIterable < Uint8Array >
379+ cat : ( cid : CID , options ?: Partial < CatOptions > & ProgressOptions < GetBlockProgressEvents > ) => AsyncIterable < Uint8Array >
372380
373381 /**
374382 * Change the permissions on a file or directory in a DAG
@@ -415,7 +423,7 @@ export interface UnixFS {
415423 * }
416424 * ```
417425 */
418- ls : ( cid : CID , options ?: Partial < LsOptions > ) => AsyncIterable < UnixFSEntry >
426+ ls : ( cid : CID , options ?: Partial < LsOptions > & ProgressOptions < GetBlockProgressEvents > ) => AsyncIterable < UnixFSEntry >
419427
420428 /**
421429 * Make a new directory under an existing directory.
@@ -489,23 +497,23 @@ class DefaultUnixFS implements UnixFS {
489497 this . components = components
490498 }
491499
492- async * addAll ( source : ImportCandidateStream , options : Partial < ImporterOptions > = { } ) : AsyncIterable < ImportResult > {
500+ async * addAll ( source : ImportCandidateStream , options : Partial < AddOptions > = { } ) : AsyncIterable < ImportResult > {
493501 yield * addAll ( source , this . components . blockstore , options )
494502 }
495503
496- async addBytes ( bytes : Uint8Array , options : Partial < ImporterOptions > = { } ) : Promise < CID > {
504+ async addBytes ( bytes : Uint8Array , options : Partial < AddOptions > = { } ) : Promise < CID > {
497505 return await addBytes ( bytes , this . components . blockstore , options )
498506 }
499507
500- async addByteStream ( bytes : ByteStream , options : Partial < ImporterOptions > = { } ) : Promise < CID > {
508+ async addByteStream ( bytes : ByteStream , options : Partial < AddOptions > = { } ) : Promise < CID > {
501509 return await addByteStream ( bytes , this . components . blockstore , options )
502510 }
503511
504- async addFile ( file : FileCandidate , options : Partial < ImporterOptions > = { } ) : Promise < CID > {
512+ async addFile ( file : FileCandidate , options : Partial < AddOptions > = { } ) : Promise < CID > {
505513 return await addFile ( file , this . components . blockstore , options )
506514 }
507515
508- async addDirectory ( dir : Partial < DirectoryCandidate > = { } , options : Partial < ImporterOptions > = { } ) : Promise < CID > {
516+ async addDirectory ( dir : Partial < DirectoryCandidate > = { } , options : Partial < AddOptions > = { } ) : Promise < CID > {
509517 return await addDirectory ( dir , this . components . blockstore , options )
510518 }
511519
0 commit comments