@helia/unixfs 4.0.2 → 4.0.3-325b36f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/src/commands/add.d.ts +7 -6
- package/dist/src/commands/add.d.ts.map +1 -1
- package/dist/src/commands/add.js +35 -13
- package/dist/src/commands/add.js.map +1 -1
- package/dist/src/commands/stat.d.ts +3 -2
- package/dist/src/commands/stat.d.ts.map +1 -1
- package/dist/src/commands/stat.js +125 -63
- package/dist/src/commands/stat.js.map +1 -1
- package/dist/src/commands/utils/add-link.js +4 -4
- package/dist/src/commands/utils/add-link.js.map +1 -1
- package/dist/src/commands/utils/dir-sharded.js +1 -1
- package/dist/src/commands/utils/dir-sharded.js.map +1 -1
- package/dist/src/commands/utils/remove-link.js +1 -1
- package/dist/src/commands/utils/remove-link.js.map +1 -1
- package/dist/src/errors.js +1 -1
- package/dist/src/errors.js.map +1 -1
- package/dist/src/index.d.ts +152 -30
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/unixfs.d.ts +4 -3
- package/dist/src/unixfs.d.ts.map +1 -1
- package/dist/src/unixfs.js.map +1 -1
- package/dist/src/utils/glob-source.d.ts +19 -0
- package/dist/src/utils/glob-source.d.ts.map +1 -1
- package/dist/src/utils/glob-source.js +19 -0
- package/dist/src/utils/glob-source.js.map +1 -1
- package/dist/src/utils/url-source.d.ts +48 -2
- package/dist/src/utils/url-source.d.ts.map +1 -1
- package/dist/src/utils/url-source.js +50 -0
- package/dist/src/utils/url-source.js.map +1 -1
- package/package.json +5 -4
- package/src/commands/add.ts +47 -17
- package/src/commands/stat.ts +149 -73
- package/src/commands/utils/add-link.ts +4 -4
- package/src/commands/utils/dir-sharded.ts +1 -1
- package/src/commands/utils/remove-link.ts +1 -1
- package/src/errors.ts +1 -1
- package/src/index.ts +163 -30
- package/src/unixfs.ts +5 -3
- package/src/utils/glob-source.ts +19 -0
- package/src/utils/url-source.ts +55 -2
- package/dist/typedoc-urls.json +0 -56
package/src/index.ts
CHANGED
|
@@ -49,10 +49,11 @@
|
|
|
49
49
|
import { UnixFS as UnixFSClass } from './unixfs.js'
|
|
50
50
|
import type { GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks'
|
|
51
51
|
import type { AbortOptions } from '@libp2p/interface'
|
|
52
|
+
import type { Filter } from '@libp2p/utils/filters'
|
|
52
53
|
import type { Blockstore } from 'interface-blockstore'
|
|
53
54
|
import type { Mtime, UnixFS as IPFSUnixFS } from 'ipfs-unixfs'
|
|
54
55
|
import type { ExporterProgressEvents, UnixFSEntry } from 'ipfs-unixfs-exporter'
|
|
55
|
-
import type { ByteStream, DirectoryCandidate,
|
|
56
|
+
import type { ByteStream, DirectoryCandidate, ImportCandidateStream, ImporterOptions, ImporterProgressEvents, ImportResult, ImportContent } from 'ipfs-unixfs-importer'
|
|
56
57
|
import type { CID, Version } from 'multiformats/cid'
|
|
57
58
|
import type { ProgressOptions } from 'progress-events'
|
|
58
59
|
|
|
@@ -60,6 +61,13 @@ export interface UnixFSComponents {
|
|
|
60
61
|
blockstore: Pick<Blockstore, 'get' | 'put' | 'has'>
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
export interface FileCandidate<T extends ImportContent = ImportContent> {
|
|
65
|
+
path: string
|
|
66
|
+
content: T
|
|
67
|
+
mtime?: Mtime
|
|
68
|
+
mode?: number
|
|
69
|
+
}
|
|
70
|
+
|
|
63
71
|
export type AddEvents = PutBlockProgressEvents
|
|
64
72
|
| ImporterProgressEvents
|
|
65
73
|
|
|
@@ -67,6 +75,8 @@ export interface AddOptions extends AbortOptions, Omit<ImporterOptions, 'onProgr
|
|
|
67
75
|
|
|
68
76
|
}
|
|
69
77
|
|
|
78
|
+
export type AddFileOptions = Omit<AddOptions, 'wrapWithDirectory'>
|
|
79
|
+
|
|
70
80
|
export type GetEvents = GetBlockProgressEvents
|
|
71
81
|
| ExporterProgressEvents
|
|
72
82
|
|
|
@@ -233,21 +243,38 @@ export interface RmOptions extends AbortOptions, ProgressOptions<GetEvents | Put
|
|
|
233
243
|
*/
|
|
234
244
|
export interface StatOptions extends AbortOptions, ProgressOptions<GetEvents> {
|
|
235
245
|
/**
|
|
236
|
-
* An optional path to allow
|
|
246
|
+
* An optional path to allow getting stats of paths inside directories
|
|
237
247
|
*/
|
|
238
248
|
path?: string
|
|
239
249
|
|
|
240
250
|
/**
|
|
241
251
|
* If true, do not perform any network operations and throw if blocks are
|
|
242
|
-
* missing from the local store.
|
|
252
|
+
* missing from the local store.
|
|
253
|
+
*
|
|
254
|
+
* @default false
|
|
243
255
|
*/
|
|
244
256
|
offline?: boolean
|
|
245
257
|
}
|
|
246
258
|
|
|
259
|
+
export interface ExtendedStatOptions extends StatOptions {
|
|
260
|
+
/**
|
|
261
|
+
* If true, traverse the whole DAG to return additional stats. If all data is
|
|
262
|
+
* not in the local blockstore, this may involve fetching them from the
|
|
263
|
+
* network.
|
|
264
|
+
*/
|
|
265
|
+
extended: true
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* By default CIDs are deduplicated using a `ScalableCuckooFilter` - if you
|
|
269
|
+
* wish to use a different filter, pass it here.
|
|
270
|
+
*/
|
|
271
|
+
filter?: Filter
|
|
272
|
+
}
|
|
273
|
+
|
|
247
274
|
/**
|
|
248
275
|
* Statistics relating to a UnixFS DAG
|
|
249
276
|
*/
|
|
250
|
-
export interface
|
|
277
|
+
export interface Stats {
|
|
251
278
|
/**
|
|
252
279
|
* The file or directory CID
|
|
253
280
|
*/
|
|
@@ -256,7 +283,7 @@ export interface UnixFSStats {
|
|
|
256
283
|
/**
|
|
257
284
|
* The file or directory mode
|
|
258
285
|
*/
|
|
259
|
-
mode
|
|
286
|
+
mode: number
|
|
260
287
|
|
|
261
288
|
/**
|
|
262
289
|
* The file or directory mtime
|
|
@@ -264,41 +291,112 @@ export interface UnixFSStats {
|
|
|
264
291
|
mtime?: Mtime
|
|
265
292
|
|
|
266
293
|
/**
|
|
267
|
-
* The
|
|
294
|
+
* The type of UnixFS node - 'file' or 'directory'
|
|
268
295
|
*/
|
|
269
|
-
|
|
296
|
+
type: 'file' | 'directory' | 'raw'
|
|
270
297
|
|
|
271
298
|
/**
|
|
272
|
-
*
|
|
299
|
+
* UnixFS metadata about this file or directory
|
|
273
300
|
*/
|
|
274
|
-
|
|
301
|
+
unixfs?: IPFSUnixFS
|
|
275
302
|
|
|
276
303
|
/**
|
|
277
|
-
*
|
|
304
|
+
* The size in bytes of the file as reported by the UnixFS metadata stored in
|
|
305
|
+
* the root DAG node, or if the CID resolves to a raw node, the size of the
|
|
306
|
+
* block that holds it.
|
|
307
|
+
*
|
|
308
|
+
* For directories this will return `0` as no size information is available in
|
|
309
|
+
* the root block - instead please stat with the `extended` option to traverse
|
|
310
|
+
* the DAG and calculate the size.
|
|
278
311
|
*/
|
|
279
|
-
|
|
312
|
+
size: bigint
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export interface FileStats extends Stats {
|
|
316
|
+
type: 'file'
|
|
317
|
+
unixfs: IPFSUnixFS
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
export interface DirectoryStats extends Stats {
|
|
321
|
+
type: 'directory'
|
|
322
|
+
unixfs: IPFSUnixFS
|
|
323
|
+
}
|
|
280
324
|
|
|
325
|
+
export interface RawStats extends Stats {
|
|
326
|
+
type: 'raw'
|
|
327
|
+
unixfs: undefined
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* More detailed statistics relating to a UnixFS DAG. These can involve
|
|
332
|
+
* traversing the DAG behind the CID so can involve network operations and/or
|
|
333
|
+
* more disk activity.
|
|
334
|
+
*/
|
|
335
|
+
export interface ExtendedStats extends Stats {
|
|
281
336
|
/**
|
|
282
|
-
* How
|
|
337
|
+
* How many blocks make up the DAG.
|
|
338
|
+
*
|
|
339
|
+
* nb. this will only be accurate if either all blocks are present in the
|
|
340
|
+
* local blockstore or the `offline` option was not `true`
|
|
283
341
|
*/
|
|
284
|
-
|
|
342
|
+
blocks: bigint
|
|
285
343
|
|
|
286
344
|
/**
|
|
287
|
-
* How many blocks make up the DAG -
|
|
288
|
-
*
|
|
345
|
+
* How many unique blocks make up the DAG - this count does not include any
|
|
346
|
+
* blocks that appear in the DAG more than once.
|
|
347
|
+
*
|
|
348
|
+
* nb. this will only be accurate if either all blocks are present in the
|
|
349
|
+
* local blockstore or the `offline` option was not `true`
|
|
289
350
|
*/
|
|
290
|
-
|
|
351
|
+
uniqueBlocks: bigint
|
|
291
352
|
|
|
292
353
|
/**
|
|
293
|
-
* The
|
|
354
|
+
* The size of the DAG that holds the file or directory in bytes - this is
|
|
355
|
+
* the sum of all block sizes so includes any protobuf overhead, etc.
|
|
356
|
+
*
|
|
357
|
+
* Duplicate blocks are included in this measurement.
|
|
358
|
+
*
|
|
359
|
+
* nb. this will only be accurate if either all blocks are present in the
|
|
360
|
+
* local blockstore or the `offline` option was not `true`
|
|
294
361
|
*/
|
|
295
|
-
|
|
362
|
+
dagSize: bigint
|
|
296
363
|
|
|
297
364
|
/**
|
|
298
|
-
*
|
|
299
|
-
*
|
|
365
|
+
* Similar to `dagSize` except duplicate blocks are not included in the
|
|
366
|
+
* reported amount.
|
|
367
|
+
*
|
|
368
|
+
* nb. this will only be accurate if either all blocks are present in the
|
|
369
|
+
* local blockstore or the `offline` option was not `true`
|
|
300
370
|
*/
|
|
301
|
-
|
|
371
|
+
deduplicatedDagSize: bigint
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* How much of the file or directory is in the local block store. If this is a
|
|
375
|
+
* directory it will include the `localSize` of all child files and
|
|
376
|
+
* directories.
|
|
377
|
+
*
|
|
378
|
+
* It does not include protobuf overhead, for that see `dagSize`.
|
|
379
|
+
*
|
|
380
|
+
* nb. if the `offline` option is `true`, and not all blocks for the
|
|
381
|
+
* file/directory are in the blockstore, this number may be smaller than
|
|
382
|
+
* `size`.
|
|
383
|
+
*/
|
|
384
|
+
localSize: bigint
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
export interface ExtendedFileStats extends ExtendedStats {
|
|
388
|
+
type: 'file'
|
|
389
|
+
unixfs: IPFSUnixFS
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export interface ExtendedDirectoryStats extends ExtendedStats {
|
|
393
|
+
type: 'directory'
|
|
394
|
+
unixfs: IPFSUnixFS
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
export interface ExtendedRawStats extends ExtendedStats {
|
|
398
|
+
type: 'raw'
|
|
399
|
+
unixfs: undefined
|
|
302
400
|
}
|
|
303
401
|
|
|
304
402
|
/**
|
|
@@ -362,7 +460,11 @@ export interface UnixFS {
|
|
|
362
460
|
addAll(source: ImportCandidateStream, options?: Partial<AddOptions>): AsyncIterable<ImportResult>
|
|
363
461
|
|
|
364
462
|
/**
|
|
365
|
-
* Add a single `Uint8Array` to your Helia node
|
|
463
|
+
* Add a single `Uint8Array` to your Helia node and receive a CID that will
|
|
464
|
+
* resolve to it.
|
|
465
|
+
*
|
|
466
|
+
* If you want to preserve a file name or other metadata such as modification
|
|
467
|
+
* time or mode, use `addFile` instead.
|
|
366
468
|
*
|
|
367
469
|
* @example
|
|
368
470
|
*
|
|
@@ -372,10 +474,14 @@ export interface UnixFS {
|
|
|
372
474
|
* console.info(cid)
|
|
373
475
|
* ```
|
|
374
476
|
*/
|
|
375
|
-
addBytes(bytes: Uint8Array, options?: Partial<
|
|
477
|
+
addBytes(bytes: Uint8Array, options?: Partial<AddFileOptions>): Promise<CID>
|
|
376
478
|
|
|
377
479
|
/**
|
|
378
|
-
* Add a stream of `Uint8Array` to your Helia node
|
|
480
|
+
* Add a stream of `Uint8Array`s to your Helia node and receive a CID that
|
|
481
|
+
* will resolve to them.
|
|
482
|
+
*
|
|
483
|
+
* If you want to preserve a file name or other metadata such as modification
|
|
484
|
+
* time or mode, use `addFile` instead.
|
|
379
485
|
*
|
|
380
486
|
* @example
|
|
381
487
|
*
|
|
@@ -388,10 +494,14 @@ export interface UnixFS {
|
|
|
388
494
|
* console.info(cid)
|
|
389
495
|
* ```
|
|
390
496
|
*/
|
|
391
|
-
addByteStream(bytes: ByteStream, options?: Partial<
|
|
497
|
+
addByteStream(bytes: ByteStream, options?: Partial<AddFileOptions>): Promise<CID>
|
|
392
498
|
|
|
393
499
|
/**
|
|
394
|
-
* Add a file to your Helia node with
|
|
500
|
+
* Add a file to your Helia node with metadata. The returned CID will resolve
|
|
501
|
+
* to a directory with one file entry.
|
|
502
|
+
*
|
|
503
|
+
* If you don't care about file names and just want a CID that will resolve to
|
|
504
|
+
* the contents of the file, use `addBytes` or `addByeStream` instead.
|
|
395
505
|
*
|
|
396
506
|
* @example
|
|
397
507
|
*
|
|
@@ -409,20 +519,42 @@ export interface UnixFS {
|
|
|
409
519
|
* console.info(cid)
|
|
410
520
|
* ```
|
|
411
521
|
*/
|
|
412
|
-
addFile(file: FileCandidate, options?: Partial<
|
|
522
|
+
addFile(file: FileCandidate, options?: Partial<AddFileOptions>): Promise<CID>
|
|
413
523
|
|
|
414
524
|
/**
|
|
415
525
|
* Add a directory to your Helia node.
|
|
416
526
|
*
|
|
417
527
|
* @example
|
|
418
528
|
*
|
|
529
|
+
* If no path is specified, the returned CID will resolve to an empty
|
|
530
|
+
* directory.
|
|
531
|
+
*
|
|
419
532
|
* ```typescript
|
|
420
533
|
* const cid = await fs.addDirectory()
|
|
421
534
|
*
|
|
422
|
-
* console.info(cid)
|
|
535
|
+
* console.info(cid) // empty directory CID
|
|
536
|
+
* ```
|
|
537
|
+
*
|
|
538
|
+
* @example
|
|
539
|
+
*
|
|
540
|
+
* If a path is specified, the CID will resolve to a directory that contains
|
|
541
|
+
* an empty directory with the specified name.
|
|
542
|
+
*
|
|
543
|
+
* ```typescript
|
|
544
|
+
* const cid = await fs.addDirectory({
|
|
545
|
+
* path: 'my-dir'
|
|
546
|
+
* })
|
|
547
|
+
*
|
|
548
|
+
* console.info(cid) // containing directory CID
|
|
549
|
+
*
|
|
550
|
+
* const stat = await fs.stat(cid, {
|
|
551
|
+
* path: 'my-dir'
|
|
552
|
+
* })
|
|
553
|
+
*
|
|
554
|
+
* console.info(stat.cid) // empty directory CID
|
|
423
555
|
* ```
|
|
424
556
|
*/
|
|
425
|
-
addDirectory(dir?: Partial<DirectoryCandidate>, options?: Partial<
|
|
557
|
+
addDirectory(dir?: Partial<DirectoryCandidate>, options?: Partial<AddFileOptions>): Promise<CID>
|
|
426
558
|
|
|
427
559
|
/**
|
|
428
560
|
* Retrieve the contents of a file from your Helia node.
|
|
@@ -528,7 +660,8 @@ export interface UnixFS {
|
|
|
528
660
|
* console.info(stats)
|
|
529
661
|
* ```
|
|
530
662
|
*/
|
|
531
|
-
stat(cid: CID, options?:
|
|
663
|
+
stat(cid: CID, options?: StatOptions): Promise<FileStats | DirectoryStats | RawStats>
|
|
664
|
+
stat(cid: CID, options?: ExtendedStatOptions): Promise<ExtendedFileStats | ExtendedDirectoryStats | ExtendedRawStats>
|
|
532
665
|
|
|
533
666
|
/**
|
|
534
667
|
* Update the mtime of a UnixFS DAG
|
package/src/unixfs.ts
CHANGED
|
@@ -7,10 +7,10 @@ import { mkdir } from './commands/mkdir.js'
|
|
|
7
7
|
import { rm } from './commands/rm.js'
|
|
8
8
|
import { stat } from './commands/stat.js'
|
|
9
9
|
import { touch } from './commands/touch.js'
|
|
10
|
-
import type { AddOptions, CatOptions, ChmodOptions, CpOptions, LsOptions, MkdirOptions, RmOptions, StatOptions, TouchOptions, UnixFSComponents, UnixFS as UnixFSInterface,
|
|
10
|
+
import type { AddOptions, CatOptions, ChmodOptions, CpOptions, ExtendedStatOptions, ExtendedDirectoryStats, ExtendedFileStats, FileCandidate, LsOptions, MkdirOptions, RmOptions, StatOptions, TouchOptions, UnixFSComponents, DirectoryStats, FileStats, UnixFS as UnixFSInterface, RawStats, ExtendedRawStats } from './index.js'
|
|
11
11
|
import type { Blockstore } from 'interface-blockstore'
|
|
12
12
|
import type { UnixFSEntry } from 'ipfs-unixfs-exporter'
|
|
13
|
-
import type { ByteStream, DirectoryCandidate,
|
|
13
|
+
import type { ByteStream, DirectoryCandidate, ImportCandidateStream, ImportResult } from 'ipfs-unixfs-importer'
|
|
14
14
|
import type { CID } from 'multiformats/cid'
|
|
15
15
|
|
|
16
16
|
export type PutStore = Pick<Blockstore, 'put'>
|
|
@@ -68,7 +68,9 @@ export class UnixFS implements UnixFSInterface {
|
|
|
68
68
|
return rm(cid, path, this.components.blockstore, options)
|
|
69
69
|
}
|
|
70
70
|
|
|
71
|
-
async stat (cid: CID, options
|
|
71
|
+
async stat (cid: CID, options?: StatOptions): Promise<FileStats | DirectoryStats | RawStats>
|
|
72
|
+
async stat (cid: CID, options?: ExtendedStatOptions): Promise<ExtendedFileStats | ExtendedDirectoryStats | ExtendedRawStats>
|
|
73
|
+
async stat (cid: CID, options: Partial<StatOptions> = {}): Promise<FileStats | DirectoryStats | RawStats> {
|
|
72
74
|
return stat(cid, this.components.blockstore, options)
|
|
73
75
|
}
|
|
74
76
|
|
package/src/utils/glob-source.ts
CHANGED
|
@@ -50,6 +50,25 @@ export interface GlobSourceResult {
|
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
52
|
* Create an async iterator that yields paths that match requested glob pattern
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { unixfs, globSource } from '@helia/unixfs'
|
|
58
|
+
* import { createHelia } from 'helia'
|
|
59
|
+
*
|
|
60
|
+
* const helia = await createHelia()
|
|
61
|
+
* const fs = unixfs(helia)
|
|
62
|
+
*
|
|
63
|
+
* for await (const entry of fs.addAll(globSource(
|
|
64
|
+
* '/path/to/dir',
|
|
65
|
+
* '**\/*'
|
|
66
|
+
* ), {
|
|
67
|
+
* wrapWithDirectory: true
|
|
68
|
+
* })) {
|
|
69
|
+
* console.info(entry)
|
|
70
|
+
* }
|
|
71
|
+
* ```
|
|
53
72
|
*/
|
|
54
73
|
export async function * globSource (cwd: string, pattern: string, options: GlobSourceOptions = {}): AsyncGenerator<ImportCandidate & GlobSourceResult> {
|
|
55
74
|
if (typeof pattern !== 'string') {
|
package/src/utils/url-source.ts
CHANGED
|
@@ -1,13 +1,66 @@
|
|
|
1
1
|
import { UnknownError } from '../errors.js'
|
|
2
|
-
import type { FileCandidate } from '
|
|
2
|
+
import type { FileCandidate } from '../index.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Import a file directly from a URL. The path of the file will be the path
|
|
6
|
+
* section of the URL.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* import { unixfs, urlSource } from '@helia/unixfs'
|
|
12
|
+
* import { createHelia } from 'helia'
|
|
13
|
+
*
|
|
14
|
+
* const helia = await createHelia()
|
|
15
|
+
* const fs = unixfs(helia)
|
|
16
|
+
*
|
|
17
|
+
* const cid = await fs.addFile(urlSource('http://example.com/path/to/file.html))
|
|
18
|
+
* const stat = await fs.stat(cid)
|
|
19
|
+
*
|
|
20
|
+
* console.info(stat)
|
|
21
|
+
* // { cid: CID(...), type: 'directory', ... }
|
|
22
|
+
*
|
|
23
|
+
* for await (const entry of fs.ls(cid)) {
|
|
24
|
+
* console.info(entry)
|
|
25
|
+
* // { type: 'file', name: 'file.html', cid: CID(...), ... }
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export function urlSource (url: URL | string, options?: RequestInit): FileCandidate<AsyncGenerator<Uint8Array, void, unknown>> {
|
|
30
|
+
url = new URL(url)
|
|
3
31
|
|
|
4
|
-
export function urlSource (url: URL, options?: RequestInit): FileCandidate<AsyncGenerator<Uint8Array, void, unknown>> {
|
|
5
32
|
return {
|
|
6
33
|
path: decodeURIComponent(new URL(url).pathname.split('/').pop() ?? ''),
|
|
7
34
|
content: readURLContent(url, options)
|
|
8
35
|
}
|
|
9
36
|
}
|
|
10
37
|
|
|
38
|
+
/**
|
|
39
|
+
* Import a file directly from a URL ignoring the file name or any containing
|
|
40
|
+
* directory.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
*
|
|
44
|
+
* ```ts
|
|
45
|
+
* import { unixfs, urlByteSource } from '@helia/unixfs'
|
|
46
|
+
* import { createHelia } from 'helia'
|
|
47
|
+
*
|
|
48
|
+
* const helia = await createHelia()
|
|
49
|
+
* const fs = unixfs(helia)
|
|
50
|
+
*
|
|
51
|
+
* const cid = await fs.addByteSource(urlByteSource('http://example.com/path/to/file.html))
|
|
52
|
+
* const stat = await fs.stat(cid)
|
|
53
|
+
*
|
|
54
|
+
* console.info(stat)
|
|
55
|
+
* // { type: 'file', cid: CID(...), ... }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export function urlByteSource (url: URL | string, options?: RequestInit): AsyncGenerator<Uint8Array, void, unknown> {
|
|
59
|
+
url = new URL(url)
|
|
60
|
+
|
|
61
|
+
return readURLContent(url, options)
|
|
62
|
+
}
|
|
63
|
+
|
|
11
64
|
async function * readURLContent (url: URL, options?: RequestInit): AsyncGenerator<Uint8Array, void, unknown> {
|
|
12
65
|
const response = await globalThis.fetch(url, options)
|
|
13
66
|
|
package/dist/typedoc-urls.json
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"AlreadyExistsError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.AlreadyExistsError.html",
|
|
3
|
-
"./errors:AlreadyExistsError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.AlreadyExistsError.html",
|
|
4
|
-
"DoesNotExistError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.DoesNotExistError.html",
|
|
5
|
-
"./errors:DoesNotExistError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.DoesNotExistError.html",
|
|
6
|
-
"InvalidPBNodeError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.InvalidPBNodeError.html",
|
|
7
|
-
"./errors:InvalidPBNodeError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.InvalidPBNodeError.html",
|
|
8
|
-
"InvalidParametersError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.InvalidParametersError.html",
|
|
9
|
-
"./errors:InvalidParametersError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.InvalidParametersError.html",
|
|
10
|
-
"NoContentError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NoContentError.html",
|
|
11
|
-
"./errors:NoContentError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NoContentError.html",
|
|
12
|
-
"NotADirectoryError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NotADirectoryError.html",
|
|
13
|
-
"./errors:NotADirectoryError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NotADirectoryError.html",
|
|
14
|
-
"NotAFileError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NotAFileError.html",
|
|
15
|
-
"./errors:NotAFileError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NotAFileError.html",
|
|
16
|
-
"NotUnixFSError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NotUnixFSError.html",
|
|
17
|
-
"./errors:NotUnixFSError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NotUnixFSError.html",
|
|
18
|
-
"UnixFSError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.UnixFSError.html",
|
|
19
|
-
"./errors:UnixFSError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.UnixFSError.html",
|
|
20
|
-
"UnknownError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.UnknownError.html",
|
|
21
|
-
"./errors:UnknownError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.UnknownError.html",
|
|
22
|
-
"AddOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.AddOptions.html",
|
|
23
|
-
".:AddOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.AddOptions.html",
|
|
24
|
-
"CatOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.CatOptions.html",
|
|
25
|
-
".:CatOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.CatOptions.html",
|
|
26
|
-
"ChmodOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ChmodOptions.html",
|
|
27
|
-
".:ChmodOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ChmodOptions.html",
|
|
28
|
-
"CpOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.CpOptions.html",
|
|
29
|
-
".:CpOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.CpOptions.html",
|
|
30
|
-
"GlobSourceOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.GlobSourceOptions.html",
|
|
31
|
-
"GlobSourceResult": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.GlobSourceResult.html",
|
|
32
|
-
"LsOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.LsOptions.html",
|
|
33
|
-
".:LsOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.LsOptions.html",
|
|
34
|
-
"MkdirOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.MkdirOptions.html",
|
|
35
|
-
".:MkdirOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.MkdirOptions.html",
|
|
36
|
-
"RmOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.RmOptions.html",
|
|
37
|
-
".:RmOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.RmOptions.html",
|
|
38
|
-
"StatOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.StatOptions.html",
|
|
39
|
-
".:StatOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.StatOptions.html",
|
|
40
|
-
"TouchOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.TouchOptions.html",
|
|
41
|
-
".:TouchOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.TouchOptions.html",
|
|
42
|
-
"UnixFS": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFS.html",
|
|
43
|
-
".:UnixFS": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFS.html",
|
|
44
|
-
"UnixFSComponents": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFSComponents.html",
|
|
45
|
-
".:UnixFSComponents": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFSComponents.html",
|
|
46
|
-
"UnixFSStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFSStats.html",
|
|
47
|
-
".:UnixFSStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFSStats.html",
|
|
48
|
-
"AddEvents": "https://ipfs.github.io/helia/types/_helia_unixfs.index.AddEvents.html",
|
|
49
|
-
".:AddEvents": "https://ipfs.github.io/helia/types/_helia_unixfs.index.AddEvents.html",
|
|
50
|
-
"GetEvents": "https://ipfs.github.io/helia/types/_helia_unixfs.index.GetEvents.html",
|
|
51
|
-
".:GetEvents": "https://ipfs.github.io/helia/types/_helia_unixfs.index.GetEvents.html",
|
|
52
|
-
"globSource": "https://ipfs.github.io/helia/functions/_helia_unixfs.index.globSource.html",
|
|
53
|
-
"unixfs": "https://ipfs.github.io/helia/functions/_helia_unixfs.index.unixfs-1.html",
|
|
54
|
-
".:unixfs": "https://ipfs.github.io/helia/functions/_helia_unixfs.index.unixfs-1.html",
|
|
55
|
-
"urlSource": "https://ipfs.github.io/helia/functions/_helia_unixfs.index.urlSource.html"
|
|
56
|
-
}
|