@helia/unixfs 3.0.4 → 3.0.5
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 +6 -6
- package/dist/src/commands/add.d.ts.map +1 -1
- package/dist/src/commands/add.js.map +1 -1
- package/dist/src/commands/cat.d.ts +2 -2
- package/dist/src/commands/cat.d.ts.map +1 -1
- package/dist/src/commands/cat.js.map +1 -1
- package/dist/src/commands/chmod.d.ts +2 -2
- package/dist/src/commands/chmod.d.ts.map +1 -1
- package/dist/src/commands/chmod.js.map +1 -1
- package/dist/src/commands/cp.d.ts +2 -2
- package/dist/src/commands/cp.d.ts.map +1 -1
- package/dist/src/commands/cp.js.map +1 -1
- package/dist/src/commands/ls.d.ts +2 -2
- package/dist/src/commands/ls.d.ts.map +1 -1
- package/dist/src/commands/ls.js.map +1 -1
- package/dist/src/commands/mkdir.d.ts +2 -2
- package/dist/src/commands/mkdir.d.ts.map +1 -1
- package/dist/src/commands/mkdir.js.map +1 -1
- package/dist/src/commands/rm.d.ts +2 -2
- package/dist/src/commands/rm.d.ts.map +1 -1
- package/dist/src/commands/rm.js.map +1 -1
- package/dist/src/commands/stat.d.ts +2 -2
- package/dist/src/commands/stat.d.ts.map +1 -1
- package/dist/src/commands/stat.js.map +1 -1
- package/dist/src/commands/touch.d.ts +2 -2
- package/dist/src/commands/touch.d.ts.map +1 -1
- package/dist/src/commands/touch.js.map +1 -1
- package/dist/src/commands/utils/add-link.d.ts +2 -2
- package/dist/src/commands/utils/add-link.d.ts.map +1 -1
- package/dist/src/commands/utils/add-link.js.map +1 -1
- package/dist/src/commands/utils/cid-to-directory.d.ts +2 -2
- package/dist/src/commands/utils/cid-to-directory.d.ts.map +1 -1
- package/dist/src/commands/utils/cid-to-directory.js.map +1 -1
- package/dist/src/commands/utils/cid-to-pblink.d.ts +2 -2
- package/dist/src/commands/utils/cid-to-pblink.d.ts.map +1 -1
- package/dist/src/commands/utils/cid-to-pblink.js.map +1 -1
- package/dist/src/commands/utils/dir-sharded.d.ts +3 -3
- package/dist/src/commands/utils/dir-sharded.d.ts.map +1 -1
- package/dist/src/commands/utils/dir-sharded.js.map +1 -1
- package/dist/src/commands/utils/hamt-utils.d.ts +4 -3
- package/dist/src/commands/utils/hamt-utils.d.ts.map +1 -1
- package/dist/src/commands/utils/hamt-utils.js.map +1 -1
- package/dist/src/commands/utils/is-over-shard-threshold.d.ts +2 -2
- package/dist/src/commands/utils/is-over-shard-threshold.d.ts.map +1 -1
- package/dist/src/commands/utils/is-over-shard-threshold.js.map +1 -1
- package/dist/src/commands/utils/persist.d.ts +1 -3
- package/dist/src/commands/utils/persist.d.ts.map +1 -1
- package/dist/src/commands/utils/persist.js.map +1 -1
- package/dist/src/commands/utils/remove-link.d.ts +2 -2
- package/dist/src/commands/utils/remove-link.d.ts.map +1 -1
- package/dist/src/commands/utils/remove-link.js.map +1 -1
- package/dist/src/commands/utils/resolve.d.ts +3 -3
- package/dist/src/commands/utils/resolve.d.ts.map +1 -1
- package/dist/src/commands/utils/resolve.js.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +2 -55
- package/dist/src/index.js.map +1 -1
- package/dist/src/unixfs.d.ts +26 -0
- package/dist/src/unixfs.d.ts.map +1 -0
- package/dist/src/unixfs.js +55 -0
- package/dist/src/unixfs.js.map +1 -0
- package/package.json +1 -1
- package/src/commands/add.ts +6 -6
- package/src/commands/cat.ts +2 -2
- package/src/commands/chmod.ts +2 -2
- package/src/commands/cp.ts +2 -2
- package/src/commands/ls.ts +2 -2
- package/src/commands/mkdir.ts +2 -2
- package/src/commands/rm.ts +2 -2
- package/src/commands/stat.ts +3 -3
- package/src/commands/touch.ts +2 -2
- package/src/commands/utils/add-link.ts +5 -5
- package/src/commands/utils/cid-to-directory.ts +2 -2
- package/src/commands/utils/cid-to-pblink.ts +2 -2
- package/src/commands/utils/dir-sharded.ts +4 -4
- package/src/commands/utils/hamt-utils.ts +4 -3
- package/src/commands/utils/is-over-shard-threshold.ts +3 -3
- package/src/commands/utils/persist.ts +1 -3
- package/src/commands/utils/remove-link.ts +5 -5
- package/src/commands/utils/resolve.ts +3 -3
- package/src/index.ts +4 -72
- package/src/unixfs.ts +78 -0
|
@@ -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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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 {
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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 {
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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 {
|
|
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
|
|
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
|
+
}
|