@helia/unixfs 7.0.3 → 7.0.4-12fd8522
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 +4 -4
- package/dist/index.min.js.map +4 -4
- package/dist/src/commands/add.d.ts +7 -7
- package/dist/src/commands/add.d.ts.map +1 -1
- package/dist/src/commands/add.js +12 -4
- package/dist/src/commands/add.js.map +1 -1
- package/dist/src/commands/cat.d.ts +3 -3
- package/dist/src/commands/cat.d.ts.map +1 -1
- package/dist/src/commands/cat.js +2 -2
- package/dist/src/commands/cat.js.map +1 -1
- package/dist/src/commands/chmod.d.ts +3 -3
- package/dist/src/commands/chmod.d.ts.map +1 -1
- package/dist/src/commands/chmod.js +3 -3
- package/dist/src/commands/chmod.js.map +1 -1
- package/dist/src/commands/cp.d.ts +3 -3
- package/dist/src/commands/cp.d.ts.map +1 -1
- package/dist/src/commands/cp.js +4 -4
- package/dist/src/commands/cp.js.map +1 -1
- package/dist/src/commands/ls.d.ts +3 -3
- package/dist/src/commands/ls.d.ts.map +1 -1
- package/dist/src/commands/ls.js +1 -1
- package/dist/src/commands/ls.js.map +1 -1
- package/dist/src/commands/mkdir.d.ts +3 -3
- package/dist/src/commands/mkdir.d.ts.map +1 -1
- package/dist/src/commands/mkdir.js +4 -4
- package/dist/src/commands/mkdir.js.map +1 -1
- package/dist/src/commands/rm.d.ts +3 -3
- package/dist/src/commands/rm.d.ts.map +1 -1
- package/dist/src/commands/rm.js +3 -3
- package/dist/src/commands/rm.js.map +1 -1
- package/dist/src/commands/stat.d.ts +2 -2
- package/dist/src/commands/stat.js +2 -2
- package/dist/src/commands/touch.d.ts +3 -3
- package/dist/src/commands/touch.d.ts.map +1 -1
- package/dist/src/commands/touch.js +3 -3
- package/dist/src/commands/touch.js.map +1 -1
- package/dist/src/commands/utils/add-link.d.ts +4 -6
- package/dist/src/commands/utils/add-link.d.ts.map +1 -1
- package/dist/src/commands/utils/add-link.js +6 -7
- package/dist/src/commands/utils/add-link.js.map +1 -1
- package/dist/src/commands/utils/cid-to-directory.d.ts +1 -1
- package/dist/src/commands/utils/cid-to-directory.js +1 -1
- package/dist/src/commands/utils/cid-to-pblink.d.ts +1 -1
- package/dist/src/commands/utils/cid-to-pblink.js +1 -1
- package/dist/src/commands/utils/hamt-utils.d.ts +3 -3
- package/dist/src/commands/utils/hamt-utils.d.ts.map +1 -1
- package/dist/src/commands/utils/hamt-utils.js +5 -5
- package/dist/src/commands/utils/hamt-utils.js.map +1 -1
- package/dist/src/commands/utils/is-over-shard-threshold.d.ts +6 -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 +54 -12
- package/dist/src/commands/utils/is-over-shard-threshold.js.map +1 -1
- package/dist/src/commands/utils/persist.d.ts +1 -1
- package/dist/src/commands/utils/remove-link.d.ts +5 -6
- package/dist/src/commands/utils/remove-link.d.ts.map +1 -1
- package/dist/src/commands/utils/remove-link.js +5 -6
- package/dist/src/commands/utils/remove-link.js.map +1 -1
- package/dist/src/commands/utils/resolve.d.ts +1 -1
- package/dist/src/commands/utils/resolve.js +4 -4
- package/dist/src/index.d.ts +23 -53
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -3
- package/dist/src/index.js.map +1 -1
- package/dist/src/unixfs.d.ts +1 -1
- package/dist/src/unixfs.js +9 -9
- package/dist/src/utils/glob-source.js +2 -2
- package/dist/src/utils/url-source.d.ts +1 -1
- package/dist/src/utils/url-source.js +1 -1
- package/package.json +3 -4
- package/src/commands/add.ts +19 -11
- package/src/commands/cat.ts +5 -5
- package/src/commands/chmod.ts +6 -6
- package/src/commands/cp.ts +7 -7
- package/src/commands/ls.ts +4 -4
- package/src/commands/mkdir.ts +7 -7
- package/src/commands/rm.ts +6 -6
- package/src/commands/stat.ts +4 -4
- package/src/commands/touch.ts +6 -6
- package/src/commands/utils/add-link.ts +10 -14
- package/src/commands/utils/cid-to-directory.ts +2 -2
- package/src/commands/utils/cid-to-pblink.ts +2 -2
- package/src/commands/utils/hamt-utils.ts +8 -8
- package/src/commands/utils/is-over-shard-threshold.ts +81 -11
- package/src/commands/utils/persist.ts +1 -1
- package/src/commands/utils/remove-link.ts +12 -13
- package/src/commands/utils/resolve.ts +5 -5
- package/src/index.ts +24 -60
- package/src/unixfs.ts +10 -10
- package/src/utils/glob-source.ts +2 -2
- package/src/utils/url-source.ts +2 -2
- package/dist/src/commands/utils/dir-sharded.d.ts +0 -74
- package/dist/src/commands/utils/dir-sharded.d.ts.map +0 -1
- package/dist/src/commands/utils/dir-sharded.js +0 -235
- package/dist/src/commands/utils/dir-sharded.js.map +0 -1
- package/dist/typedoc-urls.json +0 -76
- package/src/commands/utils/dir-sharded.ts +0 -321
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helia/unixfs",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.4-12fd8522",
|
|
4
4
|
"description": "A Helia-compatible wrapper for UnixFS",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/ipfs/helia/tree/main/packages/unixfs#readme",
|
|
@@ -67,17 +67,16 @@
|
|
|
67
67
|
"test:electron-main": "aegir test -t electron-main"
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
|
-
"@helia/interface": "
|
|
70
|
+
"@helia/interface": "6.1.1-12fd8522",
|
|
71
71
|
"@ipld/dag-pb": "^4.1.5",
|
|
72
72
|
"@libp2p/interface": "^3.1.0",
|
|
73
73
|
"@libp2p/logger": "^6.0.5",
|
|
74
74
|
"@libp2p/utils": "^7.0.5",
|
|
75
75
|
"@multiformats/murmur3": "^2.1.8",
|
|
76
|
-
"hamt-sharding": "^3.0.6",
|
|
77
76
|
"interface-blockstore": "^6.0.1",
|
|
78
77
|
"ipfs-unixfs": "^12.0.0",
|
|
79
78
|
"ipfs-unixfs-exporter": "^15.0.2",
|
|
80
|
-
"ipfs-unixfs-importer": "^16.
|
|
79
|
+
"ipfs-unixfs-importer": "^16.1.4",
|
|
81
80
|
"it-all": "^3.0.9",
|
|
82
81
|
"it-first": "^3.0.9",
|
|
83
82
|
"it-glob": "^3.0.4",
|
package/src/commands/add.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { importer, importFile } from 'ipfs-unixfs-importer'
|
|
2
2
|
import { fixedSize } from 'ipfs-unixfs-importer/chunker'
|
|
3
3
|
import { balanced } from 'ipfs-unixfs-importer/layout'
|
|
4
4
|
import first from 'it-first'
|
|
5
5
|
import last from 'it-last'
|
|
6
|
-
import { InvalidParametersError } from '../errors.
|
|
7
|
-
import type { FileCandidate, AddOptions, AddFileOptions } from '../index.
|
|
8
|
-
import type { PutStore } from '../unixfs.
|
|
6
|
+
import { InvalidParametersError } from '../errors.ts'
|
|
7
|
+
import type { FileCandidate, AddOptions, AddFileOptions } from '../index.ts'
|
|
8
|
+
import type { PutStore } from '../unixfs.ts'
|
|
9
9
|
import type { ByteStream, DirectoryCandidate, ImportCandidateStream, ImportResult } from 'ipfs-unixfs-importer'
|
|
10
10
|
import type { CID } from 'multiformats/cid'
|
|
11
11
|
|
|
@@ -23,15 +23,19 @@ const defaultImporterSettings: AddOptions = {
|
|
|
23
23
|
})
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export async function * addAll (source: ImportCandidateStream, blockstore: PutStore, options:
|
|
26
|
+
export async function * addAll (source: ImportCandidateStream, blockstore: PutStore, options: AddOptions = {}): AsyncGenerator<ImportResult, void, unknown> {
|
|
27
27
|
yield * importer(source, blockstore, {
|
|
28
28
|
...defaultImporterSettings,
|
|
29
29
|
...options
|
|
30
30
|
})
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export async function addBytes (bytes: Uint8Array, blockstore: PutStore, options:
|
|
34
|
-
const { cid } = await
|
|
33
|
+
export async function addBytes (bytes: Uint8Array, blockstore: PutStore, options: AddFileOptions = {}): Promise<CID> {
|
|
34
|
+
const { cid } = await importFile({
|
|
35
|
+
content: bytes,
|
|
36
|
+
mode: options.mode,
|
|
37
|
+
mtime: options.mtime
|
|
38
|
+
}, blockstore, {
|
|
35
39
|
...defaultImporterSettings,
|
|
36
40
|
...options
|
|
37
41
|
})
|
|
@@ -39,8 +43,12 @@ export async function addBytes (bytes: Uint8Array, blockstore: PutStore, options
|
|
|
39
43
|
return cid
|
|
40
44
|
}
|
|
41
45
|
|
|
42
|
-
export async function addByteStream (bytes: ByteStream, blockstore: PutStore, options:
|
|
43
|
-
const { cid } = await
|
|
46
|
+
export async function addByteStream (bytes: ByteStream, blockstore: PutStore, options: AddFileOptions = {}): Promise<CID> {
|
|
47
|
+
const { cid } = await importFile({
|
|
48
|
+
content: bytes,
|
|
49
|
+
mode: options.mode,
|
|
50
|
+
mtime: options.mtime
|
|
51
|
+
}, blockstore, {
|
|
44
52
|
...defaultImporterSettings,
|
|
45
53
|
...options
|
|
46
54
|
})
|
|
@@ -48,7 +56,7 @@ export async function addByteStream (bytes: ByteStream, blockstore: PutStore, op
|
|
|
48
56
|
return cid
|
|
49
57
|
}
|
|
50
58
|
|
|
51
|
-
export async function addFile (file: FileCandidate, blockstore: PutStore, options:
|
|
59
|
+
export async function addFile (file: FileCandidate, blockstore: PutStore, options: AddFileOptions = {}): Promise<CID> {
|
|
52
60
|
if (file.path == null) {
|
|
53
61
|
throw new InvalidParametersError('path is required')
|
|
54
62
|
}
|
|
@@ -70,7 +78,7 @@ export async function addFile (file: FileCandidate, blockstore: PutStore, option
|
|
|
70
78
|
return result.cid
|
|
71
79
|
}
|
|
72
80
|
|
|
73
|
-
export async function addDirectory (dir: Partial<DirectoryCandidate>, blockstore: PutStore, options:
|
|
81
|
+
export async function addDirectory (dir: Partial<DirectoryCandidate>, blockstore: PutStore, options: AddFileOptions = {}): Promise<CID> {
|
|
74
82
|
// @ts-expect-error field is not in the types
|
|
75
83
|
if (dir.content != null) {
|
|
76
84
|
throw new InvalidParametersError('Directories cannot have content, use addFile instead')
|
package/src/commands/cat.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { exporter } from 'ipfs-unixfs-exporter'
|
|
2
|
-
import { NoContentError, NotAFileError } from '../errors.
|
|
3
|
-
import { resolve } from './utils/resolve.
|
|
4
|
-
import type { CatOptions } from '../index.
|
|
5
|
-
import type { GetStore } from '../unixfs.
|
|
2
|
+
import { NoContentError, NotAFileError } from '../errors.ts'
|
|
3
|
+
import { resolve } from './utils/resolve.ts'
|
|
4
|
+
import type { CatOptions } from '../index.ts'
|
|
5
|
+
import type { GetStore } from '../unixfs.ts'
|
|
6
6
|
import type { CID } from 'multiformats/cid'
|
|
7
7
|
|
|
8
|
-
export async function * cat (cid: CID, blockstore: GetStore, options:
|
|
8
|
+
export async function * cat (cid: CID, blockstore: GetStore, options: CatOptions = {}): AsyncIterable<Uint8Array> {
|
|
9
9
|
const resolved = await resolve(cid, options.path, blockstore, options)
|
|
10
10
|
const result = await exporter(resolved.cid, blockstore, options)
|
|
11
11
|
|
package/src/commands/chmod.ts
CHANGED
|
@@ -9,16 +9,16 @@ import toBuffer from 'it-to-buffer'
|
|
|
9
9
|
import { CID } from 'multiformats/cid'
|
|
10
10
|
import * as raw from 'multiformats/codecs/raw'
|
|
11
11
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
12
|
-
import { InvalidPBNodeError, NotUnixFSError, UnknownError } from '../errors.
|
|
13
|
-
import { persist } from './utils/persist.
|
|
14
|
-
import { resolve, updatePathCids } from './utils/resolve.
|
|
15
|
-
import type { ChmodOptions } from '../index.
|
|
16
|
-
import type { GetStore, PutStore } from '../unixfs.
|
|
12
|
+
import { InvalidPBNodeError, NotUnixFSError, UnknownError } from '../errors.ts'
|
|
13
|
+
import { persist } from './utils/persist.ts'
|
|
14
|
+
import { resolve, updatePathCids } from './utils/resolve.ts'
|
|
15
|
+
import type { ChmodOptions } from '../index.ts'
|
|
16
|
+
import type { GetStore, PutStore } from '../unixfs.ts'
|
|
17
17
|
import type { PBNode, PBLink } from '@ipld/dag-pb'
|
|
18
18
|
|
|
19
19
|
const log = logger('helia:unixfs:chmod')
|
|
20
20
|
|
|
21
|
-
export async function chmod (cid: CID, mode: number, blockstore: PutStore & GetStore, options:
|
|
21
|
+
export async function chmod (cid: CID, mode: number, blockstore: PutStore & GetStore, options: ChmodOptions = {}): Promise<CID> {
|
|
22
22
|
const resolved = await resolve(cid, options.path, blockstore, options)
|
|
23
23
|
|
|
24
24
|
log('chmod %c %d', resolved.cid, mode)
|
package/src/commands/cp.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
|
-
import { InvalidParametersError } from '../errors.
|
|
3
|
-
import { addLink } from './utils/add-link.
|
|
4
|
-
import { cidToDirectory } from './utils/cid-to-directory.
|
|
5
|
-
import { cidToPBLink } from './utils/cid-to-pblink.
|
|
6
|
-
import type { CpOptions } from '../index.
|
|
7
|
-
import type { GetStore, PutStore } from '../unixfs.
|
|
2
|
+
import { InvalidParametersError } from '../errors.ts'
|
|
3
|
+
import { addLink } from './utils/add-link.ts'
|
|
4
|
+
import { cidToDirectory } from './utils/cid-to-directory.ts'
|
|
5
|
+
import { cidToPBLink } from './utils/cid-to-pblink.ts'
|
|
6
|
+
import type { CpOptions } from '../index.ts'
|
|
7
|
+
import type { GetStore, PutStore } from '../unixfs.ts'
|
|
8
8
|
import type { CID } from 'multiformats/cid'
|
|
9
9
|
|
|
10
10
|
const log = logger('helia:unixfs:cp')
|
|
11
11
|
|
|
12
|
-
export async function cp (source: CID, target: CID, name: string, blockstore: GetStore & PutStore, options:
|
|
12
|
+
export async function cp (source: CID, target: CID, name: string, blockstore: GetStore & PutStore, options: CpOptions = {}): Promise<CID> {
|
|
13
13
|
if (name.includes('/')) {
|
|
14
14
|
throw new InvalidParametersError('Name must not have slashes')
|
|
15
15
|
}
|
package/src/commands/ls.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { exporter } from 'ipfs-unixfs-exporter'
|
|
2
|
-
import { resolve } from './utils/resolve.
|
|
3
|
-
import type { LsOptions } from '../index.
|
|
4
|
-
import type { GetStore } from '../unixfs.
|
|
2
|
+
import { resolve } from './utils/resolve.ts'
|
|
3
|
+
import type { LsOptions } from '../index.ts'
|
|
4
|
+
import type { GetStore } from '../unixfs.ts'
|
|
5
5
|
import type { UnixFSDirectoryEntry } from 'ipfs-unixfs-exporter'
|
|
6
6
|
import type { CID } from 'multiformats/cid'
|
|
7
7
|
|
|
8
|
-
export async function * ls (cid: CID, blockstore: GetStore, options:
|
|
8
|
+
export async function * ls (cid: CID, blockstore: GetStore, options: LsOptions = {}): AsyncIterable<UnixFSDirectoryEntry> {
|
|
9
9
|
const resolved = await resolve(cid, options.path, blockstore, options)
|
|
10
10
|
const result = await exporter(resolved.cid, blockstore, options)
|
|
11
11
|
|
package/src/commands/mkdir.ts
CHANGED
|
@@ -5,16 +5,16 @@ import { exporter } from 'ipfs-unixfs-exporter'
|
|
|
5
5
|
import { CID } from 'multiformats/cid'
|
|
6
6
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
7
7
|
import { DEFAULT_CID_VERSION } from '../constants.ts'
|
|
8
|
-
import { InvalidParametersError, NotADirectoryError } from '../errors.
|
|
9
|
-
import { addLink } from './utils/add-link.
|
|
10
|
-
import { cidToDirectory } from './utils/cid-to-directory.
|
|
11
|
-
import { cidToPBLink } from './utils/cid-to-pblink.
|
|
12
|
-
import type { MkdirOptions } from '../index.
|
|
13
|
-
import type { GetStore, PutStore } from '../unixfs.
|
|
8
|
+
import { InvalidParametersError, NotADirectoryError } from '../errors.ts'
|
|
9
|
+
import { addLink } from './utils/add-link.ts'
|
|
10
|
+
import { cidToDirectory } from './utils/cid-to-directory.ts'
|
|
11
|
+
import { cidToPBLink } from './utils/cid-to-pblink.ts'
|
|
12
|
+
import type { MkdirOptions } from '../index.ts'
|
|
13
|
+
import type { GetStore, PutStore } from '../unixfs.ts'
|
|
14
14
|
|
|
15
15
|
const log = logger('helia:unixfs:mkdir')
|
|
16
16
|
|
|
17
|
-
export async function mkdir (parentCid: CID, dirname: string, blockstore: GetStore & PutStore, options:
|
|
17
|
+
export async function mkdir (parentCid: CID, dirname: string, blockstore: GetStore & PutStore, options: MkdirOptions = {}): Promise<CID> {
|
|
18
18
|
if (dirname.includes('/')) {
|
|
19
19
|
throw new InvalidParametersError('Path must not have slashes')
|
|
20
20
|
}
|
package/src/commands/rm.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
|
-
import { InvalidParametersError } from '../errors.
|
|
3
|
-
import { cidToDirectory } from './utils/cid-to-directory.
|
|
4
|
-
import { removeLink } from './utils/remove-link.
|
|
5
|
-
import type { RmOptions } from '../index.
|
|
6
|
-
import type { GetStore, PutStore } from '../unixfs.
|
|
2
|
+
import { InvalidParametersError } from '../errors.ts'
|
|
3
|
+
import { cidToDirectory } from './utils/cid-to-directory.ts'
|
|
4
|
+
import { removeLink } from './utils/remove-link.ts'
|
|
5
|
+
import type { RmOptions } from '../index.ts'
|
|
6
|
+
import type { GetStore, PutStore } from '../unixfs.ts'
|
|
7
7
|
import type { CID } from 'multiformats/cid'
|
|
8
8
|
|
|
9
9
|
const log = logger('helia:unixfs:rm')
|
|
10
10
|
|
|
11
|
-
export async function rm (target: CID, name: string, blockstore: GetStore & PutStore, options:
|
|
11
|
+
export async function rm (target: CID, name: string, blockstore: GetStore & PutStore, options: RmOptions = {}): Promise<CID> {
|
|
12
12
|
if (name.includes('/')) {
|
|
13
13
|
throw new InvalidParametersError('Name must not have slashes')
|
|
14
14
|
}
|
package/src/commands/stat.ts
CHANGED
|
@@ -5,10 +5,10 @@ import { UnixFS } from 'ipfs-unixfs'
|
|
|
5
5
|
import { exporter } from 'ipfs-unixfs-exporter'
|
|
6
6
|
import toBuffer from 'it-to-buffer'
|
|
7
7
|
import * as raw from 'multiformats/codecs/raw'
|
|
8
|
-
import { InvalidPBNodeError, NotUnixFSError, UnknownError } from '../errors.
|
|
9
|
-
import { resolve } from './utils/resolve.
|
|
10
|
-
import type { ExtendedStatOptions, ExtendedDirectoryStats, ExtendedFileStats, StatOptions, DirectoryStats, FileStats, RawStats, ExtendedRawStats } from '../index.
|
|
11
|
-
import type { GetStore, HasStore } from '../unixfs.
|
|
8
|
+
import { InvalidPBNodeError, NotUnixFSError, UnknownError } from '../errors.ts'
|
|
9
|
+
import { resolve } from './utils/resolve.ts'
|
|
10
|
+
import type { ExtendedStatOptions, ExtendedDirectoryStats, ExtendedFileStats, StatOptions, DirectoryStats, FileStats, RawStats, ExtendedRawStats } from '../index.ts'
|
|
11
|
+
import type { GetStore, HasStore } from '../unixfs.ts'
|
|
12
12
|
import type { Filter } from '@libp2p/utils'
|
|
13
13
|
import type { RawNode, UnixFSDirectory, UnixFSFile } from 'ipfs-unixfs-exporter'
|
|
14
14
|
import type { CID } from 'multiformats/cid'
|
package/src/commands/touch.ts
CHANGED
|
@@ -9,16 +9,16 @@ import toBuffer from 'it-to-buffer'
|
|
|
9
9
|
import { CID } from 'multiformats/cid'
|
|
10
10
|
import * as raw from 'multiformats/codecs/raw'
|
|
11
11
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
12
|
-
import { InvalidPBNodeError, NotUnixFSError, UnknownError } from '../errors.
|
|
13
|
-
import { persist } from './utils/persist.
|
|
14
|
-
import { resolve, updatePathCids } from './utils/resolve.
|
|
15
|
-
import type { TouchOptions } from '../index.
|
|
16
|
-
import type { GetStore, PutStore } from '../unixfs.
|
|
12
|
+
import { InvalidPBNodeError, NotUnixFSError, UnknownError } from '../errors.ts'
|
|
13
|
+
import { persist } from './utils/persist.ts'
|
|
14
|
+
import { resolve, updatePathCids } from './utils/resolve.ts'
|
|
15
|
+
import type { TouchOptions } from '../index.ts'
|
|
16
|
+
import type { GetStore, PutStore } from '../unixfs.ts'
|
|
17
17
|
import type { PBNode, PBLink } from '@ipld/dag-pb'
|
|
18
18
|
|
|
19
19
|
const log = logger('helia:unixfs:touch')
|
|
20
20
|
|
|
21
|
-
export async function touch (cid: CID, blockstore: GetStore & PutStore, options:
|
|
21
|
+
export async function touch (cid: CID, blockstore: GetStore & PutStore, options: TouchOptions = {}): Promise<CID> {
|
|
22
22
|
const resolved = await resolve(cid, options.path, blockstore, options)
|
|
23
23
|
const mtime = options.mtime ?? {
|
|
24
24
|
secs: BigInt(Math.round(Date.now() / 1000)),
|
|
@@ -7,23 +7,21 @@ import { sha256 } from 'multiformats/hashes/sha2'
|
|
|
7
7
|
// @ts-expect-error no types
|
|
8
8
|
import SparseArray from 'sparse-array'
|
|
9
9
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { hamtBucketBits, hamtHashFn } from './hamt-constants.js'
|
|
10
|
+
import { AlreadyExistsError, InvalidParametersError, InvalidPBNodeError } from '../../errors.ts'
|
|
11
|
+
import { wrapHash } from './consumable-hash.ts'
|
|
12
|
+
import { hamtBucketBits, hamtHashFn } from './hamt-constants.ts'
|
|
14
13
|
import {
|
|
15
14
|
createShard,
|
|
16
15
|
recreateShardedDirectory,
|
|
17
16
|
toPrefix,
|
|
18
17
|
updateShardedDirectory
|
|
19
|
-
} from './hamt-utils.
|
|
20
|
-
import { isOverShardThreshold } from './is-over-shard-threshold.
|
|
21
|
-
import type { Directory } from './cid-to-directory.
|
|
22
|
-
import type { GetStore, PutStore } from '../../unixfs.
|
|
18
|
+
} from './hamt-utils.ts'
|
|
19
|
+
import { isOverShardThreshold } from './is-over-shard-threshold.ts'
|
|
20
|
+
import type { Directory } from './cid-to-directory.ts'
|
|
21
|
+
import type { GetStore, PutStore } from '../../unixfs.ts'
|
|
23
22
|
import type { PBNode, PBLink } from '@ipld/dag-pb'
|
|
24
23
|
import type { AbortOptions } from '@libp2p/interface'
|
|
25
|
-
import type { ImportResult } from 'ipfs-unixfs-importer'
|
|
26
|
-
import type { Version } from 'multiformats/cid'
|
|
24
|
+
import type { ImporterOptions, ImportResult } from 'ipfs-unixfs-importer'
|
|
27
25
|
|
|
28
26
|
const log = logger('helia:unixfs:components:utils:add-link')
|
|
29
27
|
|
|
@@ -32,10 +30,8 @@ export interface AddLinkResult {
|
|
|
32
30
|
cid: CID
|
|
33
31
|
}
|
|
34
32
|
|
|
35
|
-
export interface AddLinkOptions extends AbortOptions {
|
|
33
|
+
export interface AddLinkOptions extends AbortOptions, Pick<ImporterOptions, 'profile' | 'shardSplitThresholdBytes' | 'shardSplitStrategy' | 'shardFanoutBits' | 'cidVersion'> {
|
|
36
34
|
allowOverwriting?: boolean
|
|
37
|
-
shardSplitThresholdBytes?: number
|
|
38
|
-
cidVersion?: Version
|
|
39
35
|
}
|
|
40
36
|
|
|
41
37
|
export async function addLink (parent: Directory, child: Required<PBLink>, blockstore: GetStore & PutStore, options: AddLinkOptions): Promise<AddLinkResult> {
|
|
@@ -55,7 +51,7 @@ export async function addLink (parent: Directory, child: Required<PBLink>, block
|
|
|
55
51
|
|
|
56
52
|
const result = await addToDirectory(parent, child, blockstore, options)
|
|
57
53
|
|
|
58
|
-
if (await isOverShardThreshold(result.node, blockstore, options
|
|
54
|
+
if (await isOverShardThreshold(result.node, blockstore, options)) {
|
|
59
55
|
log('converting directory to sharded directory')
|
|
60
56
|
|
|
61
57
|
const converted = await convertToShardedDirectory(result, blockstore)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { exporter } from 'ipfs-unixfs-exporter'
|
|
2
|
-
import { NotADirectoryError } from '../../errors.
|
|
3
|
-
import type { GetStore } from '../../unixfs.
|
|
2
|
+
import { NotADirectoryError } from '../../errors.ts'
|
|
3
|
+
import type { GetStore } from '../../unixfs.ts'
|
|
4
4
|
import type { PBNode } from '@ipld/dag-pb'
|
|
5
5
|
import type { ExporterOptions } from 'ipfs-unixfs-exporter'
|
|
6
6
|
import type { CID } from 'multiformats/cid'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as dagPb from '@ipld/dag-pb'
|
|
2
2
|
import { exporter } from 'ipfs-unixfs-exporter'
|
|
3
|
-
import { NotUnixFSError } from '../../errors.
|
|
4
|
-
import type { GetStore } from '../../unixfs.
|
|
3
|
+
import { NotUnixFSError } from '../../errors.ts'
|
|
4
|
+
import type { GetStore } from '../../unixfs.ts'
|
|
5
5
|
import type { PBNode, PBLink } from '@ipld/dag-pb'
|
|
6
6
|
import type { ExporterOptions } from 'ipfs-unixfs-exporter'
|
|
7
7
|
import type { CID } from 'multiformats/cid'
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import * as dagPB from '@ipld/dag-pb'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
3
|
import { UnixFS } from 'ipfs-unixfs'
|
|
4
|
+
import { DirSharded } from 'ipfs-unixfs-importer/utils'
|
|
4
5
|
import last from 'it-last'
|
|
5
6
|
import toBuffer from 'it-to-buffer'
|
|
6
7
|
// @ts-expect-error no types
|
|
7
8
|
import SparseArray from 'sparse-array'
|
|
8
9
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
9
|
-
import { wrapHash } from './consumable-hash.
|
|
10
|
-
import { DirSharded } from './dir-sharded.js'
|
|
10
|
+
import { wrapHash } from './consumable-hash.ts'
|
|
11
11
|
import {
|
|
12
12
|
hamtHashCode,
|
|
13
13
|
hamtHashFn,
|
|
14
14
|
hamtBucketBits
|
|
15
|
-
} from './hamt-constants.
|
|
16
|
-
import { persist } from './persist.
|
|
17
|
-
import type { InfiniteHash } from './consumable-hash.
|
|
18
|
-
import type { PersistOptions } from './persist.
|
|
19
|
-
import type { GetStore, PutStore } from '../../unixfs.
|
|
15
|
+
} from './hamt-constants.ts'
|
|
16
|
+
import { persist } from './persist.ts'
|
|
17
|
+
import type { InfiniteHash } from './consumable-hash.ts'
|
|
18
|
+
import type { PersistOptions } from './persist.ts'
|
|
19
|
+
import type { GetStore, PutStore } from '../../unixfs.ts'
|
|
20
20
|
import type { AbortOptions } from '@libp2p/interface'
|
|
21
21
|
import type { Blockstore } from 'interface-blockstore'
|
|
22
22
|
import type { Mtime } from 'ipfs-unixfs'
|
|
@@ -57,7 +57,7 @@ export const createShard = async (blockstore: PutStore, contents: Array<{ name:
|
|
|
57
57
|
}, options)
|
|
58
58
|
|
|
59
59
|
for (let i = 0; i < contents.length; i++) {
|
|
60
|
-
await shard.
|
|
60
|
+
await shard.bucket.put(contents[i].name, {
|
|
61
61
|
size: contents[i].size,
|
|
62
62
|
cid: contents[i].cid
|
|
63
63
|
})
|
|
@@ -1,31 +1,53 @@
|
|
|
1
1
|
import * as dagPb from '@ipld/dag-pb'
|
|
2
|
+
import { InvalidParametersError } from '@libp2p/interface'
|
|
2
3
|
import { UnixFS } from 'ipfs-unixfs'
|
|
4
|
+
import { dataFieldSerializedSize, linkSerializedSize, utf8ByteLength } from 'ipfs-unixfs-importer/utils'
|
|
3
5
|
import toBuffer from 'it-to-buffer'
|
|
4
|
-
import {
|
|
6
|
+
import { DEFAULT_SHARD_SPLIT_THRESHOLD_BYTES } from '../../constants.ts'
|
|
5
7
|
import type { GetStore } from '../../unixfs.js'
|
|
6
8
|
import type { PBNode } from '@ipld/dag-pb'
|
|
7
9
|
import type { AbortOptions } from '@libp2p/interface'
|
|
10
|
+
import type { ImporterOptions, ShardSplitStrategy } from 'ipfs-unixfs-importer'
|
|
11
|
+
|
|
12
|
+
export interface IsOverShardThresholdOptions extends AbortOptions, Pick<ImporterOptions, 'profile' | 'shardSplitThresholdBytes' | 'shardSplitStrategy'> {
|
|
13
|
+
|
|
14
|
+
}
|
|
8
15
|
|
|
9
16
|
/**
|
|
10
17
|
* Estimate node size only based on DAGLink name and CID byte lengths
|
|
11
18
|
* https://github.com/ipfs/go-unixfsnode/blob/37b47f1f917f1b2f54c207682f38886e49896ef9/data/builder/directory.go#L81-L96
|
|
12
19
|
*
|
|
13
|
-
* If the node is a hamt sharded directory the calculation is based on if it was
|
|
20
|
+
* If the node is a hamt sharded directory the calculation is based on if it was
|
|
21
|
+
* a regular directory.
|
|
14
22
|
*/
|
|
15
|
-
export async function isOverShardThreshold (node: PBNode, blockstore: GetStore,
|
|
23
|
+
export async function isOverShardThreshold (node: PBNode, blockstore: GetStore, options: IsOverShardThresholdOptions): Promise<boolean> {
|
|
16
24
|
if (node.Data == null) {
|
|
17
25
|
throw new Error('DagPB node had no data')
|
|
18
26
|
}
|
|
19
27
|
|
|
28
|
+
const threshold = options.shardSplitThresholdBytes ?? DEFAULT_SHARD_SPLIT_THRESHOLD_BYTES
|
|
29
|
+
let strategy: ShardSplitStrategy = options.shardSplitStrategy ?? 'links-bytes'
|
|
30
|
+
|
|
31
|
+
if (options.profile === 'unixfs-v0-2015') {
|
|
32
|
+
strategy = 'links-bytes'
|
|
33
|
+
}
|
|
34
|
+
|
|
20
35
|
const unixfs = UnixFS.unmarshal(node.Data)
|
|
21
|
-
|
|
36
|
+
|
|
37
|
+
if (!unixfs.isDirectory()) {
|
|
38
|
+
throw new Error('Can only estimate the size of directories or shards')
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (strategy !== 'links-bytes' && strategy !== 'block-bytes') {
|
|
42
|
+
throw new InvalidParametersError(`Invalid shard split threshold "${strategy}"`)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let size: number = 0
|
|
22
46
|
|
|
23
47
|
if (unixfs.type === 'directory') {
|
|
24
|
-
size = estimateNodeSize(node)
|
|
48
|
+
size = strategy === 'links-bytes' ? estimateNodeSize(node) : calculateNodeSize(unixfs, node)
|
|
25
49
|
} else if (unixfs.type === 'hamt-sharded-directory') {
|
|
26
|
-
size = await estimateShardSize(node, 0, threshold, blockstore, options)
|
|
27
|
-
} else {
|
|
28
|
-
throw new Error('Can only estimate the size of directories or shards')
|
|
50
|
+
size = strategy === 'links-bytes' ? await estimateShardSize(node, 0, threshold, blockstore, options) : await calculateShardSize(node, dataFieldSerializedSize(unixfs.mode, unixfs.mtime), threshold, blockstore, options)
|
|
29
51
|
}
|
|
30
52
|
|
|
31
53
|
return size > threshold
|
|
@@ -37,8 +59,20 @@ function estimateNodeSize (node: PBNode): number {
|
|
|
37
59
|
// estimate size only based on DAGLink name and CID byte lengths
|
|
38
60
|
// https://github.com/ipfs/go-unixfsnode/blob/37b47f1f917f1b2f54c207682f38886e49896ef9/data/builder/directory.go#L81-L96
|
|
39
61
|
for (const link of node.Links) {
|
|
40
|
-
size += (link.Name ?? '')
|
|
41
|
-
size += link.Hash.
|
|
62
|
+
size += utf8ByteLength(link.Name ?? '')
|
|
63
|
+
size += link.Hash.byteLength
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return size
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function calculateNodeSize (unixfs: UnixFS, node: PBNode): number {
|
|
70
|
+
let size = dataFieldSerializedSize(unixfs.mode, unixfs.mtime)
|
|
71
|
+
|
|
72
|
+
for (const link of node.Links) {
|
|
73
|
+
size += linkSerializedSize(
|
|
74
|
+
utf8ByteLength(link.Name ?? ''), link.Hash.byteLength, Number(link.Tsize ?? 0)
|
|
75
|
+
)
|
|
42
76
|
}
|
|
43
77
|
|
|
44
78
|
return size
|
|
@@ -65,7 +99,7 @@ async function estimateShardSize (node: PBNode, current: number, max: number, bl
|
|
|
65
99
|
// remove hamt hash prefix from name
|
|
66
100
|
name = name.substring(2)
|
|
67
101
|
|
|
68
|
-
current += name
|
|
102
|
+
current += utf8ByteLength(name)
|
|
69
103
|
current += link.Hash.bytes.byteLength
|
|
70
104
|
|
|
71
105
|
if (link.Hash.code === dagPb.code) {
|
|
@@ -78,3 +112,39 @@ async function estimateShardSize (node: PBNode, current: number, max: number, bl
|
|
|
78
112
|
|
|
79
113
|
return current
|
|
80
114
|
}
|
|
115
|
+
|
|
116
|
+
async function calculateShardSize (node: PBNode, current: number, max: number, blockstore: GetStore, options: AbortOptions): Promise<number> {
|
|
117
|
+
if (current > max) {
|
|
118
|
+
return max
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (node.Data == null) {
|
|
122
|
+
return current
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const unixfs = UnixFS.unmarshal(node.Data)
|
|
126
|
+
|
|
127
|
+
if (!unixfs.isDirectory()) {
|
|
128
|
+
return current
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
for (const link of node.Links) {
|
|
132
|
+
let name = link.Name ?? ''
|
|
133
|
+
|
|
134
|
+
// remove hamt hash prefix from name
|
|
135
|
+
name = name.substring(2)
|
|
136
|
+
|
|
137
|
+
current += linkSerializedSize(
|
|
138
|
+
utf8ByteLength(name), link.Hash.byteLength, Number(link.Tsize ?? 0)
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
if (link.Hash.code === dagPb.code) {
|
|
142
|
+
const block = await toBuffer(blockstore.get(link.Hash, options))
|
|
143
|
+
const node = dagPb.decode(block)
|
|
144
|
+
|
|
145
|
+
current += await calculateShardSize(node, current, max, blockstore, options)
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return current
|
|
150
|
+
}
|
|
@@ -2,7 +2,7 @@ import * as dagPb from '@ipld/dag-pb'
|
|
|
2
2
|
import { CID } from 'multiformats/cid'
|
|
3
3
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
4
4
|
import { DEFAULT_CID_VERSION } from '../../constants.ts'
|
|
5
|
-
import type { PutStore } from '../../unixfs.
|
|
5
|
+
import type { PutStore } from '../../unixfs.ts'
|
|
6
6
|
import type { Version as CIDVersion } from 'multiformats/cid'
|
|
7
7
|
import type { BlockCodec } from 'multiformats/codecs/interface'
|
|
8
8
|
|
|
@@ -2,27 +2,26 @@ import * as dagPB from '@ipld/dag-pb'
|
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
3
|
import { UnixFS } from 'ipfs-unixfs'
|
|
4
4
|
import { exporter } from 'ipfs-unixfs-exporter'
|
|
5
|
-
import {
|
|
6
|
-
import { InvalidParametersError, InvalidPBNodeError } from '../../errors.js'
|
|
5
|
+
import { InvalidParametersError, InvalidPBNodeError } from '../../errors.ts'
|
|
7
6
|
import {
|
|
8
7
|
recreateShardedDirectory,
|
|
9
8
|
|
|
10
9
|
updateShardedDirectory
|
|
11
|
-
} from './hamt-utils.
|
|
12
|
-
import { isOverShardThreshold } from './is-over-shard-threshold.
|
|
13
|
-
import { persist } from './persist.
|
|
14
|
-
import type { Directory } from './cid-to-directory.
|
|
15
|
-
import type { UpdateHamtDirectoryOptions } from './hamt-utils.
|
|
16
|
-
import type { GetStore, PutStore } from '../../unixfs.
|
|
10
|
+
} from './hamt-utils.ts'
|
|
11
|
+
import { isOverShardThreshold } from './is-over-shard-threshold.ts'
|
|
12
|
+
import { persist } from './persist.ts'
|
|
13
|
+
import type { Directory } from './cid-to-directory.ts'
|
|
14
|
+
import type { UpdateHamtDirectoryOptions } from './hamt-utils.ts'
|
|
15
|
+
import type { GetStore, PutStore } from '../../unixfs.ts'
|
|
17
16
|
import type { PBNode } from '@ipld/dag-pb'
|
|
18
17
|
import type { AbortOptions } from '@libp2p/interface'
|
|
19
|
-
import type {
|
|
18
|
+
import type { ImporterOptions } from 'ipfs-unixfs-importer'
|
|
19
|
+
import type { CID } from 'multiformats/cid'
|
|
20
20
|
|
|
21
21
|
const log = logger('helia:unixfs:utils:remove-link')
|
|
22
22
|
|
|
23
|
-
export interface RmLinkOptions extends AbortOptions {
|
|
24
|
-
|
|
25
|
-
cidVersion?: Version
|
|
23
|
+
export interface RmLinkOptions extends AbortOptions, Pick<ImporterOptions, 'profile' | 'shardSplitThresholdBytes' | 'shardSplitStrategy' | 'shardFanoutBits' | 'cidVersion'> {
|
|
24
|
+
|
|
26
25
|
}
|
|
27
26
|
|
|
28
27
|
export interface RemoveLinkResult {
|
|
@@ -42,7 +41,7 @@ export async function removeLink (parent: Directory, name: string, blockstore: P
|
|
|
42
41
|
|
|
43
42
|
const result = await removeFromShardedDirectory(parent, name, blockstore, options)
|
|
44
43
|
|
|
45
|
-
if (!(await isOverShardThreshold(result.node, blockstore, options
|
|
44
|
+
if (!(await isOverShardThreshold(result.node, blockstore, options))) {
|
|
46
45
|
log('converting shard to flat directory %c', parent.cid)
|
|
47
46
|
|
|
48
47
|
return convertToFlatDirectory(result, blockstore, options)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
2
|
import { walkPath } from 'ipfs-unixfs-exporter'
|
|
3
3
|
import all from 'it-all'
|
|
4
|
-
import { DoesNotExistError } from '../../errors.
|
|
5
|
-
import { addLink } from './add-link.
|
|
6
|
-
import { cidToDirectory } from './cid-to-directory.
|
|
7
|
-
import { cidToPBLink } from './cid-to-pblink.
|
|
8
|
-
import type { GetStore, PutStore } from '../../unixfs.
|
|
4
|
+
import { DoesNotExistError } from '../../errors.ts'
|
|
5
|
+
import { addLink } from './add-link.ts'
|
|
6
|
+
import { cidToDirectory } from './cid-to-directory.ts'
|
|
7
|
+
import { cidToPBLink } from './cid-to-pblink.ts'
|
|
8
|
+
import type { GetStore, PutStore } from '../../unixfs.ts'
|
|
9
9
|
import type { AbortOptions } from '@libp2p/interface'
|
|
10
10
|
import type { PathEntry } from 'ipfs-unixfs-exporter'
|
|
11
11
|
import type { CID } from 'multiformats/cid'
|