@helia/unixfs 3.0.4 → 3.0.5-0ecb529

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.
Files changed (85) hide show
  1. package/dist/index.min.js +1 -1
  2. package/dist/src/commands/add.d.ts +6 -6
  3. package/dist/src/commands/add.d.ts.map +1 -1
  4. package/dist/src/commands/add.js.map +1 -1
  5. package/dist/src/commands/cat.d.ts +2 -2
  6. package/dist/src/commands/cat.d.ts.map +1 -1
  7. package/dist/src/commands/cat.js.map +1 -1
  8. package/dist/src/commands/chmod.d.ts +2 -2
  9. package/dist/src/commands/chmod.d.ts.map +1 -1
  10. package/dist/src/commands/chmod.js.map +1 -1
  11. package/dist/src/commands/cp.d.ts +2 -2
  12. package/dist/src/commands/cp.d.ts.map +1 -1
  13. package/dist/src/commands/cp.js.map +1 -1
  14. package/dist/src/commands/ls.d.ts +2 -2
  15. package/dist/src/commands/ls.d.ts.map +1 -1
  16. package/dist/src/commands/ls.js.map +1 -1
  17. package/dist/src/commands/mkdir.d.ts +2 -2
  18. package/dist/src/commands/mkdir.d.ts.map +1 -1
  19. package/dist/src/commands/mkdir.js.map +1 -1
  20. package/dist/src/commands/rm.d.ts +2 -2
  21. package/dist/src/commands/rm.d.ts.map +1 -1
  22. package/dist/src/commands/rm.js.map +1 -1
  23. package/dist/src/commands/stat.d.ts +2 -2
  24. package/dist/src/commands/stat.d.ts.map +1 -1
  25. package/dist/src/commands/stat.js.map +1 -1
  26. package/dist/src/commands/touch.d.ts +2 -2
  27. package/dist/src/commands/touch.d.ts.map +1 -1
  28. package/dist/src/commands/touch.js.map +1 -1
  29. package/dist/src/commands/utils/add-link.d.ts +2 -2
  30. package/dist/src/commands/utils/add-link.d.ts.map +1 -1
  31. package/dist/src/commands/utils/add-link.js.map +1 -1
  32. package/dist/src/commands/utils/cid-to-directory.d.ts +2 -2
  33. package/dist/src/commands/utils/cid-to-directory.d.ts.map +1 -1
  34. package/dist/src/commands/utils/cid-to-directory.js.map +1 -1
  35. package/dist/src/commands/utils/cid-to-pblink.d.ts +2 -2
  36. package/dist/src/commands/utils/cid-to-pblink.d.ts.map +1 -1
  37. package/dist/src/commands/utils/cid-to-pblink.js.map +1 -1
  38. package/dist/src/commands/utils/dir-sharded.d.ts +3 -3
  39. package/dist/src/commands/utils/dir-sharded.d.ts.map +1 -1
  40. package/dist/src/commands/utils/dir-sharded.js.map +1 -1
  41. package/dist/src/commands/utils/hamt-utils.d.ts +4 -3
  42. package/dist/src/commands/utils/hamt-utils.d.ts.map +1 -1
  43. package/dist/src/commands/utils/hamt-utils.js.map +1 -1
  44. package/dist/src/commands/utils/is-over-shard-threshold.d.ts +2 -2
  45. package/dist/src/commands/utils/is-over-shard-threshold.d.ts.map +1 -1
  46. package/dist/src/commands/utils/is-over-shard-threshold.js.map +1 -1
  47. package/dist/src/commands/utils/persist.d.ts +1 -3
  48. package/dist/src/commands/utils/persist.d.ts.map +1 -1
  49. package/dist/src/commands/utils/persist.js.map +1 -1
  50. package/dist/src/commands/utils/remove-link.d.ts +2 -2
  51. package/dist/src/commands/utils/remove-link.d.ts.map +1 -1
  52. package/dist/src/commands/utils/remove-link.js.map +1 -1
  53. package/dist/src/commands/utils/resolve.d.ts +3 -3
  54. package/dist/src/commands/utils/resolve.d.ts.map +1 -1
  55. package/dist/src/commands/utils/resolve.js.map +1 -1
  56. package/dist/src/index.d.ts +2 -2
  57. package/dist/src/index.d.ts.map +1 -1
  58. package/dist/src/index.js +2 -55
  59. package/dist/src/index.js.map +1 -1
  60. package/dist/src/unixfs.d.ts +26 -0
  61. package/dist/src/unixfs.d.ts.map +1 -0
  62. package/dist/src/unixfs.js +55 -0
  63. package/dist/src/unixfs.js.map +1 -0
  64. package/package.json +2 -2
  65. package/src/commands/add.ts +6 -6
  66. package/src/commands/cat.ts +2 -2
  67. package/src/commands/chmod.ts +2 -2
  68. package/src/commands/cp.ts +2 -2
  69. package/src/commands/ls.ts +2 -2
  70. package/src/commands/mkdir.ts +2 -2
  71. package/src/commands/rm.ts +2 -2
  72. package/src/commands/stat.ts +3 -3
  73. package/src/commands/touch.ts +2 -2
  74. package/src/commands/utils/add-link.ts +5 -5
  75. package/src/commands/utils/cid-to-directory.ts +2 -2
  76. package/src/commands/utils/cid-to-pblink.ts +2 -2
  77. package/src/commands/utils/dir-sharded.ts +4 -4
  78. package/src/commands/utils/hamt-utils.ts +4 -3
  79. package/src/commands/utils/is-over-shard-threshold.ts +3 -3
  80. package/src/commands/utils/persist.ts +1 -3
  81. package/src/commands/utils/remove-link.ts +5 -5
  82. package/src/commands/utils/resolve.ts +3 -3
  83. package/src/index.ts +4 -72
  84. package/src/unixfs.ts +78 -0
  85. package/dist/typedoc-urls.json +0 -54
@@ -17,9 +17,9 @@ import {
17
17
  } from './hamt-utils.js'
18
18
  import { isOverShardThreshold } from './is-over-shard-threshold.js'
19
19
  import type { Directory } from './cid-to-directory.js'
20
+ import type { GetStore, PutStore } from '../../unixfs.js'
20
21
  import type { PBNode, PBLink } from '@ipld/dag-pb/interface'
21
22
  import type { AbortOptions } from '@libp2p/interface'
22
- import type { Blockstore } from 'interface-blockstore'
23
23
  import type { ImportResult } from 'ipfs-unixfs-importer'
24
24
 
25
25
  const log = logger('helia:unixfs:components:utils:add-link')
@@ -35,7 +35,7 @@ export interface AddLinkOptions extends AbortOptions {
35
35
  cidVersion: Version
36
36
  }
37
37
 
38
- export async function addLink (parent: Directory, child: Required<PBLink>, blockstore: Blockstore, options: AddLinkOptions): Promise<AddLinkResult> {
38
+ export async function addLink (parent: Directory, child: Required<PBLink>, blockstore: GetStore & PutStore, options: AddLinkOptions): Promise<AddLinkResult> {
39
39
  if (parent.node.Data == null) {
40
40
  throw new InvalidParametersError('Invalid parent passed to addLink')
41
41
  }
@@ -63,7 +63,7 @@ export async function addLink (parent: Directory, child: Required<PBLink>, block
63
63
  return result
64
64
  }
65
65
 
66
- const convertToShardedDirectory = async (parent: Directory, blockstore: Blockstore): Promise<ImportResult> => {
66
+ const convertToShardedDirectory = async (parent: Directory, blockstore: PutStore): Promise<ImportResult> => {
67
67
  if (parent.node.Data == null) {
68
68
  throw new InvalidParametersError('Invalid parent passed to convertToShardedDirectory')
69
69
  }
@@ -85,7 +85,7 @@ const convertToShardedDirectory = async (parent: Directory, blockstore: Blocksto
85
85
  return result
86
86
  }
87
87
 
88
- const addToDirectory = async (parent: Directory, child: PBLink, blockstore: Blockstore, options: AddLinkOptions): Promise<AddLinkResult> => {
88
+ const addToDirectory = async (parent: Directory, child: PBLink, blockstore: PutStore, options: AddLinkOptions): Promise<AddLinkResult> => {
89
89
  // Remove existing link if it exists
90
90
  const parentLinks = parent.node.Links.filter((link) => {
91
91
  const matches = link.Name === child.Name
@@ -137,7 +137,7 @@ const addToDirectory = async (parent: Directory, child: PBLink, blockstore: Bloc
137
137
  }
138
138
  }
139
139
 
140
- const addToShardedDirectory = async (parent: Directory, child: Required<PBLink>, blockstore: Blockstore, options: AddLinkOptions): Promise<AddLinkResult> => {
140
+ const addToShardedDirectory = async (parent: Directory, child: Required<PBLink>, blockstore: GetStore & PutStore, options: AddLinkOptions): Promise<AddLinkResult> => {
141
141
  const { path, hash } = await recreateShardedDirectory(parent.cid, child.Name, blockstore, options)
142
142
  const finalSegment = path[path.length - 1]
143
143
 
@@ -1,7 +1,7 @@
1
1
  import { exporter, type ExporterOptions } from 'ipfs-unixfs-exporter'
2
2
  import { NotADirectoryError } from '../../errors.js'
3
+ import type { GetStore } from '../../unixfs.js'
3
4
  import type { PBNode } from '@ipld/dag-pb'
4
- import type { Blockstore } from 'interface-blockstore'
5
5
  import type { CID } from 'multiformats/cid'
6
6
 
7
7
  export interface Directory {
@@ -9,7 +9,7 @@ export interface Directory {
9
9
  node: PBNode
10
10
  }
11
11
 
12
- export async function cidToDirectory (cid: CID, blockstore: Blockstore, options: ExporterOptions = {}): Promise<Directory> {
12
+ export async function cidToDirectory (cid: CID, blockstore: GetStore, options: ExporterOptions = {}): Promise<Directory> {
13
13
  const entry = await exporter(cid, blockstore, options)
14
14
 
15
15
  if (entry.type !== 'directory') {
@@ -1,11 +1,11 @@
1
1
  import * as dagPb from '@ipld/dag-pb'
2
2
  import { exporter, type ExporterOptions } from 'ipfs-unixfs-exporter'
3
3
  import { NotUnixFSError } from '../../errors.js'
4
+ import type { GetStore } from '../../unixfs.js'
4
5
  import type { PBNode, PBLink } from '@ipld/dag-pb'
5
- import type { Blockstore } from 'interface-blockstore'
6
6
  import type { CID } from 'multiformats/cid'
7
7
 
8
- export async function cidToPBLink (cid: CID, name: string, blockstore: Blockstore, options?: ExporterOptions): Promise<Required<PBLink>> {
8
+ export async function cidToPBLink (cid: CID, name: string, blockstore: GetStore, options?: ExporterOptions): Promise<Required<PBLink>> {
9
9
  const sourceEntry = await exporter(cid, blockstore, options)
10
10
 
11
11
  if (sourceEntry.type !== 'directory' && sourceEntry.type !== 'file' && sourceEntry.type !== 'raw') {
@@ -7,7 +7,7 @@ import {
7
7
  hamtHashFn
8
8
  } from './hamt-constants.js'
9
9
  import { persist, type PersistOptions } from './persist.js'
10
- import type { Blockstore } from 'interface-blockstore'
10
+ import type { PutStore } from '../../unixfs.js'
11
11
  import type { Mtime } from 'ipfs-unixfs'
12
12
 
13
13
  interface InProgressImportResult extends ImportResult {
@@ -69,7 +69,7 @@ abstract class Dir {
69
69
  abstract put (name: string, value: InProgressImportResult | Dir): Promise<void>
70
70
  abstract get (name: string): Promise<InProgressImportResult | Dir | undefined>
71
71
  abstract eachChildSeries (): AsyncIterable<{ key: string, child: InProgressImportResult | Dir }>
72
- abstract flush (blockstore: Blockstore): AsyncGenerator<ImportResult>
72
+ abstract flush (blockstore: PutStore): AsyncGenerator<ImportResult>
73
73
  abstract estimateNodeSize (): number
74
74
  abstract childCount (): number
75
75
  }
@@ -129,7 +129,7 @@ export class DirSharded extends Dir {
129
129
  return this.nodeSize
130
130
  }
131
131
 
132
- async * flush (blockstore: Blockstore): AsyncGenerator<ImportResult> {
132
+ async * flush (blockstore: PutStore): AsyncGenerator<ImportResult> {
133
133
  for await (const entry of flush(this._bucket, blockstore, this, this.options)) {
134
134
  yield {
135
135
  ...entry,
@@ -139,7 +139,7 @@ export class DirSharded extends Dir {
139
139
  }
140
140
  }
141
141
 
142
- async function * flush (bucket: Bucket<Dir | InProgressImportResult>, blockstore: Blockstore, shardRoot: DirSharded | null, options: PersistOptions): AsyncIterable<ImportResult> {
142
+ async function * flush (bucket: Bucket<Dir | InProgressImportResult>, blockstore: PutStore, shardRoot: DirSharded | null, options: PersistOptions): AsyncIterable<ImportResult> {
143
143
  const children = bucket._children
144
144
  const links: PBLink[] = []
145
145
  let childrenSize = 0n
@@ -14,6 +14,7 @@ import {
14
14
  } from './hamt-constants.js'
15
15
  import { persist } from './persist.js'
16
16
  import type { PersistOptions } from './persist.js'
17
+ import type { GetStore, PutStore } from '../../unixfs.js'
17
18
  import type { AbortOptions } from '@libp2p/interface'
18
19
  import type { Blockstore } from 'interface-blockstore'
19
20
  import type { Mtime } from 'ipfs-unixfs'
@@ -40,7 +41,7 @@ export interface CreateShardOptions {
40
41
  cidVersion: Version
41
42
  }
42
43
 
43
- export const createShard = async (blockstore: Blockstore, contents: Array<{ name: string, size: bigint, cid: CID }>, options: CreateShardOptions): Promise<ImportResult> => {
44
+ export const createShard = async (blockstore: PutStore, contents: Array<{ name: string, size: bigint, cid: CID }>, options: CreateShardOptions): Promise<ImportResult> => {
44
45
  const shard = new DirSharded({
45
46
  root: true,
46
47
  dir: true,
@@ -75,7 +76,7 @@ export interface HAMTPath {
75
76
  node: dagPB.PBNode
76
77
  }
77
78
 
78
- export const updateShardedDirectory = async (path: HAMTPath[], blockstore: Blockstore, options: PersistOptions): Promise<{ cid: CID, node: dagPB.PBNode }> => {
79
+ export const updateShardedDirectory = async (path: HAMTPath[], blockstore: GetStore & PutStore, options: PersistOptions): Promise<{ cid: CID, node: dagPB.PBNode }> => {
79
80
  // persist any metadata on the shard root
80
81
  const shardRoot = UnixFS.unmarshal(path[0].node.Data ?? new Uint8Array(0))
81
82
 
@@ -142,7 +143,7 @@ export const updateShardedDirectory = async (path: HAMTPath[], blockstore: Block
142
143
  return { cid, node }
143
144
  }
144
145
 
145
- export const recreateShardedDirectory = async (cid: CID, fileName: string, blockstore: Blockstore, options: AbortOptions): Promise<{ path: HAMTPath[], hash: InfiniteHash }> => {
146
+ export const recreateShardedDirectory = async (cid: CID, fileName: string, blockstore: Pick<Blockstore, 'get'>, options: AbortOptions): Promise<{ path: HAMTPath[], hash: InfiniteHash }> => {
146
147
  const wrapped = wrapHash(hamtHashFn)
147
148
  const hash = wrapped(uint8ArrayFromString(fileName))
148
149
  const path: HAMTPath[] = []
@@ -1,9 +1,9 @@
1
1
  import * as dagPb from '@ipld/dag-pb'
2
2
  import { UnixFS } from 'ipfs-unixfs'
3
3
  import { CID_V0, CID_V1 } from './dir-sharded.js'
4
+ import type { GetStore } from '../../unixfs.js'
4
5
  import type { PBNode } from '@ipld/dag-pb'
5
6
  import type { AbortOptions } from '@libp2p/interface'
6
- import type { Blockstore } from 'interface-blockstore'
7
7
 
8
8
  /**
9
9
  * Estimate node size only based on DAGLink name and CID byte lengths
@@ -11,7 +11,7 @@ import type { Blockstore } from 'interface-blockstore'
11
11
  *
12
12
  * If the node is a hamt sharded directory the calculation is based on if it was a regular directory.
13
13
  */
14
- export async function isOverShardThreshold (node: PBNode, blockstore: Blockstore, threshold: number, options: AbortOptions): Promise<boolean> {
14
+ export async function isOverShardThreshold (node: PBNode, blockstore: GetStore, threshold: number, options: AbortOptions): Promise<boolean> {
15
15
  if (node.Data == null) {
16
16
  throw new Error('DagPB node had no data')
17
17
  }
@@ -43,7 +43,7 @@ function estimateNodeSize (node: PBNode): number {
43
43
  return size
44
44
  }
45
45
 
46
- async function estimateShardSize (node: PBNode, current: number, max: number, blockstore: Blockstore, options: AbortOptions): Promise<number> {
46
+ async function estimateShardSize (node: PBNode, current: number, max: number, blockstore: GetStore, options: AbortOptions): Promise<number> {
47
47
  if (current > max) {
48
48
  return max
49
49
  }
@@ -1,7 +1,7 @@
1
1
  import * as dagPb from '@ipld/dag-pb'
2
2
  import { CID } from 'multiformats/cid'
3
3
  import { sha256 } from 'multiformats/hashes/sha2'
4
- import type { Blocks } from '@helia/interface/blocks'
4
+ import type { PutStore } from '../../unixfs.js'
5
5
  import type { Version as CIDVersion } from 'multiformats/cid'
6
6
  import type { BlockCodec } from 'multiformats/codecs/interface'
7
7
 
@@ -11,8 +11,6 @@ export interface PersistOptions {
11
11
  signal?: AbortSignal
12
12
  }
13
13
 
14
- type PutStore = Pick<Blocks, 'put'>
15
-
16
14
  export const persist = async (buffer: Uint8Array, blockstore: PutStore, options: PersistOptions): Promise<CID> => {
17
15
  if (options.codec == null) {
18
16
  options.codec = dagPb
@@ -11,9 +11,9 @@ import {
11
11
  import { isOverShardThreshold } from './is-over-shard-threshold.js'
12
12
  import { persist } from './persist.js'
13
13
  import type { Directory } from './cid-to-directory.js'
14
+ import type { GetStore, PutStore } from '../../unixfs.js'
14
15
  import type { PBNode } from '@ipld/dag-pb'
15
16
  import type { AbortOptions } from '@libp2p/interface'
16
- import type { Blockstore } from 'interface-blockstore'
17
17
  import type { CID, Version } from 'multiformats/cid'
18
18
 
19
19
  const log = logger('helia:unixfs:utils:remove-link')
@@ -28,7 +28,7 @@ export interface RemoveLinkResult {
28
28
  cid: CID
29
29
  }
30
30
 
31
- export async function removeLink (parent: Directory, name: string, blockstore: Blockstore, options: RmLinkOptions): Promise<RemoveLinkResult> {
31
+ export async function removeLink (parent: Directory, name: string, blockstore: PutStore & GetStore, options: RmLinkOptions): Promise<RemoveLinkResult> {
32
32
  if (parent.node.Data == null) {
33
33
  throw new InvalidPBNodeError('Parent node had no data')
34
34
  }
@@ -54,7 +54,7 @@ export async function removeLink (parent: Directory, name: string, blockstore: B
54
54
  return removeFromDirectory(parent, name, blockstore, options)
55
55
  }
56
56
 
57
- const removeFromDirectory = async (parent: Directory, name: string, blockstore: Blockstore, options: AbortOptions): Promise<RemoveLinkResult> => {
57
+ const removeFromDirectory = async (parent: Directory, name: string, blockstore: PutStore & GetStore, options: AbortOptions): Promise<RemoveLinkResult> => {
58
58
  // Remove existing link if it exists
59
59
  parent.node.Links = parent.node.Links.filter((link) => {
60
60
  return link.Name !== name
@@ -74,7 +74,7 @@ const removeFromDirectory = async (parent: Directory, name: string, blockstore:
74
74
  }
75
75
  }
76
76
 
77
- const removeFromShardedDirectory = async (parent: Directory, name: string, blockstore: Blockstore, options: UpdateHamtDirectoryOptions): Promise<{ cid: CID, node: PBNode }> => {
77
+ const removeFromShardedDirectory = async (parent: Directory, name: string, blockstore: PutStore & GetStore, options: UpdateHamtDirectoryOptions): Promise<{ cid: CID, node: PBNode }> => {
78
78
  const { path } = await recreateShardedDirectory(parent.cid, name, blockstore, options)
79
79
  const finalSegment = path[path.length - 1]
80
80
 
@@ -131,7 +131,7 @@ const removeFromShardedDirectory = async (parent: Directory, name: string, block
131
131
  return updateShardedDirectory(path, blockstore, options)
132
132
  }
133
133
 
134
- const convertToFlatDirectory = async (parent: Directory, blockstore: Blockstore, options: RmLinkOptions): Promise<RemoveLinkResult> => {
134
+ const convertToFlatDirectory = async (parent: Directory, blockstore: PutStore & GetStore, options: RmLinkOptions): Promise<RemoveLinkResult> => {
135
135
  if (parent.node.Data == null) {
136
136
  throw new InvalidParametersError('Invalid parent passed to convertToFlatDirectory')
137
137
  }
@@ -5,8 +5,8 @@ import { DoesNotExistError } from '../../errors.js'
5
5
  import { addLink } from './add-link.js'
6
6
  import { cidToDirectory } from './cid-to-directory.js'
7
7
  import { cidToPBLink } from './cid-to-pblink.js'
8
+ import type { GetStore, PutStore } from '../../unixfs.js'
8
9
  import type { AbortOptions } from '@libp2p/interface'
9
- import type { Blockstore } from 'interface-blockstore'
10
10
  import type { CID } from 'multiformats/cid'
11
11
 
12
12
  const log = logger('helia:unixfs:components:utils:resolve')
@@ -33,7 +33,7 @@ export interface ResolveResult {
33
33
  segments?: Segment[]
34
34
  }
35
35
 
36
- export async function resolve (cid: CID, path: string | undefined, blockstore: Blockstore, options: AbortOptions): Promise<ResolveResult> {
36
+ export async function resolve (cid: CID, path: string | undefined, blockstore: GetStore, options: AbortOptions): Promise<ResolveResult> {
37
37
  if (path == null || path === '') {
38
38
  return { cid }
39
39
  }
@@ -62,7 +62,7 @@ export interface UpdatePathCidsOptions extends AbortOptions {
62
62
  * Where we have descended into a DAG to update a child node, ascend up the DAG creating
63
63
  * new hashes and blocks for the changed content
64
64
  */
65
- export async function updatePathCids (cid: CID, result: ResolveResult, blockstore: Blockstore, options: UpdatePathCidsOptions): Promise<CID> {
65
+ export async function updatePathCids (cid: CID, result: ResolveResult, blockstore: PutStore & GetStore, options: UpdatePathCidsOptions): Promise<CID> {
66
66
  if (result.segments == null || result.segments.length === 0) {
67
67
  return cid
68
68
  }
package/src/index.ts CHANGED
@@ -43,15 +43,7 @@
43
43
  * ```
44
44
  */
45
45
 
46
- import { addAll, addBytes, addByteStream, addDirectory, addFile } from './commands/add.js'
47
- import { cat } from './commands/cat.js'
48
- import { chmod } from './commands/chmod.js'
49
- import { cp } from './commands/cp.js'
50
- import { ls } from './commands/ls.js'
51
- import { mkdir } from './commands/mkdir.js'
52
- import { rm } from './commands/rm.js'
53
- import { stat } from './commands/stat.js'
54
- import { touch } from './commands/touch.js'
46
+ import { UnixFS as UnixFSClass } from './unixfs.js'
55
47
  import type { GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks'
56
48
  import type { AbortOptions } from '@libp2p/interface'
57
49
  import type { Blockstore } from 'interface-blockstore'
@@ -62,7 +54,7 @@ import type { CID, Version } from 'multiformats/cid'
62
54
  import type { ProgressOptions } from 'progress-events'
63
55
 
64
56
  export interface UnixFSComponents {
65
- blockstore: Blockstore
57
+ blockstore: Pick<Blockstore, 'get' | 'put' | 'has'>
66
58
  }
67
59
 
68
60
  export type AddEvents = PutBlockProgressEvents
@@ -554,71 +546,11 @@ export interface UnixFS {
554
546
  touch(cid: CID, options?: Partial<TouchOptions>): Promise<CID>
555
547
  }
556
548
 
557
- class DefaultUnixFS implements UnixFS {
558
- private readonly components: UnixFSComponents
559
-
560
- constructor (components: UnixFSComponents) {
561
- this.components = components
562
- }
563
-
564
- async * addAll (source: ImportCandidateStream, options: Partial<AddOptions> = {}): AsyncIterable<ImportResult> {
565
- yield * addAll(source, this.components.blockstore, options)
566
- }
567
-
568
- async addBytes (bytes: Uint8Array, options: Partial<AddOptions> = {}): Promise<CID> {
569
- return addBytes(bytes, this.components.blockstore, options)
570
- }
571
-
572
- async addByteStream (bytes: ByteStream, options: Partial<AddOptions> = {}): Promise<CID> {
573
- return addByteStream(bytes, this.components.blockstore, options)
574
- }
575
-
576
- async addFile (file: FileCandidate, options: Partial<AddOptions> = {}): Promise<CID> {
577
- return addFile(file, this.components.blockstore, options)
578
- }
579
-
580
- async addDirectory (dir: Partial<DirectoryCandidate> = {}, options: Partial<AddOptions> = {}): Promise<CID> {
581
- return addDirectory(dir, this.components.blockstore, options)
582
- }
583
-
584
- async * cat (cid: CID, options: Partial<CatOptions> = {}): AsyncIterable<Uint8Array> {
585
- yield * cat(cid, this.components.blockstore, options)
586
- }
587
-
588
- async chmod (cid: CID, mode: number, options: Partial<ChmodOptions> = {}): Promise<CID> {
589
- return chmod(cid, mode, this.components.blockstore, options)
590
- }
591
-
592
- async cp (source: CID, target: CID, name: string, options: Partial<CpOptions> = {}): Promise<CID> {
593
- return cp(source, target, name, this.components.blockstore, options)
594
- }
595
-
596
- async * ls (cid: CID, options: Partial<LsOptions> = {}): AsyncIterable<UnixFSEntry> {
597
- yield * ls(cid, this.components.blockstore, options)
598
- }
599
-
600
- async mkdir (cid: CID, dirname: string, options: Partial<MkdirOptions> = {}): Promise<CID> {
601
- return mkdir(cid, dirname, this.components.blockstore, options)
602
- }
603
-
604
- async rm (cid: CID, path: string, options: Partial<RmOptions> = {}): Promise<CID> {
605
- return rm(cid, path, this.components.blockstore, options)
606
- }
607
-
608
- async stat (cid: CID, options: Partial<StatOptions> = {}): Promise<UnixFSStats> {
609
- return stat(cid, this.components.blockstore, options)
610
- }
611
-
612
- async touch (cid: CID, options: Partial<TouchOptions> = {}): Promise<CID> {
613
- return touch(cid, this.components.blockstore, options)
614
- }
615
- }
616
-
617
549
  /**
618
550
  * Create a {@link UnixFS} instance for use with {@link https://github.com/ipfs/helia Helia}
619
551
  */
620
- export function unixfs (helia: { blockstore: Blockstore }): UnixFS {
621
- return new DefaultUnixFS(helia)
552
+ export function unixfs (helia: { blockstore: Pick<Blockstore, 'get' | 'put' | 'has'> }): UnixFS {
553
+ return new UnixFSClass(helia)
622
554
  }
623
555
 
624
556
  export { globSource } from './utils/glob-source.js'
package/src/unixfs.ts ADDED
@@ -0,0 +1,78 @@
1
+ import { addAll, addBytes, addByteStream, addDirectory, addFile } from './commands/add.js'
2
+ import { cat } from './commands/cat.js'
3
+ import { chmod } from './commands/chmod.js'
4
+ import { cp } from './commands/cp.js'
5
+ import { ls } from './commands/ls.js'
6
+ import { mkdir } from './commands/mkdir.js'
7
+ import { rm } from './commands/rm.js'
8
+ import { stat } from './commands/stat.js'
9
+ import { touch } from './commands/touch.js'
10
+ import type { AddOptions, CatOptions, ChmodOptions, CpOptions, LsOptions, MkdirOptions, RmOptions, StatOptions, TouchOptions, UnixFSComponents, UnixFS as UnixFSInterface, UnixFSStats } from './index.js'
11
+ import type { Blockstore } from 'interface-blockstore'
12
+ import type { UnixFSEntry } from 'ipfs-unixfs-exporter'
13
+ import type { ByteStream, DirectoryCandidate, FileCandidate, ImportCandidateStream, ImportResult } from 'ipfs-unixfs-importer'
14
+ import type { CID } from 'multiformats/cid'
15
+
16
+ export type PutStore = Pick<Blockstore, 'put'>
17
+ export type GetStore = Pick<Blockstore, 'get'>
18
+ export type HasStore = Pick<Blockstore, 'has'>
19
+
20
+ export class UnixFS implements UnixFSInterface {
21
+ private readonly components: UnixFSComponents
22
+
23
+ constructor (components: UnixFSComponents) {
24
+ this.components = components
25
+ }
26
+
27
+ async * addAll (source: ImportCandidateStream, options: Partial<AddOptions> = {}): AsyncIterable<ImportResult> {
28
+ yield * addAll(source, this.components.blockstore, options)
29
+ }
30
+
31
+ async addBytes (bytes: Uint8Array, options: Partial<AddOptions> = {}): Promise<CID> {
32
+ return addBytes(bytes, this.components.blockstore, options)
33
+ }
34
+
35
+ async addByteStream (bytes: ByteStream, options: Partial<AddOptions> = {}): Promise<CID> {
36
+ return addByteStream(bytes, this.components.blockstore, options)
37
+ }
38
+
39
+ async addFile (file: FileCandidate, options: Partial<AddOptions> = {}): Promise<CID> {
40
+ return addFile(file, this.components.blockstore, options)
41
+ }
42
+
43
+ async addDirectory (dir: Partial<DirectoryCandidate> = {}, options: Partial<AddOptions> = {}): Promise<CID> {
44
+ return addDirectory(dir, this.components.blockstore, options)
45
+ }
46
+
47
+ async * cat (cid: CID, options: Partial<CatOptions> = {}): AsyncIterable<Uint8Array> {
48
+ yield * cat(cid, this.components.blockstore, options)
49
+ }
50
+
51
+ async chmod (cid: CID, mode: number, options: Partial<ChmodOptions> = {}): Promise<CID> {
52
+ return chmod(cid, mode, this.components.blockstore, options)
53
+ }
54
+
55
+ async cp (source: CID, target: CID, name: string, options: Partial<CpOptions> = {}): Promise<CID> {
56
+ return cp(source, target, name, this.components.blockstore, options)
57
+ }
58
+
59
+ async * ls (cid: CID, options: Partial<LsOptions> = {}): AsyncIterable<UnixFSEntry> {
60
+ yield * ls(cid, this.components.blockstore, options)
61
+ }
62
+
63
+ async mkdir (cid: CID, dirname: string, options: Partial<MkdirOptions> = {}): Promise<CID> {
64
+ return mkdir(cid, dirname, this.components.blockstore, options)
65
+ }
66
+
67
+ async rm (cid: CID, path: string, options: Partial<RmOptions> = {}): Promise<CID> {
68
+ return rm(cid, path, this.components.blockstore, options)
69
+ }
70
+
71
+ async stat (cid: CID, options: Partial<StatOptions> = {}): Promise<UnixFSStats> {
72
+ return stat(cid, this.components.blockstore, options)
73
+ }
74
+
75
+ async touch (cid: CID, options: Partial<TouchOptions> = {}): Promise<CID> {
76
+ return touch(cid, this.components.blockstore, options)
77
+ }
78
+ }
@@ -1,54 +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
- "LsOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.LsOptions.html",
31
- ".:LsOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.LsOptions.html",
32
- "MkdirOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.MkdirOptions.html",
33
- ".:MkdirOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.MkdirOptions.html",
34
- "RmOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.RmOptions.html",
35
- ".:RmOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.RmOptions.html",
36
- "StatOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.StatOptions.html",
37
- ".:StatOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.StatOptions.html",
38
- "TouchOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.TouchOptions.html",
39
- ".:TouchOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.TouchOptions.html",
40
- "UnixFS": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFS.html",
41
- ".:UnixFS": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFS.html",
42
- "UnixFSComponents": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFSComponents.html",
43
- ".:UnixFSComponents": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFSComponents.html",
44
- "UnixFSStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFSStats.html",
45
- ".:UnixFSStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFSStats.html",
46
- "AddEvents": "https://ipfs.github.io/helia/types/_helia_unixfs.index.AddEvents.html",
47
- ".:AddEvents": "https://ipfs.github.io/helia/types/_helia_unixfs.index.AddEvents.html",
48
- "GetEvents": "https://ipfs.github.io/helia/types/_helia_unixfs.index.GetEvents.html",
49
- ".:GetEvents": "https://ipfs.github.io/helia/types/_helia_unixfs.index.GetEvents.html",
50
- "globSource": "https://ipfs.github.io/helia/functions/_helia_unixfs.index.globSource.html",
51
- "unixfs": "https://ipfs.github.io/helia/functions/_helia_unixfs.index.unixfs-1.html",
52
- ".:unixfs": "https://ipfs.github.io/helia/functions/_helia_unixfs.index.unixfs-1.html",
53
- "urlSource": "https://ipfs.github.io/helia/functions/_helia_unixfs.index.urlSource.html"
54
- }