@helia/unixfs 5.0.4 → 5.1.0-34d3ecd7
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 +2 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/commands/cat.d.ts.map +1 -1
- package/dist/src/commands/cat.js +3 -7
- package/dist/src/commands/cat.js.map +1 -1
- package/dist/src/commands/chmod.d.ts.map +1 -1
- package/dist/src/commands/chmod.js +8 -15
- package/dist/src/commands/chmod.js.map +1 -1
- package/dist/src/commands/cp.d.ts.map +1 -1
- package/dist/src/commands/cp.js +4 -12
- package/dist/src/commands/cp.js.map +1 -1
- package/dist/src/commands/ls.d.ts +4 -1
- package/dist/src/commands/ls.d.ts.map +1 -1
- package/dist/src/commands/ls.js +17 -11
- package/dist/src/commands/ls.js.map +1 -1
- package/dist/src/commands/mkdir.d.ts.map +1 -1
- package/dist/src/commands/mkdir.js +8 -16
- package/dist/src/commands/mkdir.js.map +1 -1
- package/dist/src/commands/rm.d.ts.map +1 -1
- package/dist/src/commands/rm.js +2 -9
- package/dist/src/commands/rm.js.map +1 -1
- package/dist/src/commands/stat.d.ts.map +1 -1
- package/dist/src/commands/stat.js +5 -8
- package/dist/src/commands/stat.js.map +1 -1
- package/dist/src/commands/touch.d.ts.map +1 -1
- package/dist/src/commands/touch.js +9 -16
- package/dist/src/commands/touch.js.map +1 -1
- package/dist/src/commands/utils/add-link.d.ts +3 -3
- package/dist/src/commands/utils/add-link.d.ts.map +1 -1
- package/dist/src/commands/utils/add-link.js +4 -2
- package/dist/src/commands/utils/add-link.js.map +1 -1
- package/dist/src/commands/utils/hamt-utils.d.ts +2 -2
- package/dist/src/commands/utils/hamt-utils.d.ts.map +1 -1
- package/dist/src/commands/utils/hamt-utils.js +2 -1
- package/dist/src/commands/utils/hamt-utils.js.map +1 -1
- package/dist/src/commands/utils/is-over-shard-threshold.d.ts.map +1 -1
- package/dist/src/commands/utils/is-over-shard-threshold.js +2 -1
- 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/persist.d.ts.map +1 -1
- package/dist/src/commands/utils/persist.js +2 -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 +2 -1
- 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.d.ts.map +1 -1
- package/dist/src/constants.d.ts +3 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +3 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/index.d.ts +19 -9
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/package.json +19 -26
- package/src/commands/cat.ts +3 -11
- package/src/commands/chmod.ts +8 -16
- package/src/commands/cp.ts +4 -14
- package/src/commands/ls.ts +22 -17
- package/src/commands/mkdir.ts +8 -18
- package/src/commands/rm.ts +2 -11
- package/src/commands/stat.ts +6 -12
- package/src/commands/touch.ts +9 -17
- package/src/commands/utils/add-link.ts +7 -5
- package/src/commands/utils/hamt-utils.ts +4 -3
- package/src/commands/utils/is-over-shard-threshold.ts +2 -1
- package/src/commands/utils/persist.ts +3 -2
- package/src/commands/utils/remove-link.ts +4 -3
- package/src/commands/utils/resolve.ts +1 -1
- package/src/constants.ts +2 -0
- package/src/index.ts +18 -9
- package/dist/src/commands/utils/constants.d.ts +0 -2
- package/dist/src/commands/utils/constants.d.ts.map +0 -1
- package/dist/src/commands/utils/constants.js +0 -2
- package/dist/src/commands/utils/constants.js.map +0 -1
- package/dist/typedoc-urls.json +0 -76
- package/src/commands/utils/constants.ts +0 -1
package/src/commands/cp.ts
CHANGED
|
@@ -1,25 +1,15 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
|
-
import { mergeOptions as mergeOpts } from '@libp2p/utils/merge-options'
|
|
3
2
|
import { InvalidParametersError } from '../errors.js'
|
|
4
3
|
import { addLink } from './utils/add-link.js'
|
|
5
4
|
import { cidToDirectory } from './utils/cid-to-directory.js'
|
|
6
5
|
import { cidToPBLink } from './utils/cid-to-pblink.js'
|
|
7
|
-
import { SHARD_SPLIT_THRESHOLD_BYTES } from './utils/constants.js'
|
|
8
6
|
import type { CpOptions } from '../index.js'
|
|
9
7
|
import type { GetStore, PutStore } from '../unixfs.js'
|
|
10
8
|
import type { CID } from 'multiformats/cid'
|
|
11
9
|
|
|
12
|
-
const mergeOptions = mergeOpts.bind({ ignoreUndefined: true })
|
|
13
10
|
const log = logger('helia:unixfs:cp')
|
|
14
11
|
|
|
15
|
-
const defaultOptions: CpOptions = {
|
|
16
|
-
force: false,
|
|
17
|
-
shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES
|
|
18
|
-
}
|
|
19
|
-
|
|
20
12
|
export async function cp (source: CID, target: CID, name: string, blockstore: GetStore & PutStore, options: Partial<CpOptions> = {}): Promise<CID> {
|
|
21
|
-
const opts: CpOptions = mergeOptions(defaultOptions, options)
|
|
22
|
-
|
|
23
13
|
if (name.includes('/')) {
|
|
24
14
|
throw new InvalidParametersError('Name must not have slashes')
|
|
25
15
|
}
|
|
@@ -28,16 +18,16 @@ export async function cp (source: CID, target: CID, name: string, blockstore: Ge
|
|
|
28
18
|
directory,
|
|
29
19
|
pblink
|
|
30
20
|
] = await Promise.all([
|
|
31
|
-
cidToDirectory(target, blockstore,
|
|
32
|
-
cidToPBLink(source, name, blockstore,
|
|
21
|
+
cidToDirectory(target, blockstore, options),
|
|
22
|
+
cidToPBLink(source, name, blockstore, options)
|
|
33
23
|
])
|
|
34
24
|
|
|
35
25
|
log('Adding %c as "%s" to %c', source, name, target)
|
|
36
26
|
|
|
37
27
|
const result = await addLink(directory, pblink, blockstore, {
|
|
38
|
-
allowOverwriting:
|
|
28
|
+
allowOverwriting: options.force,
|
|
39
29
|
cidVersion: target.version,
|
|
40
|
-
...
|
|
30
|
+
...options
|
|
41
31
|
})
|
|
42
32
|
|
|
43
33
|
return result.cid
|
package/src/commands/ls.ts
CHANGED
|
@@ -1,25 +1,33 @@
|
|
|
1
|
-
import { mergeOptions as mergeOpts } from '@libp2p/utils/merge-options'
|
|
2
1
|
import { exporter } from 'ipfs-unixfs-exporter'
|
|
3
2
|
import { NoContentError, NotADirectoryError } from '../errors.js'
|
|
4
3
|
import { resolve } from './utils/resolve.js'
|
|
5
4
|
import type { LsOptions } from '../index.js'
|
|
6
5
|
import type { GetStore } from '../unixfs.js'
|
|
7
|
-
import type { UnixFSEntry } from 'ipfs-unixfs-exporter'
|
|
6
|
+
import type { UnixFSEntry, UnixFSBasicEntry } from 'ipfs-unixfs-exporter'
|
|
8
7
|
import type { CID } from 'multiformats/cid'
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const resolved = await resolve(cid, opts.path, blockstore, opts)
|
|
19
|
-
const result = await exporter(resolved.cid, blockstore)
|
|
9
|
+
export function ls (cid: CID, blockstore: GetStore, options: Partial<LsOptions & { extended: false }>): AsyncIterable<UnixFSBasicEntry>
|
|
10
|
+
export function ls (cid: CID, blockstore: GetStore, options?: Partial<LsOptions>): AsyncIterable<UnixFSEntry>
|
|
11
|
+
export async function * ls (cid: CID, blockstore: GetStore, options: Partial<LsOptions> = {}): AsyncIterable<any> {
|
|
12
|
+
const resolved = await resolve(cid, options.path, blockstore, options)
|
|
13
|
+
const result = await exporter(resolved.cid, blockstore, {
|
|
14
|
+
...options,
|
|
15
|
+
extended: true
|
|
16
|
+
})
|
|
20
17
|
|
|
21
18
|
if (result.type === 'file' || result.type === 'raw') {
|
|
22
|
-
|
|
19
|
+
if (options.extended === false) {
|
|
20
|
+
const basic: UnixFSBasicEntry = {
|
|
21
|
+
name: result.name,
|
|
22
|
+
path: result.path,
|
|
23
|
+
cid: result.cid
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
yield basic
|
|
27
|
+
} else {
|
|
28
|
+
yield result
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
return
|
|
24
32
|
}
|
|
25
33
|
|
|
@@ -31,8 +39,5 @@ export async function * ls (cid: CID, blockstore: GetStore, options: Partial<LsO
|
|
|
31
39
|
throw new NotADirectoryError()
|
|
32
40
|
}
|
|
33
41
|
|
|
34
|
-
yield * result.content(
|
|
35
|
-
offset: options.offset,
|
|
36
|
-
length: options.length
|
|
37
|
-
})
|
|
42
|
+
yield * result.content(options)
|
|
38
43
|
}
|
package/src/commands/mkdir.ts
CHANGED
|
@@ -1,30 +1,20 @@
|
|
|
1
1
|
import * as dagPB from '@ipld/dag-pb'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
|
-
import { mergeOptions as mergeOpts } from '@libp2p/utils/merge-options'
|
|
4
3
|
import { UnixFS } from 'ipfs-unixfs'
|
|
5
4
|
import { exporter } from 'ipfs-unixfs-exporter'
|
|
6
5
|
import { CID } from 'multiformats/cid'
|
|
7
6
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
7
|
+
import { DEFAULT_CID_VERSION } from '../constants.ts'
|
|
8
8
|
import { InvalidParametersError, NotADirectoryError } from '../errors.js'
|
|
9
9
|
import { addLink } from './utils/add-link.js'
|
|
10
10
|
import { cidToDirectory } from './utils/cid-to-directory.js'
|
|
11
11
|
import { cidToPBLink } from './utils/cid-to-pblink.js'
|
|
12
|
-
import { SHARD_SPLIT_THRESHOLD_BYTES } from './utils/constants.js'
|
|
13
12
|
import type { MkdirOptions } from '../index.js'
|
|
14
13
|
import type { GetStore, PutStore } from '../unixfs.js'
|
|
15
14
|
|
|
16
|
-
const mergeOptions = mergeOpts.bind({ ignoreUndefined: true })
|
|
17
15
|
const log = logger('helia:unixfs:mkdir')
|
|
18
16
|
|
|
19
|
-
const defaultOptions: MkdirOptions = {
|
|
20
|
-
cidVersion: 1,
|
|
21
|
-
force: false,
|
|
22
|
-
shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES
|
|
23
|
-
}
|
|
24
|
-
|
|
25
17
|
export async function mkdir (parentCid: CID, dirname: string, blockstore: GetStore & PutStore, options: Partial<MkdirOptions> = {}): Promise<CID> {
|
|
26
|
-
const opts: MkdirOptions = mergeOptions(defaultOptions, options)
|
|
27
|
-
|
|
28
18
|
if (dirname.includes('/')) {
|
|
29
19
|
throw new InvalidParametersError('Path must not have slashes')
|
|
30
20
|
}
|
|
@@ -39,8 +29,8 @@ export async function mkdir (parentCid: CID, dirname: string, blockstore: GetSto
|
|
|
39
29
|
|
|
40
30
|
const metadata = new UnixFS({
|
|
41
31
|
type: 'directory',
|
|
42
|
-
mode:
|
|
43
|
-
mtime:
|
|
32
|
+
mode: options.mode,
|
|
33
|
+
mtime: options.mtime
|
|
44
34
|
})
|
|
45
35
|
|
|
46
36
|
// Persist the new parent PBNode
|
|
@@ -50,7 +40,7 @@ export async function mkdir (parentCid: CID, dirname: string, blockstore: GetSto
|
|
|
50
40
|
}
|
|
51
41
|
const buf = dagPB.encode(node)
|
|
52
42
|
const hash = await sha256.digest(buf)
|
|
53
|
-
const emptyDirCid = CID.create(
|
|
43
|
+
const emptyDirCid = CID.create(options.cidVersion ?? DEFAULT_CID_VERSION, dagPB.code, hash)
|
|
54
44
|
|
|
55
45
|
await blockstore.put(emptyDirCid, buf)
|
|
56
46
|
|
|
@@ -58,15 +48,15 @@ export async function mkdir (parentCid: CID, dirname: string, blockstore: GetSto
|
|
|
58
48
|
directory,
|
|
59
49
|
pblink
|
|
60
50
|
] = await Promise.all([
|
|
61
|
-
cidToDirectory(parentCid, blockstore,
|
|
62
|
-
cidToPBLink(emptyDirCid, dirname, blockstore,
|
|
51
|
+
cidToDirectory(parentCid, blockstore, options),
|
|
52
|
+
cidToPBLink(emptyDirCid, dirname, blockstore, options)
|
|
63
53
|
])
|
|
64
54
|
|
|
65
55
|
log('adding empty dir called %s to %c', dirname, parentCid)
|
|
66
56
|
|
|
67
57
|
const result = await addLink(directory, pblink, blockstore, {
|
|
68
|
-
...
|
|
69
|
-
allowOverwriting:
|
|
58
|
+
...options,
|
|
59
|
+
allowOverwriting: options.force
|
|
70
60
|
})
|
|
71
61
|
|
|
72
62
|
return result.cid
|
package/src/commands/rm.ts
CHANGED
|
@@ -1,33 +1,24 @@
|
|
|
1
1
|
import { logger } from '@libp2p/logger'
|
|
2
|
-
import { mergeOptions as mergeOpts } from '@libp2p/utils/merge-options'
|
|
3
2
|
import { InvalidParametersError } from '../errors.js'
|
|
4
3
|
import { cidToDirectory } from './utils/cid-to-directory.js'
|
|
5
|
-
import { SHARD_SPLIT_THRESHOLD_BYTES } from './utils/constants.js'
|
|
6
4
|
import { removeLink } from './utils/remove-link.js'
|
|
7
5
|
import type { RmOptions } from '../index.js'
|
|
8
6
|
import type { GetStore, PutStore } from '../unixfs.js'
|
|
9
7
|
import type { CID } from 'multiformats/cid'
|
|
10
8
|
|
|
11
|
-
const mergeOptions = mergeOpts.bind({ ignoreUndefined: true })
|
|
12
9
|
const log = logger('helia:unixfs:rm')
|
|
13
10
|
|
|
14
|
-
const defaultOptions: RmOptions = {
|
|
15
|
-
shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES
|
|
16
|
-
}
|
|
17
|
-
|
|
18
11
|
export async function rm (target: CID, name: string, blockstore: GetStore & PutStore, options: Partial<RmOptions> = {}): Promise<CID> {
|
|
19
|
-
const opts: RmOptions = mergeOptions(defaultOptions, options)
|
|
20
|
-
|
|
21
12
|
if (name.includes('/')) {
|
|
22
13
|
throw new InvalidParametersError('Name must not have slashes')
|
|
23
14
|
}
|
|
24
15
|
|
|
25
|
-
const directory = await cidToDirectory(target, blockstore,
|
|
16
|
+
const directory = await cidToDirectory(target, blockstore, options)
|
|
26
17
|
|
|
27
18
|
log('Removing %s from %c', name, target)
|
|
28
19
|
|
|
29
20
|
const result = await removeLink(directory, name, blockstore, {
|
|
30
|
-
...
|
|
21
|
+
...options,
|
|
31
22
|
cidVersion: target.version
|
|
32
23
|
})
|
|
33
24
|
|
package/src/commands/stat.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import * as dagPb from '@ipld/dag-pb'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
|
-
import { ScalableCuckooFilter } from '@libp2p/utils
|
|
4
|
-
import { mergeOptions as mergeOpts } from '@libp2p/utils/merge-options'
|
|
3
|
+
import { ScalableCuckooFilter } from '@libp2p/utils'
|
|
5
4
|
import { UnixFS } from 'ipfs-unixfs'
|
|
6
5
|
import { exporter } from 'ipfs-unixfs-exporter'
|
|
6
|
+
import toBuffer from 'it-to-buffer'
|
|
7
7
|
import * as raw from 'multiformats/codecs/raw'
|
|
8
8
|
import { InvalidPBNodeError, NotUnixFSError, UnknownError } from '../errors.js'
|
|
9
9
|
import { resolve } from './utils/resolve.js'
|
|
10
10
|
import type { ExtendedStatOptions, ExtendedDirectoryStats, ExtendedFileStats, StatOptions, DirectoryStats, FileStats, RawStats, ExtendedRawStats } from '../index.js'
|
|
11
11
|
import type { GetStore, HasStore } from '../unixfs.js'
|
|
12
|
-
import type { Filter } from '@libp2p/utils
|
|
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'
|
|
15
15
|
|
|
@@ -17,22 +17,16 @@ import type { CID } from 'multiformats/cid'
|
|
|
17
17
|
const DEFAULT_DIR_MODE = 0x755
|
|
18
18
|
const DEFAULT_FILE_MODE = 0x644
|
|
19
19
|
|
|
20
|
-
const mergeOptions = mergeOpts.bind({ ignoreUndefined: true })
|
|
21
20
|
const log = logger('helia:unixfs:stat')
|
|
22
21
|
|
|
23
|
-
const defaultOptions: StatOptions = {
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
22
|
export async function stat (cid: CID, blockstore: GetStore & HasStore, options?: StatOptions): Promise<FileStats | DirectoryStats | RawStats>
|
|
28
23
|
export async function stat (cid: CID, blockstore: GetStore & HasStore, options?: ExtendedStatOptions): Promise<ExtendedFileStats | ExtendedDirectoryStats | ExtendedRawStats>
|
|
29
24
|
export async function stat (cid: CID, blockstore: GetStore & HasStore, options: Partial<ExtendedStatOptions> = {}): Promise<any> {
|
|
30
|
-
const
|
|
31
|
-
const resolved = await resolve(cid, options.path, blockstore, opts)
|
|
25
|
+
const resolved = await resolve(cid, options.path, blockstore, options)
|
|
32
26
|
|
|
33
27
|
log('stat %c', resolved.cid)
|
|
34
28
|
|
|
35
|
-
const result = await exporter(resolved.cid, blockstore,
|
|
29
|
+
const result = await exporter(resolved.cid, blockstore, options)
|
|
36
30
|
|
|
37
31
|
if (result.type === 'raw') {
|
|
38
32
|
if (options.extended === true) {
|
|
@@ -130,7 +124,7 @@ async function inspectDag (cid: CID, blockstore: GetStore & HasStore, isFile: bo
|
|
|
130
124
|
const alreadyTraversed = filter.has(cid.bytes)
|
|
131
125
|
filter.add(cid.bytes)
|
|
132
126
|
|
|
133
|
-
const block = await blockstore.get(cid, options)
|
|
127
|
+
const block = await toBuffer(blockstore.get(cid, options))
|
|
134
128
|
results.blocks++
|
|
135
129
|
results.dagSize += BigInt(block.byteLength)
|
|
136
130
|
|
package/src/commands/touch.ts
CHANGED
|
@@ -1,41 +1,33 @@
|
|
|
1
1
|
import * as dagPB from '@ipld/dag-pb'
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
|
-
import { mergeOptions as mergeOpts } from '@libp2p/utils/merge-options'
|
|
4
3
|
import { UnixFS } from 'ipfs-unixfs'
|
|
5
4
|
import { recursive } from 'ipfs-unixfs-exporter'
|
|
6
5
|
import { importer } from 'ipfs-unixfs-importer'
|
|
7
6
|
import last from 'it-last'
|
|
8
7
|
import { pipe } from 'it-pipe'
|
|
8
|
+
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
12
|
import { InvalidPBNodeError, NotUnixFSError, UnknownError } from '../errors.js'
|
|
13
|
-
import { SHARD_SPLIT_THRESHOLD_BYTES } from './utils/constants.js'
|
|
14
13
|
import { persist } from './utils/persist.js'
|
|
15
14
|
import { resolve, updatePathCids } from './utils/resolve.js'
|
|
16
15
|
import type { TouchOptions } from '../index.js'
|
|
17
16
|
import type { GetStore, PutStore } from '../unixfs.js'
|
|
18
17
|
import type { PBNode, PBLink } from '@ipld/dag-pb'
|
|
19
18
|
|
|
20
|
-
const mergeOptions = mergeOpts.bind({ ignoreUndefined: true })
|
|
21
19
|
const log = logger('helia:unixfs:touch')
|
|
22
20
|
|
|
23
|
-
const defaultOptions: TouchOptions = {
|
|
24
|
-
recursive: false,
|
|
25
|
-
shardSplitThresholdBytes: SHARD_SPLIT_THRESHOLD_BYTES
|
|
26
|
-
}
|
|
27
|
-
|
|
28
21
|
export async function touch (cid: CID, blockstore: GetStore & PutStore, options: Partial<TouchOptions> = {}): Promise<CID> {
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const mtime = opts.mtime ?? {
|
|
22
|
+
const resolved = await resolve(cid, options.path, blockstore, options)
|
|
23
|
+
const mtime = options.mtime ?? {
|
|
32
24
|
secs: BigInt(Math.round(Date.now() / 1000)),
|
|
33
25
|
nsecs: 0
|
|
34
26
|
}
|
|
35
27
|
|
|
36
28
|
log('touch %c %o', resolved.cid, mtime)
|
|
37
29
|
|
|
38
|
-
if (
|
|
30
|
+
if (options.recursive) {
|
|
39
31
|
// recursively export from root CID, change perms of each entry then reimport
|
|
40
32
|
// but do not reimport files, only manipulate dag-pb nodes
|
|
41
33
|
const root = await pipe(
|
|
@@ -69,7 +61,7 @@ export async function touch (cid: CID, blockstore: GetStore & PutStore, options:
|
|
|
69
61
|
},
|
|
70
62
|
// @ts-expect-error blockstore types are incompatible
|
|
71
63
|
(source) => importer(source, blockstore, {
|
|
72
|
-
...
|
|
64
|
+
...options,
|
|
73
65
|
dagBuilder: async function * (source, block) {
|
|
74
66
|
for await (const entry of source) {
|
|
75
67
|
yield async function () {
|
|
@@ -78,7 +70,7 @@ export async function touch (cid: CID, blockstore: GetStore & PutStore, options:
|
|
|
78
70
|
|
|
79
71
|
const buf = dagPB.encode(node)
|
|
80
72
|
const updatedCid = await persist(buf, block, {
|
|
81
|
-
...
|
|
73
|
+
...options,
|
|
82
74
|
cidVersion: cid.version
|
|
83
75
|
})
|
|
84
76
|
|
|
@@ -105,10 +97,10 @@ export async function touch (cid: CID, blockstore: GetStore & PutStore, options:
|
|
|
105
97
|
throw new UnknownError(`Could not chmod ${resolved.cid.toString()}`)
|
|
106
98
|
}
|
|
107
99
|
|
|
108
|
-
return updatePathCids(root.cid, resolved, blockstore,
|
|
100
|
+
return updatePathCids(root.cid, resolved, blockstore, options)
|
|
109
101
|
}
|
|
110
102
|
|
|
111
|
-
const block = await blockstore.get(resolved.cid, options)
|
|
103
|
+
const block = await toBuffer(blockstore.get(resolved.cid, options))
|
|
112
104
|
let metadata: UnixFS
|
|
113
105
|
let links: PBLink[] = []
|
|
114
106
|
|
|
@@ -136,5 +128,5 @@ export async function touch (cid: CID, blockstore: GetStore & PutStore, options:
|
|
|
136
128
|
|
|
137
129
|
await blockstore.put(updatedCid, updatedBlock)
|
|
138
130
|
|
|
139
|
-
return updatePathCids(updatedCid, resolved, blockstore,
|
|
131
|
+
return updatePathCids(updatedCid, resolved, blockstore, options)
|
|
140
132
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
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 toBuffer from 'it-to-buffer'
|
|
4
5
|
import { CID } from 'multiformats/cid'
|
|
5
6
|
import { sha256 } from 'multiformats/hashes/sha2'
|
|
6
7
|
// @ts-expect-error no types
|
|
7
8
|
import SparseArray from 'sparse-array'
|
|
8
9
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
10
|
+
import { DEFAULT_SHARD_SPLIT_THRESHOLD_BYTES } from '../../constants.ts'
|
|
9
11
|
import { AlreadyExistsError, InvalidParametersError, InvalidPBNodeError } from '../../errors.js'
|
|
10
12
|
import { wrapHash } from './consumable-hash.js'
|
|
11
13
|
import { hamtBucketBits, hamtHashFn } from './hamt-constants.js'
|
|
@@ -31,9 +33,9 @@ export interface AddLinkResult {
|
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
export interface AddLinkOptions extends AbortOptions {
|
|
34
|
-
allowOverwriting
|
|
35
|
-
shardSplitThresholdBytes
|
|
36
|
-
cidVersion
|
|
36
|
+
allowOverwriting?: boolean
|
|
37
|
+
shardSplitThresholdBytes?: number
|
|
38
|
+
cidVersion?: Version
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
export async function addLink (parent: Directory, child: Required<PBLink>, blockstore: GetStore & PutStore, options: AddLinkOptions): Promise<AddLinkResult> {
|
|
@@ -53,12 +55,12 @@ export async function addLink (parent: Directory, child: Required<PBLink>, block
|
|
|
53
55
|
|
|
54
56
|
const result = await addToDirectory(parent, child, blockstore, options)
|
|
55
57
|
|
|
56
|
-
if (await isOverShardThreshold(result.node, blockstore, options.shardSplitThresholdBytes, options)) {
|
|
58
|
+
if (await isOverShardThreshold(result.node, blockstore, options.shardSplitThresholdBytes ?? DEFAULT_SHARD_SPLIT_THRESHOLD_BYTES, options)) {
|
|
57
59
|
log('converting directory to sharded directory')
|
|
58
60
|
|
|
59
61
|
const converted = await convertToShardedDirectory(result, blockstore)
|
|
60
62
|
result.cid = converted.cid
|
|
61
|
-
result.node = dagPB.decode(await blockstore.get(converted.cid, options))
|
|
63
|
+
result.node = dagPB.decode(await toBuffer(blockstore.get(converted.cid, options)))
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
return result
|
|
@@ -2,6 +2,7 @@ import * as dagPB from '@ipld/dag-pb'
|
|
|
2
2
|
import { logger } from '@libp2p/logger'
|
|
3
3
|
import { UnixFS } from 'ipfs-unixfs'
|
|
4
4
|
import last from 'it-last'
|
|
5
|
+
import toBuffer from 'it-to-buffer'
|
|
5
6
|
// @ts-expect-error no types
|
|
6
7
|
import SparseArray from 'sparse-array'
|
|
7
8
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
@@ -25,7 +26,7 @@ import type { CID, Version } from 'multiformats/cid'
|
|
|
25
26
|
const log = logger('helia:unixfs:commands:utils:hamt-utils')
|
|
26
27
|
|
|
27
28
|
export interface UpdateHamtDirectoryOptions extends AbortOptions {
|
|
28
|
-
cidVersion
|
|
29
|
+
cidVersion?: Version
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
export const toPrefix = (position: number): string => {
|
|
@@ -39,7 +40,7 @@ export const toPrefix = (position: number): string => {
|
|
|
39
40
|
export interface CreateShardOptions {
|
|
40
41
|
mtime?: Mtime
|
|
41
42
|
mode?: number
|
|
42
|
-
cidVersion
|
|
43
|
+
cidVersion?: Version
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export const createShard = async (blockstore: PutStore, contents: Array<{ name: string, size: bigint, cid: CID }>, options: CreateShardOptions): Promise<ImportResult> => {
|
|
@@ -151,7 +152,7 @@ export const recreateShardedDirectory = async (cid: CID, fileName: string, block
|
|
|
151
152
|
|
|
152
153
|
// descend the HAMT, loading each layer as we head towards the target child
|
|
153
154
|
while (true) {
|
|
154
|
-
const block = await blockstore.get(cid, options)
|
|
155
|
+
const block = await toBuffer(blockstore.get(cid, options))
|
|
155
156
|
const node = dagPB.decode(block)
|
|
156
157
|
const children = new SparseArray()
|
|
157
158
|
const index = await hash.take(hamtBucketBits)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as dagPb from '@ipld/dag-pb'
|
|
2
2
|
import { UnixFS } from 'ipfs-unixfs'
|
|
3
|
+
import toBuffer from 'it-to-buffer'
|
|
3
4
|
import { CID_V0, CID_V1 } from './dir-sharded.js'
|
|
4
5
|
import type { GetStore } from '../../unixfs.js'
|
|
5
6
|
import type { PBNode } from '@ipld/dag-pb'
|
|
@@ -68,7 +69,7 @@ async function estimateShardSize (node: PBNode, current: number, max: number, bl
|
|
|
68
69
|
current += link.Hash.bytes.byteLength
|
|
69
70
|
|
|
70
71
|
if (link.Hash.code === dagPb.code) {
|
|
71
|
-
const block = await blockstore.get(link.Hash, options)
|
|
72
|
+
const block = await toBuffer(blockstore.get(link.Hash, options))
|
|
72
73
|
const node = dagPb.decode(block)
|
|
73
74
|
|
|
74
75
|
current += await estimateShardSize(node, current, max, blockstore, options)
|
|
@@ -1,13 +1,14 @@
|
|
|
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 { DEFAULT_CID_VERSION } from '../../constants.ts'
|
|
4
5
|
import type { PutStore } from '../../unixfs.js'
|
|
5
6
|
import type { Version as CIDVersion } from 'multiformats/cid'
|
|
6
7
|
import type { BlockCodec } from 'multiformats/codecs/interface'
|
|
7
8
|
|
|
8
9
|
export interface PersistOptions {
|
|
9
10
|
codec?: BlockCodec<any, any>
|
|
10
|
-
cidVersion
|
|
11
|
+
cidVersion?: CIDVersion
|
|
11
12
|
signal?: AbortSignal
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -17,7 +18,7 @@ export const persist = async (buffer: Uint8Array, blockstore: PutStore, options:
|
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
const multihash = await sha256.digest(buffer)
|
|
20
|
-
const cid = CID.create(options.cidVersion, options.codec.code, multihash)
|
|
21
|
+
const cid = CID.create(options.cidVersion ?? DEFAULT_CID_VERSION, options.codec.code, multihash)
|
|
21
22
|
|
|
22
23
|
await blockstore.put(cid, buffer, {
|
|
23
24
|
...options,
|
|
@@ -2,6 +2,7 @@ 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 { DEFAULT_SHARD_SPLIT_THRESHOLD_BYTES } from '../../constants.ts'
|
|
5
6
|
import { InvalidParametersError, InvalidPBNodeError } from '../../errors.js'
|
|
6
7
|
import {
|
|
7
8
|
recreateShardedDirectory,
|
|
@@ -20,8 +21,8 @@ import type { CID, Version } from 'multiformats/cid'
|
|
|
20
21
|
const log = logger('helia:unixfs:utils:remove-link')
|
|
21
22
|
|
|
22
23
|
export interface RmLinkOptions extends AbortOptions {
|
|
23
|
-
shardSplitThresholdBytes
|
|
24
|
-
cidVersion
|
|
24
|
+
shardSplitThresholdBytes?: number
|
|
25
|
+
cidVersion?: Version
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
export interface RemoveLinkResult {
|
|
@@ -41,7 +42,7 @@ export async function removeLink (parent: Directory, name: string, blockstore: P
|
|
|
41
42
|
|
|
42
43
|
const result = await removeFromShardedDirectory(parent, name, blockstore, options)
|
|
43
44
|
|
|
44
|
-
if (!(await isOverShardThreshold(result.node, blockstore, options.shardSplitThresholdBytes, options))) {
|
|
45
|
+
if (!(await isOverShardThreshold(result.node, blockstore, options.shardSplitThresholdBytes ?? DEFAULT_SHARD_SPLIT_THRESHOLD_BYTES, options))) {
|
|
45
46
|
log('converting shard to flat directory %c', parent.cid)
|
|
46
47
|
|
|
47
48
|
return convertToFlatDirectory(result, blockstore, options)
|
package/src/constants.ts
ADDED
package/src/index.ts
CHANGED
|
@@ -76,12 +76,12 @@
|
|
|
76
76
|
*/
|
|
77
77
|
|
|
78
78
|
import { UnixFS as UnixFSClass } from './unixfs.js'
|
|
79
|
-
import type { GetBlockProgressEvents, PutBlockProgressEvents } from '@helia/interface/blocks'
|
|
79
|
+
import type { GetBlockProgressEvents, ProviderOptions, PutBlockProgressEvents } from '@helia/interface/blocks'
|
|
80
80
|
import type { AbortOptions } from '@libp2p/interface'
|
|
81
|
-
import type { Filter } from '@libp2p/utils
|
|
81
|
+
import type { Filter } from '@libp2p/utils'
|
|
82
82
|
import type { Blockstore } from 'interface-blockstore'
|
|
83
83
|
import type { Mtime, UnixFS as IPFSUnixFS } from 'ipfs-unixfs'
|
|
84
|
-
import type { ExporterProgressEvents, UnixFSEntry } from 'ipfs-unixfs-exporter'
|
|
84
|
+
import type { ExporterProgressEvents, UnixFSEntry, UnixFSBasicEntry } from 'ipfs-unixfs-exporter'
|
|
85
85
|
import type { ByteStream, DirectoryCandidate, ImportCandidateStream, ImporterOptions, ImporterProgressEvents, ImportResult, ImportContent } from 'ipfs-unixfs-importer'
|
|
86
86
|
import type { CID, Version } from 'multiformats/cid'
|
|
87
87
|
import type { ProgressOptions } from 'progress-events'
|
|
@@ -112,7 +112,7 @@ export type GetEvents = GetBlockProgressEvents
|
|
|
112
112
|
/**
|
|
113
113
|
* Options to pass to the cat command
|
|
114
114
|
*/
|
|
115
|
-
export interface CatOptions extends AbortOptions, ProgressOptions<GetEvents
|
|
115
|
+
export interface CatOptions extends AbortOptions, ProgressOptions<GetEvents>, ProviderOptions {
|
|
116
116
|
/**
|
|
117
117
|
* Start reading the file at this offset
|
|
118
118
|
*/
|
|
@@ -138,7 +138,7 @@ export interface CatOptions extends AbortOptions, ProgressOptions<GetEvents> {
|
|
|
138
138
|
/**
|
|
139
139
|
* Options to pass to the chmod command
|
|
140
140
|
*/
|
|
141
|
-
export interface ChmodOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents
|
|
141
|
+
export interface ChmodOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents>, ProviderOptions {
|
|
142
142
|
/**
|
|
143
143
|
* If the target of the operation is a directory and this is true,
|
|
144
144
|
* apply the new mode to all directory contents
|
|
@@ -166,7 +166,7 @@ export interface ChmodOptions extends AbortOptions, ProgressOptions<GetEvents |
|
|
|
166
166
|
/**
|
|
167
167
|
* Options to pass to the cp command
|
|
168
168
|
*/
|
|
169
|
-
export interface CpOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents
|
|
169
|
+
export interface CpOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents>, ProviderOptions {
|
|
170
170
|
/**
|
|
171
171
|
* If true, allow overwriting existing directory entries (default: false)
|
|
172
172
|
*/
|
|
@@ -210,12 +210,20 @@ export interface LsOptions extends AbortOptions, ProgressOptions<GetEvents> {
|
|
|
210
210
|
* missing from the local store. (default: false)
|
|
211
211
|
*/
|
|
212
212
|
offline?: boolean
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* If true, including UnixFS metadata in the output - nb. this will resolve
|
|
216
|
+
* the root node of every encountered filesystem entry
|
|
217
|
+
*
|
|
218
|
+
* @default true
|
|
219
|
+
*/
|
|
220
|
+
extended?: boolean
|
|
213
221
|
}
|
|
214
222
|
|
|
215
223
|
/**
|
|
216
224
|
* Options to pass to the mkdir command
|
|
217
225
|
*/
|
|
218
|
-
export interface MkdirOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents
|
|
226
|
+
export interface MkdirOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents>, ProviderOptions {
|
|
219
227
|
/**
|
|
220
228
|
* The CID version to create the new directory with - defaults to the same
|
|
221
229
|
* version as the containing directory
|
|
@@ -253,7 +261,7 @@ export interface MkdirOptions extends AbortOptions, ProgressOptions<GetEvents |
|
|
|
253
261
|
/**
|
|
254
262
|
* Options to pass to the rm command
|
|
255
263
|
*/
|
|
256
|
-
export interface RmOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents
|
|
264
|
+
export interface RmOptions extends AbortOptions, ProgressOptions<GetEvents | PutBlockProgressEvents>, ProviderOptions {
|
|
257
265
|
/**
|
|
258
266
|
* DAGs with a root block larger than this value will be sharded. Blocks
|
|
259
267
|
* smaller than this value will be regular UnixFS directories.
|
|
@@ -270,7 +278,7 @@ export interface RmOptions extends AbortOptions, ProgressOptions<GetEvents | Put
|
|
|
270
278
|
/**
|
|
271
279
|
* Options to pass to the stat command
|
|
272
280
|
*/
|
|
273
|
-
export interface StatOptions extends AbortOptions, ProgressOptions<GetEvents
|
|
281
|
+
export interface StatOptions extends AbortOptions, ProgressOptions<GetEvents>, ProviderOptions {
|
|
274
282
|
/**
|
|
275
283
|
* An optional path to allow getting stats of paths inside directories
|
|
276
284
|
*/
|
|
@@ -644,6 +652,7 @@ export interface UnixFS {
|
|
|
644
652
|
* ```
|
|
645
653
|
*/
|
|
646
654
|
ls(cid: CID, options?: Partial<LsOptions>): AsyncIterable<UnixFSEntry>
|
|
655
|
+
ls(cid: CID, options: Partial<LsOptions> & { extended: false }): AsyncIterable<UnixFSBasicEntry>
|
|
647
656
|
|
|
648
657
|
/**
|
|
649
658
|
* Make a new directory under an existing directory.
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/commands/utils/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,SAAS,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../src/commands/utils/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAA"}
|