@helia/unixfs 1.0.4 → 1.1.0
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/README.md +1 -1
- 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 +35 -5
- 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 +4 -2
- 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 -4
- 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 +4 -2
- package/dist/src/commands/utils/persist.d.ts.map +1 -1
- package/dist/src/commands/utils/persist.js +1 -0
- 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 +22 -18
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/typedoc-urls.json +2 -0
- package/package.json +12 -7
- package/src/commands/add.ts +42 -11
- package/src/commands/cat.ts +2 -2
- package/src/commands/chmod.ts +4 -3
- 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 -4
- package/src/commands/utils/is-over-shard-threshold.ts +3 -3
- package/src/commands/utils/persist.ts +5 -2
- package/src/commands/utils/remove-link.ts +5 -5
- package/src/commands/utils/resolve.ts +3 -3
- package/src/index.ts +31 -23
package/src/commands/chmod.ts
CHANGED
|
@@ -10,7 +10,7 @@ import * as dagPB from '@ipld/dag-pb'
|
|
|
10
10
|
import type { PBNode, PBLink } from '@ipld/dag-pb'
|
|
11
11
|
import { importer } from 'ipfs-unixfs-importer'
|
|
12
12
|
import { persist } from './utils/persist.js'
|
|
13
|
-
import type {
|
|
13
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
14
14
|
import last from 'it-last'
|
|
15
15
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
16
16
|
import { resolve, updatePathCids } from './utils/resolve.js'
|
|
@@ -25,7 +25,7 @@ const defaultOptions: ChmodOptions = {
|
|
|
25
25
|
shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export async function chmod (cid: CID, mode: number, blockstore:
|
|
28
|
+
export async function chmod (cid: CID, mode: number, blockstore: Blocks, options: Partial<ChmodOptions> = {}): Promise<CID> {
|
|
29
29
|
const opts: ChmodOptions = mergeOptions(defaultOptions, options)
|
|
30
30
|
const resolved = await resolve(cid, opts.path, blockstore, options)
|
|
31
31
|
|
|
@@ -36,7 +36,7 @@ export async function chmod (cid: CID, mode: number, blockstore: Blockstore, opt
|
|
|
36
36
|
// but do not reimport files, only manipulate dag-pb nodes
|
|
37
37
|
const root = await pipe(
|
|
38
38
|
async function * () {
|
|
39
|
-
for await (const entry of recursive(resolved.cid, blockstore)) {
|
|
39
|
+
for await (const entry of recursive(resolved.cid, blockstore, options)) {
|
|
40
40
|
let metadata: UnixFS
|
|
41
41
|
let links: PBLink[] = []
|
|
42
42
|
|
|
@@ -63,6 +63,7 @@ export async function chmod (cid: CID, mode: number, blockstore: Blockstore, opt
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
+
// @ts-expect-error cannot combine progress types
|
|
66
67
|
(source) => importer(source, blockstore, {
|
|
67
68
|
...opts,
|
|
68
69
|
dagBuilder: async function * (source, block) {
|
package/src/commands/cp.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
2
2
|
import type { CID } from 'multiformats/cid'
|
|
3
3
|
import type { CpOptions } from '../index.js'
|
|
4
4
|
import mergeOpts from 'merge-options'
|
|
@@ -17,7 +17,7 @@ const defaultOptions: CpOptions = {
|
|
|
17
17
|
shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export async function cp (source: CID, target: CID, name: string, blockstore:
|
|
20
|
+
export async function cp (source: CID, target: CID, name: string, blockstore: Blocks, options: Partial<CpOptions> = {}): Promise<CID> {
|
|
21
21
|
const opts: CpOptions = mergeOptions(defaultOptions, options)
|
|
22
22
|
|
|
23
23
|
if (name.includes('/')) {
|
package/src/commands/ls.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { CID } from 'multiformats/cid'
|
|
|
3
3
|
import type { LsOptions } from '../index.js'
|
|
4
4
|
import { resolve } from './utils/resolve.js'
|
|
5
5
|
import mergeOpts from 'merge-options'
|
|
6
|
-
import type {
|
|
6
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
7
7
|
import { NoContentError, NotADirectoryError } from './utils/errors.js'
|
|
8
8
|
|
|
9
9
|
const mergeOptions = mergeOpts.bind({ ignoreUndefined: true })
|
|
@@ -12,7 +12,7 @@ const defaultOptions: LsOptions = {
|
|
|
12
12
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export async function * ls (cid: CID, blockstore:
|
|
15
|
+
export async function * ls (cid: CID, blockstore: Blocks, options: Partial<LsOptions> = {}): AsyncIterable<UnixFSEntry> {
|
|
16
16
|
const opts: LsOptions = mergeOptions(defaultOptions, options)
|
|
17
17
|
const resolved = await resolve(cid, opts.path, blockstore, opts)
|
|
18
18
|
const result = await exporter(resolved.cid, blockstore)
|
package/src/commands/mkdir.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { logger } from '@libp2p/logger'
|
|
|
4
4
|
import type { MkdirOptions } from '../index.js'
|
|
5
5
|
import * as dagPB from '@ipld/dag-pb'
|
|
6
6
|
import { addLink } from './utils/add-link.js'
|
|
7
|
-
import type {
|
|
7
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
8
8
|
import { UnixFS } from 'ipfs-unixfs'
|
|
9
9
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
10
10
|
import { exporter } from 'ipfs-unixfs-exporter'
|
|
@@ -22,7 +22,7 @@ const defaultOptions: MkdirOptions = {
|
|
|
22
22
|
shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export async function mkdir (parentCid: CID, dirname: string, blockstore:
|
|
25
|
+
export async function mkdir (parentCid: CID, dirname: string, blockstore: Blocks, options: Partial<MkdirOptions> = {}): Promise<CID> {
|
|
26
26
|
const opts: MkdirOptions = mergeOptions(defaultOptions, options)
|
|
27
27
|
|
|
28
28
|
if (dirname.includes('/')) {
|
package/src/commands/rm.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
2
2
|
import type { CID } from 'multiformats/cid'
|
|
3
3
|
import type { RmOptions } from '../index.js'
|
|
4
4
|
import mergeOpts from 'merge-options'
|
|
@@ -15,7 +15,7 @@ const defaultOptions: RmOptions = {
|
|
|
15
15
|
shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export async function rm (target: CID, name: string, blockstore:
|
|
18
|
+
export async function rm (target: CID, name: string, blockstore: Blocks, options: Partial<RmOptions> = {}): Promise<CID> {
|
|
19
19
|
const opts: RmOptions = mergeOptions(defaultOptions, options)
|
|
20
20
|
|
|
21
21
|
if (name.includes('/')) {
|
package/src/commands/stat.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type { AbortOptions } from '@libp2p/interfaces'
|
|
|
10
10
|
import type { Mtime } from 'ipfs-unixfs'
|
|
11
11
|
import { resolve } from './utils/resolve.js'
|
|
12
12
|
import * as raw from 'multiformats/codecs/raw'
|
|
13
|
-
import type {
|
|
13
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
14
14
|
|
|
15
15
|
const mergeOptions = mergeOpts.bind({ ignoreUndefined: true })
|
|
16
16
|
const log = logger('helia:unixfs:stat')
|
|
@@ -19,7 +19,7 @@ const defaultOptions: StatOptions = {
|
|
|
19
19
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export async function stat (cid: CID, blockstore:
|
|
22
|
+
export async function stat (cid: CID, blockstore: Blocks, options: Partial<StatOptions> = {}): Promise<UnixFSStats> {
|
|
23
23
|
const opts: StatOptions = mergeOptions(defaultOptions, options)
|
|
24
24
|
const resolved = await resolve(cid, options.path, blockstore, opts)
|
|
25
25
|
|
|
@@ -93,7 +93,7 @@ interface InspectDagResults {
|
|
|
93
93
|
blocks: number
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
async function inspectDag (cid: CID, blockstore:
|
|
96
|
+
async function inspectDag (cid: CID, blockstore: Blocks, options: AbortOptions): Promise<InspectDagResults> {
|
|
97
97
|
const results = {
|
|
98
98
|
localFileSize: 0,
|
|
99
99
|
localDagSize: 0,
|
package/src/commands/touch.ts
CHANGED
|
@@ -10,7 +10,7 @@ import * as dagPB from '@ipld/dag-pb'
|
|
|
10
10
|
import type { PBNode, PBLink } from '@ipld/dag-pb'
|
|
11
11
|
import { importer } from 'ipfs-unixfs-importer'
|
|
12
12
|
import { persist } from './utils/persist.js'
|
|
13
|
-
import type {
|
|
13
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
14
14
|
import last from 'it-last'
|
|
15
15
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
16
16
|
import { resolve, updatePathCids } from './utils/resolve.js'
|
|
@@ -25,7 +25,7 @@ const defaultOptions: TouchOptions = {
|
|
|
25
25
|
shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export async function touch (cid: CID, blockstore:
|
|
28
|
+
export async function touch (cid: CID, blockstore: Blocks, options: Partial<TouchOptions> = {}): Promise<CID> {
|
|
29
29
|
const opts: TouchOptions = mergeOptions(defaultOptions, options)
|
|
30
30
|
const resolved = await resolve(cid, opts.path, blockstore, opts)
|
|
31
31
|
const mtime = opts.mtime ?? {
|
|
@@ -14,7 +14,7 @@ import { AlreadyExistsError, InvalidParametersError, InvalidPBNodeError } from '
|
|
|
14
14
|
import type { ImportResult } from 'ipfs-unixfs-importer'
|
|
15
15
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
16
16
|
import type { Directory } from './cid-to-directory.js'
|
|
17
|
-
import type {
|
|
17
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
18
18
|
import { isOverShardThreshold } from './is-over-shard-threshold.js'
|
|
19
19
|
import { hamtBucketBits, hamtHashFn } from './hamt-constants.js'
|
|
20
20
|
// @ts-expect-error no types
|
|
@@ -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: Blocks, 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: Blocks): 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: Blocks, 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: Blocks, 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, ExporterOptions } from 'ipfs-unixfs-exporter'
|
|
2
2
|
import type { CID } from 'multiformats/cid'
|
|
3
3
|
import type { PBNode } from '@ipld/dag-pb'
|
|
4
|
-
import type {
|
|
4
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
5
5
|
import { NotADirectoryError } from './errors.js'
|
|
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: Blocks, options: ExporterOptions = {}): Promise<Directory> {
|
|
13
13
|
const entry = await exporter(cid, blockstore, options)
|
|
14
14
|
|
|
15
15
|
if (entry.type !== 'directory') {
|
|
@@ -3,9 +3,9 @@ import type { CID } from 'multiformats/cid'
|
|
|
3
3
|
import { NotUnixFSError } from './errors.js'
|
|
4
4
|
import * as dagPb from '@ipld/dag-pb'
|
|
5
5
|
import type { PBNode, PBLink } from '@ipld/dag-pb'
|
|
6
|
-
import type {
|
|
6
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
7
7
|
|
|
8
|
-
export async function cidToPBLink (cid: CID, name: string, blockstore:
|
|
8
|
+
export async function cidToPBLink (cid: CID, name: string, blockstore: Blocks, 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') {
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from './hamt-constants.js'
|
|
9
9
|
import { CID } from 'multiformats/cid'
|
|
10
10
|
import type { Mtime } from 'ipfs-unixfs'
|
|
11
|
-
import type {
|
|
11
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
12
12
|
|
|
13
13
|
interface InProgressImportResult extends ImportResult {
|
|
14
14
|
single?: boolean
|
|
@@ -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: Blocks): 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: Blocks): 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: Blocks, shardRoot: DirSharded | null, options: PersistOptions): AsyncIterable<ImportResult> {
|
|
143
143
|
const children = bucket._children
|
|
144
144
|
const links: PBLink[] = []
|
|
145
145
|
let childrenSize = 0n
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
hamtHashFn,
|
|
10
10
|
hamtBucketBits
|
|
11
11
|
} from './hamt-constants.js'
|
|
12
|
-
import type {
|
|
12
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
13
13
|
import type { Mtime } from 'ipfs-unixfs'
|
|
14
14
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
15
15
|
import type { ImportResult } from 'ipfs-unixfs-importer'
|
|
@@ -40,7 +40,7 @@ export interface CreateShardOptions {
|
|
|
40
40
|
cidVersion: Version
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
export const createShard = async (blockstore:
|
|
43
|
+
export const createShard = async (blockstore: Blocks, contents: Array<{ name: string, size: bigint, cid: CID }>, options: CreateShardOptions): Promise<ImportResult> => {
|
|
44
44
|
const shard = new DirSharded({
|
|
45
45
|
root: true,
|
|
46
46
|
dir: true,
|
|
@@ -75,7 +75,7 @@ export interface HAMTPath {
|
|
|
75
75
|
node: dagPB.PBNode
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
export const updateShardedDirectory = async (path: HAMTPath[], blockstore:
|
|
78
|
+
export const updateShardedDirectory = async (path: HAMTPath[], blockstore: Blocks, options: PersistOptions): Promise<{ cid: CID, node: dagPB.PBNode }> => {
|
|
79
79
|
// persist any metadata on the shard root
|
|
80
80
|
const shardRoot = UnixFS.unmarshal(path[0].node.Data ?? new Uint8Array(0))
|
|
81
81
|
|
|
@@ -142,7 +142,7 @@ export const updateShardedDirectory = async (path: HAMTPath[], blockstore: Block
|
|
|
142
142
|
return { cid, node }
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
export const recreateShardedDirectory = async (cid: CID, fileName: string, blockstore:
|
|
145
|
+
export const recreateShardedDirectory = async (cid: CID, fileName: string, blockstore: Blocks, options: AbortOptions): Promise<{ path: HAMTPath[], hash: InfiniteHash }> => {
|
|
146
146
|
const wrapped = wrapHash(hamtHashFn)
|
|
147
147
|
const hash = wrapped(uint8ArrayFromString(fileName))
|
|
148
148
|
const path: HAMTPath[] = []
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PBNode } from '@ipld/dag-pb'
|
|
2
|
-
import type {
|
|
2
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
3
3
|
import { UnixFS } from 'ipfs-unixfs'
|
|
4
4
|
import * as dagPb from '@ipld/dag-pb'
|
|
5
5
|
import { CID_V0, CID_V1 } from './dir-sharded.js'
|
|
@@ -10,7 +10,7 @@ import { CID_V0, CID_V1 } from './dir-sharded.js'
|
|
|
10
10
|
*
|
|
11
11
|
* If the node is a hamt sharded directory the calculation is based on if it was a regular directory.
|
|
12
12
|
*/
|
|
13
|
-
export async function isOverShardThreshold (node: PBNode, blockstore:
|
|
13
|
+
export async function isOverShardThreshold (node: PBNode, blockstore: Blocks, threshold: number): Promise<boolean> {
|
|
14
14
|
if (node.Data == null) {
|
|
15
15
|
throw new Error('DagPB node had no data')
|
|
16
16
|
}
|
|
@@ -42,7 +42,7 @@ function estimateNodeSize (node: PBNode): number {
|
|
|
42
42
|
return size
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
async function estimateShardSize (node: PBNode, current: number, max: number, blockstore:
|
|
45
|
+
async function estimateShardSize (node: PBNode, current: number, max: number, blockstore: Blocks): Promise<number> {
|
|
46
46
|
if (current > max) {
|
|
47
47
|
return max
|
|
48
48
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { CID } from 'multiformats/cid'
|
|
2
2
|
import * as dagPb from '@ipld/dag-pb'
|
|
3
3
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
4
|
-
import type {
|
|
4
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
5
5
|
import type { BlockCodec } from 'multiformats/codecs/interface'
|
|
6
6
|
import type { Version as CIDVersion } from 'multiformats/cid'
|
|
7
7
|
|
|
@@ -11,7 +11,9 @@ export interface PersistOptions {
|
|
|
11
11
|
signal?: AbortSignal
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
type PutStore = Pick<Blocks, 'put'>
|
|
15
|
+
|
|
16
|
+
export const persist = async (buffer: Uint8Array, blockstore: PutStore, options: PersistOptions): Promise<CID> => {
|
|
15
17
|
if (options.codec == null) {
|
|
16
18
|
options.codec = dagPb
|
|
17
19
|
}
|
|
@@ -20,6 +22,7 @@ export const persist = async (buffer: Uint8Array, blockstore: Blockstore, option
|
|
|
20
22
|
const cid = CID.create(options.cidVersion, options.codec.code, multihash)
|
|
21
23
|
|
|
22
24
|
await blockstore.put(cid, buffer, {
|
|
25
|
+
...options,
|
|
23
26
|
signal: options.signal
|
|
24
27
|
})
|
|
25
28
|
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
updateShardedDirectory
|
|
10
10
|
} from './hamt-utils.js'
|
|
11
11
|
import type { PBNode } from '@ipld/dag-pb'
|
|
12
|
-
import type {
|
|
12
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
13
13
|
import type { Directory } from './cid-to-directory.js'
|
|
14
14
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
15
15
|
import { InvalidParametersError, InvalidPBNodeError } from './errors.js'
|
|
@@ -29,7 +29,7 @@ export interface RemoveLinkResult {
|
|
|
29
29
|
cid: CID
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export async function removeLink (parent: Directory, name: string, blockstore:
|
|
32
|
+
export async function removeLink (parent: Directory, name: string, blockstore: Blocks, options: RmLinkOptions): Promise<RemoveLinkResult> {
|
|
33
33
|
if (parent.node.Data == null) {
|
|
34
34
|
throw new InvalidPBNodeError('Parent node had no data')
|
|
35
35
|
}
|
|
@@ -55,7 +55,7 @@ export async function removeLink (parent: Directory, name: string, blockstore: B
|
|
|
55
55
|
return await removeFromDirectory(parent, name, blockstore, options)
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
const removeFromDirectory = async (parent: Directory, name: string, blockstore:
|
|
58
|
+
const removeFromDirectory = async (parent: Directory, name: string, blockstore: Blocks, options: AbortOptions): Promise<RemoveLinkResult> => {
|
|
59
59
|
// Remove existing link if it exists
|
|
60
60
|
parent.node.Links = parent.node.Links.filter((link) => {
|
|
61
61
|
return link.Name !== name
|
|
@@ -75,7 +75,7 @@ const removeFromDirectory = async (parent: Directory, name: string, blockstore:
|
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
const removeFromShardedDirectory = async (parent: Directory, name: string, blockstore:
|
|
78
|
+
const removeFromShardedDirectory = async (parent: Directory, name: string, blockstore: Blocks, options: UpdateHamtDirectoryOptions): Promise<{ cid: CID, node: PBNode }> => {
|
|
79
79
|
const { path } = await recreateShardedDirectory(parent.cid, name, blockstore, options)
|
|
80
80
|
const finalSegment = path[path.length - 1]
|
|
81
81
|
|
|
@@ -132,7 +132,7 @@ const removeFromShardedDirectory = async (parent: Directory, name: string, block
|
|
|
132
132
|
return await updateShardedDirectory(path, blockstore, options)
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
const convertToFlatDirectory = async (parent: Directory, blockstore:
|
|
135
|
+
const convertToFlatDirectory = async (parent: Directory, blockstore: Blocks, options: RmLinkOptions): Promise<RemoveLinkResult> => {
|
|
136
136
|
if (parent.node.Data == null) {
|
|
137
137
|
throw new InvalidParametersError('Invalid parent passed to convertToFlatDirectory')
|
|
138
138
|
}
|
|
@@ -6,7 +6,7 @@ import { DoesNotExistError, InvalidParametersError } from './errors.js'
|
|
|
6
6
|
import { addLink } from './add-link.js'
|
|
7
7
|
import { cidToDirectory } from './cid-to-directory.js'
|
|
8
8
|
import { cidToPBLink } from './cid-to-pblink.js'
|
|
9
|
-
import type {
|
|
9
|
+
import type { Blocks } from '@helia/interface/blocks'
|
|
10
10
|
|
|
11
11
|
const log = logger('helia:unixfs:components:utils:resolve')
|
|
12
12
|
|
|
@@ -32,7 +32,7 @@ export interface ResolveResult {
|
|
|
32
32
|
segments?: Segment[]
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export async function resolve (cid: CID, path: string | undefined, blockstore:
|
|
35
|
+
export async function resolve (cid: CID, path: string | undefined, blockstore: Blocks, options: AbortOptions): Promise<ResolveResult> {
|
|
36
36
|
if (path == null || path === '') {
|
|
37
37
|
return { cid }
|
|
38
38
|
}
|
|
@@ -101,7 +101,7 @@ export interface UpdatePathCidsOptions extends AbortOptions {
|
|
|
101
101
|
* Where we have descended into a DAG to update a child node, ascend up the DAG creating
|
|
102
102
|
* new hashes and blocks for the changed content
|
|
103
103
|
*/
|
|
104
|
-
export async function updatePathCids (cid: CID, result: ResolveResult, blockstore:
|
|
104
|
+
export async function updatePathCids (cid: CID, result: ResolveResult, blockstore: Blocks, options: UpdatePathCidsOptions): Promise<CID> {
|
|
105
105
|
if (result.segments == null || result.segments.length === 0) {
|
|
106
106
|
return cid
|
|
107
107
|
}
|
package/src/index.ts
CHANGED
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
*/
|
|
33
33
|
|
|
34
34
|
import type { CID, Version } from 'multiformats/cid'
|
|
35
|
-
import type {
|
|
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
|
-
blockstore:
|
|
52
|
+
blockstore: Blocks
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type AddEvents = PutBlockProgressEvents
|
|
56
|
+
| ImportProgressEvents
|
|
57
|
+
|
|
58
|
+
export interface AddOptions extends AbortOptions, Omit<ImporterOptions, 'onProgress'>, ProgressOptions<AddEvents> {
|
|
59
|
+
|
|
52
60
|
}
|
|
53
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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
|
|
|
@@ -545,6 +553,6 @@ class DefaultUnixFS implements UnixFS {
|
|
|
545
553
|
/**
|
|
546
554
|
* Create a {@link UnixFS} instance for use with {@link https://github.com/ipfs/helia Helia}
|
|
547
555
|
*/
|
|
548
|
-
export function unixfs (helia: { blockstore:
|
|
556
|
+
export function unixfs (helia: { blockstore: Blocks }): UnixFS {
|
|
549
557
|
return new DefaultUnixFS(helia)
|
|
550
558
|
}
|