32
32
*/
33
33
34
34
import type { CID , Version } from 'multiformats/cid'
35
- import type { Blocks } from '@helia/interface/blocks'
35
+ import type { Blocks , GetBlockProgressEvents , PutBlockProgressEvents } from '@helia/interface/blocks'
36
36
import type { AbortOptions } from '@libp2p/interfaces'
37
37
import { addAll , addBytes , addByteStream , addDirectory , addFile } from './commands/add.js'
38
38
import { cat } from './commands/cat.js'
@@ -45,16 +45,24 @@ import { touch } from './commands/touch.js'
45
45
import { chmod } from './commands/chmod.js'
46
46
import type { UnixFSEntry } from 'ipfs-unixfs-exporter'
47
47
import { 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'
49
50
50
51
export interface UnixFSComponents {
51
52
blockstore : Blocks
52
53
}
53
54
55
+ export type AddEvents = PutBlockProgressEvents
56
+ | ImportProgressEvents
57
+
58
+ export interface AddOptions extends AbortOptions , Omit < ImporterOptions , 'onProgress' > , ProgressOptions < AddEvents > {
59
+
60
+ }
61
+
54
62
/**
55
63
* Options to pass to the cat command
56
64
*/
57
- export interface CatOptions extends AbortOptions {
65
+ export interface CatOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents > {
58
66
/**
59
67
* Start reading the file at this offset
60
68
*/
@@ -74,7 +82,7 @@ export interface CatOptions extends AbortOptions {
74
82
/**
75
83
* Options to pass to the chmod command
76
84
*/
77
- export interface ChmodOptions extends AbortOptions {
85
+ export interface ChmodOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents | PutBlockProgressEvents > {
78
86
/**
79
87
* If the target of the operation is a directory and this is true,
80
88
* apply the new mode to all directory contents
@@ -96,7 +104,7 @@ export interface ChmodOptions extends AbortOptions {
96
104
/**
97
105
* Options to pass to the cp command
98
106
*/
99
- export interface CpOptions extends AbortOptions {
107
+ export interface CpOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents | PutBlockProgressEvents > {
100
108
/**
101
109
* If true, allow overwriting existing directory entries (default: false)
102
110
*/
@@ -112,7 +120,7 @@ export interface CpOptions extends AbortOptions {
112
120
/**
113
121
* Options to pass to the ls command
114
122
*/
115
- export interface LsOptions extends AbortOptions {
123
+ export interface LsOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents > {
116
124
/**
117
125
* Optional path to list subdirectory contents if the target CID resolves to
118
126
* a directory
@@ -133,7 +141,7 @@ export interface LsOptions extends AbortOptions {
133
141
/**
134
142
* Options to pass to the mkdir command
135
143
*/
136
- export interface MkdirOptions extends AbortOptions {
144
+ export interface MkdirOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents | PutBlockProgressEvents > {
137
145
/**
138
146
* The CID version to create the new directory with - defaults to the same
139
147
* version as the containing directory
@@ -165,7 +173,7 @@ export interface MkdirOptions extends AbortOptions {
165
173
/**
166
174
* Options to pass to the rm command
167
175
*/
168
- export interface RmOptions extends AbortOptions {
176
+ export interface RmOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents | PutBlockProgressEvents > {
169
177
/**
170
178
* DAGs with a root block larger than this value will be sharded. Blocks
171
179
* smaller than this value will be regular UnixFS directories.
@@ -176,7 +184,7 @@ export interface RmOptions extends AbortOptions {
176
184
/**
177
185
* Options to pass to the stat command
178
186
*/
179
- export interface StatOptions extends AbortOptions {
187
+ export interface StatOptions extends AbortOptions , ProgressOptions < GetBlockProgressEvents > {
180
188
/**
181
189
* An optional path to allow statting paths inside directories
182
190
*/
@@ -292,7 +300,7 @@ export interface UnixFS {
292
300
* }
293
301
* ```
294
302
*/
295
- addAll : ( source : ImportCandidateStream , options ?: Partial < ImporterOptions > ) => AsyncIterable < ImportResult >
303
+ addAll : ( source : ImportCandidateStream , options ?: Partial < AddOptions > ) => AsyncIterable < ImportResult >
296
304
297
305
/**
298
306
* Add a single `Uint8Array` to your Helia node as a file.
@@ -305,7 +313,7 @@ export interface UnixFS {
305
313
* console.info(cid)
306
314
* ```
307
315
*/
308
- addBytes : ( bytes : Uint8Array , options ?: Partial < ImporterOptions > ) => Promise < CID >
316
+ addBytes : ( bytes : Uint8Array , options ?: Partial < AddOptions > ) => Promise < CID >
309
317
310
318
/**
311
319
* Add a stream of `Uint8Array` to your Helia node as a file.
@@ -321,7 +329,7 @@ export interface UnixFS {
321
329
* console.info(cid)
322
330
* ```
323
331
*/
324
- addByteStream : ( bytes : ByteStream , options ?: Partial < ImporterOptions > ) => Promise < CID >
332
+ addByteStream : ( bytes : ByteStream , options ?: Partial < AddOptions > ) => Promise < CID >
325
333
326
334
/**
327
335
* Add a file to your Helia node with optional metadata.
@@ -342,7 +350,7 @@ export interface UnixFS {
342
350
* console.info(cid)
343
351
* ```
344
352
*/
345
- addFile : ( file : FileCandidate , options ?: Partial < ImporterOptions > ) => Promise < CID >
353
+ addFile : ( file : FileCandidate , options ?: Partial < AddOptions > ) => Promise < CID >
346
354
347
355
/**
348
356
* Add a directory to your Helia node.
@@ -355,7 +363,7 @@ export interface UnixFS {
355
363
* console.info(cid)
356
364
* ```
357
365
*/
358
- addDirectory : ( dir ?: Partial < DirectoryCandidate > , options ?: Partial < ImporterOptions > ) => Promise < CID >
366
+ addDirectory : ( dir ?: Partial < DirectoryCandidate > , options ?: Partial < AddOptions > ) => Promise < CID >
359
367
360
368
/**
361
369
* Retrieve the contents of a file from your Helia node.
@@ -368,7 +376,7 @@ export interface UnixFS {
368
376
* }
369
377
* ```
370
378
*/
371
- cat : ( cid : CID , options ?: Partial < CatOptions > ) => AsyncIterable < Uint8Array >
379
+ cat : ( cid : CID , options ?: Partial < CatOptions > & ProgressOptions < GetBlockProgressEvents > ) => AsyncIterable < Uint8Array >
372
380
373
381
/**
374
382
* Change the permissions on a file or directory in a DAG
@@ -415,7 +423,7 @@ export interface UnixFS {
415
423
* }
416
424
* ```
417
425
*/
418
- ls : ( cid : CID , options ?: Partial < LsOptions > ) => AsyncIterable < UnixFSEntry >
426
+ ls : ( cid : CID , options ?: Partial < LsOptions > & ProgressOptions < GetBlockProgressEvents > ) => AsyncIterable < UnixFSEntry >
419
427
420
428
/**
421
429
* Make a new directory under an existing directory.
@@ -489,23 +497,23 @@ class DefaultUnixFS implements UnixFS {
489
497
this . components = components
490
498
}
491
499
492
- async * addAll ( source : ImportCandidateStream , options : Partial < ImporterOptions > = { } ) : AsyncIterable < ImportResult > {
500
+ async * addAll ( source : ImportCandidateStream , options : Partial < AddOptions > = { } ) : AsyncIterable < ImportResult > {
493
501
yield * addAll ( source , this . components . blockstore , options )
494
502
}
495
503
496
- async addBytes ( bytes : Uint8Array , options : Partial < ImporterOptions > = { } ) : Promise < CID > {
504
+ async addBytes ( bytes : Uint8Array , options : Partial < AddOptions > = { } ) : Promise < CID > {
497
505
return await addBytes ( bytes , this . components . blockstore , options )
498
506
}
499
507
500
- async addByteStream ( bytes : ByteStream , options : Partial < ImporterOptions > = { } ) : Promise < CID > {
508
+ async addByteStream ( bytes : ByteStream , options : Partial < AddOptions > = { } ) : Promise < CID > {
501
509
return await addByteStream ( bytes , this . components . blockstore , options )
502
510
}
503
511
504
- async addFile ( file : FileCandidate , options : Partial < ImporterOptions > = { } ) : Promise < CID > {
512
+ async addFile ( file : FileCandidate , options : Partial < AddOptions > = { } ) : Promise < CID > {
505
513
return await addFile ( file , this . components . blockstore , options )
506
514
}
507
515
508
- async addDirectory ( dir : Partial < DirectoryCandidate > = { } , options : Partial < ImporterOptions > = { } ) : Promise < CID > {
516
+ async addDirectory ( dir : Partial < DirectoryCandidate > = { } , options : Partial < AddOptions > = { } ) : Promise < CID > {
509
517
return await addDirectory ( dir , this . components . blockstore , options )
510
518
}
511
519
0 commit comments