@helia/unixfs 7.0.4 → 7.1.0-080e4f91
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 +23 -17
- 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 +9 -8
- package/dist/src/commands/utils/hamt-utils.d.ts.map +1 -1
- package/dist/src/commands/utils/hamt-utils.js +18 -16
- 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 +58 -13
- package/dist/src/commands/utils/is-over-shard-threshold.js.map +1 -1
- package/dist/src/commands/utils/persist.d.ts +3 -3
- package/dist/src/commands/utils/persist.d.ts.map +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 +10 -9
- 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 +24 -54
- 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 +5 -6
- 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 +30 -24
- 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 +29 -23
- package/src/commands/utils/is-over-shard-threshold.ts +88 -13
- package/src/commands/utils/persist.ts +3 -3
- package/src/commands/utils/remove-link.ts +17 -17
- package/src/commands/utils/resolve.ts +5 -5
- package/src/index.ts +25 -61
- 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/dist/typedoc-urls.json
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"AlreadyExistsError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.AlreadyExistsError.html",
|
|
3
|
-
"./errors:AlreadyExistsError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.AlreadyExistsError.html",
|
|
4
|
-
"DoesNotExistError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.DoesNotExistError.html",
|
|
5
|
-
"./errors:DoesNotExistError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.DoesNotExistError.html",
|
|
6
|
-
"InvalidParametersError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.InvalidParametersError.html",
|
|
7
|
-
"./errors:InvalidParametersError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.InvalidParametersError.html",
|
|
8
|
-
"InvalidPBNodeError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.InvalidPBNodeError.html",
|
|
9
|
-
"./errors:InvalidPBNodeError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.InvalidPBNodeError.html",
|
|
10
|
-
"NoContentError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NoContentError.html",
|
|
11
|
-
"./errors:NoContentError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NoContentError.html",
|
|
12
|
-
"NotADirectoryError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NotADirectoryError.html",
|
|
13
|
-
"./errors:NotADirectoryError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NotADirectoryError.html",
|
|
14
|
-
"NotAFileError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NotAFileError.html",
|
|
15
|
-
"./errors:NotAFileError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NotAFileError.html",
|
|
16
|
-
"NotUnixFSError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NotUnixFSError.html",
|
|
17
|
-
"./errors:NotUnixFSError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.NotUnixFSError.html",
|
|
18
|
-
"UnixFSError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.UnixFSError.html",
|
|
19
|
-
"./errors:UnixFSError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.UnixFSError.html",
|
|
20
|
-
"UnknownError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.UnknownError.html",
|
|
21
|
-
"./errors:UnknownError": "https://ipfs.github.io/helia/classes/_helia_unixfs.errors.UnknownError.html",
|
|
22
|
-
"AddOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.AddOptions.html",
|
|
23
|
-
".:AddOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.AddOptions.html",
|
|
24
|
-
"CatOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.CatOptions.html",
|
|
25
|
-
".:CatOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.CatOptions.html",
|
|
26
|
-
"ChmodOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ChmodOptions.html",
|
|
27
|
-
".:ChmodOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ChmodOptions.html",
|
|
28
|
-
"CpOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.CpOptions.html",
|
|
29
|
-
".:CpOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.CpOptions.html",
|
|
30
|
-
"DirectoryStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.DirectoryStats.html",
|
|
31
|
-
".:DirectoryStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.DirectoryStats.html",
|
|
32
|
-
"ExtendedDirectoryStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ExtendedDirectoryStats.html",
|
|
33
|
-
".:ExtendedDirectoryStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ExtendedDirectoryStats.html",
|
|
34
|
-
"ExtendedFileStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ExtendedFileStats.html",
|
|
35
|
-
".:ExtendedFileStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ExtendedFileStats.html",
|
|
36
|
-
"ExtendedRawStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ExtendedRawStats.html",
|
|
37
|
-
".:ExtendedRawStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ExtendedRawStats.html",
|
|
38
|
-
"ExtendedStatOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ExtendedStatOptions.html",
|
|
39
|
-
".:ExtendedStatOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ExtendedStatOptions.html",
|
|
40
|
-
"ExtendedStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ExtendedStats.html",
|
|
41
|
-
".:ExtendedStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.ExtendedStats.html",
|
|
42
|
-
"FileCandidate": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.FileCandidate.html",
|
|
43
|
-
".:FileCandidate": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.FileCandidate.html",
|
|
44
|
-
"FileStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.FileStats.html",
|
|
45
|
-
".:FileStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.FileStats.html",
|
|
46
|
-
"GlobSourceOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.GlobSourceOptions.html",
|
|
47
|
-
"GlobSourceResult": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.GlobSourceResult.html",
|
|
48
|
-
"LsOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.LsOptions.html",
|
|
49
|
-
".:LsOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.LsOptions.html",
|
|
50
|
-
"MkdirOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.MkdirOptions.html",
|
|
51
|
-
".:MkdirOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.MkdirOptions.html",
|
|
52
|
-
"RawStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.RawStats.html",
|
|
53
|
-
".:RawStats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.RawStats.html",
|
|
54
|
-
"RmOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.RmOptions.html",
|
|
55
|
-
".:RmOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.RmOptions.html",
|
|
56
|
-
"StatOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.StatOptions.html",
|
|
57
|
-
".:StatOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.StatOptions.html",
|
|
58
|
-
"Stats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.Stats.html",
|
|
59
|
-
".:Stats": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.Stats.html",
|
|
60
|
-
"TouchOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.TouchOptions.html",
|
|
61
|
-
".:TouchOptions": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.TouchOptions.html",
|
|
62
|
-
"UnixFS": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFS.html",
|
|
63
|
-
".:UnixFS": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFS.html",
|
|
64
|
-
"UnixFSComponents": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFSComponents.html",
|
|
65
|
-
".:UnixFSComponents": "https://ipfs.github.io/helia/interfaces/_helia_unixfs.index.UnixFSComponents.html",
|
|
66
|
-
"AddEvents": "https://ipfs.github.io/helia/types/_helia_unixfs.index.AddEvents.html",
|
|
67
|
-
".:AddEvents": "https://ipfs.github.io/helia/types/_helia_unixfs.index.AddEvents.html",
|
|
68
|
-
"AddFileOptions": "https://ipfs.github.io/helia/types/_helia_unixfs.index.AddFileOptions.html",
|
|
69
|
-
".:AddFileOptions": "https://ipfs.github.io/helia/types/_helia_unixfs.index.AddFileOptions.html",
|
|
70
|
-
"GetEvents": "https://ipfs.github.io/helia/types/_helia_unixfs.index.GetEvents.html",
|
|
71
|
-
".:GetEvents": "https://ipfs.github.io/helia/types/_helia_unixfs.index.GetEvents.html",
|
|
72
|
-
"globSource": "https://ipfs.github.io/helia/functions/_helia_unixfs.index.globSource.html",
|
|
73
|
-
"unixfs": "https://ipfs.github.io/helia/functions/_helia_unixfs.index.unixfs.html",
|
|
74
|
-
".:unixfs": "https://ipfs.github.io/helia/functions/_helia_unixfs.index.unixfs.html",
|
|
75
|
-
"urlSource": "https://ipfs.github.io/helia/functions/_helia_unixfs.index.urlSource.html"
|
|
76
|
-
}
|
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import { encode, prepare } from '@ipld/dag-pb'
|
|
2
|
-
import { createHAMT, Bucket } from 'hamt-sharding'
|
|
3
|
-
import { UnixFS } from 'ipfs-unixfs'
|
|
4
|
-
import { CID } from 'multiformats/cid'
|
|
5
|
-
import {
|
|
6
|
-
hamtHashCode,
|
|
7
|
-
hamtHashFn
|
|
8
|
-
} from './hamt-constants.js'
|
|
9
|
-
import { persist } from './persist.js'
|
|
10
|
-
import type { PersistOptions } from './persist.js'
|
|
11
|
-
import type { PutStore } from '../../unixfs.js'
|
|
12
|
-
import type { PBLink } from '@ipld/dag-pb'
|
|
13
|
-
import type { BucketChild } from 'hamt-sharding'
|
|
14
|
-
import type { Mtime } from 'ipfs-unixfs'
|
|
15
|
-
|
|
16
|
-
interface InProgressImportResult extends ImportResult {
|
|
17
|
-
single?: boolean
|
|
18
|
-
originalPath?: string
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
interface ImportResult {
|
|
22
|
-
cid: CID
|
|
23
|
-
size: bigint
|
|
24
|
-
path?: string
|
|
25
|
-
unixfs?: UnixFS
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
interface DirProps {
|
|
29
|
-
root: boolean
|
|
30
|
-
dir: boolean
|
|
31
|
-
path: string
|
|
32
|
-
dirty: boolean
|
|
33
|
-
flat: boolean
|
|
34
|
-
parent?: Dir
|
|
35
|
-
parentKey?: string
|
|
36
|
-
unixfs?: UnixFS
|
|
37
|
-
mode?: number
|
|
38
|
-
mtime?: Mtime
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
abstract class Dir {
|
|
42
|
-
public options: PersistOptions
|
|
43
|
-
public root: boolean
|
|
44
|
-
public dir: boolean
|
|
45
|
-
public path: string
|
|
46
|
-
public dirty: boolean
|
|
47
|
-
public flat: boolean
|
|
48
|
-
public parent?: Dir
|
|
49
|
-
public parentKey?: string
|
|
50
|
-
public unixfs?: UnixFS
|
|
51
|
-
public mode?: number
|
|
52
|
-
public mtime?: Mtime
|
|
53
|
-
public cid?: CID
|
|
54
|
-
public size?: number
|
|
55
|
-
public nodeSize?: number
|
|
56
|
-
|
|
57
|
-
constructor (props: DirProps, options: PersistOptions) {
|
|
58
|
-
this.options = options ?? {}
|
|
59
|
-
|
|
60
|
-
this.root = props.root
|
|
61
|
-
this.dir = props.dir
|
|
62
|
-
this.path = props.path
|
|
63
|
-
this.dirty = props.dirty
|
|
64
|
-
this.flat = props.flat
|
|
65
|
-
this.parent = props.parent
|
|
66
|
-
this.parentKey = props.parentKey
|
|
67
|
-
this.unixfs = props.unixfs
|
|
68
|
-
this.mode = props.mode
|
|
69
|
-
this.mtime = props.mtime
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
abstract put (name: string, value: InProgressImportResult | Dir): Promise<void>
|
|
73
|
-
abstract get (name: string): Promise<InProgressImportResult | Dir | undefined>
|
|
74
|
-
abstract eachChildSeries (): AsyncIterable<{ key: string, child: InProgressImportResult | Dir }>
|
|
75
|
-
abstract flush (blockstore: PutStore): AsyncGenerator<ImportResult>
|
|
76
|
-
abstract estimateNodeSize (): number
|
|
77
|
-
abstract childCount (): number
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export class DirSharded extends Dir {
|
|
81
|
-
public _bucket: Bucket<InProgressImportResult | Dir>
|
|
82
|
-
|
|
83
|
-
constructor (props: DirProps, options: PersistOptions) {
|
|
84
|
-
super(props, options)
|
|
85
|
-
|
|
86
|
-
this._bucket = createHAMT({
|
|
87
|
-
hashFn: hamtHashFn,
|
|
88
|
-
bits: 8
|
|
89
|
-
})
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
async put (name: string, value: InProgressImportResult | Dir): Promise<void> {
|
|
93
|
-
this.cid = undefined
|
|
94
|
-
this.size = undefined
|
|
95
|
-
this.nodeSize = undefined
|
|
96
|
-
|
|
97
|
-
await this._bucket.put(name, value)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
async get (name: string): Promise<InProgressImportResult | Dir | undefined> {
|
|
101
|
-
return this._bucket.get(name)
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
childCount (): number {
|
|
105
|
-
return this._bucket.leafCount()
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
directChildrenCount (): number {
|
|
109
|
-
return this._bucket.childrenCount()
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
onlyChild (): Bucket<InProgressImportResult | Dir> | BucketChild<InProgressImportResult | Dir> {
|
|
113
|
-
return this._bucket.onlyChild()
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
async * eachChildSeries (): AsyncGenerator<{ key: string, child: InProgressImportResult | Dir }> {
|
|
117
|
-
for (const { key, value } of this._bucket.eachLeafSeries()) {
|
|
118
|
-
yield {
|
|
119
|
-
key,
|
|
120
|
-
child: value
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
estimateNodeSize (): number {
|
|
126
|
-
if (this.nodeSize !== undefined) {
|
|
127
|
-
return this.nodeSize
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
this.nodeSize = calculateSize(this._bucket, this, this.options)
|
|
131
|
-
|
|
132
|
-
return this.nodeSize
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async * flush (blockstore: PutStore): AsyncGenerator<ImportResult> {
|
|
136
|
-
for await (const entry of flush(this._bucket, blockstore, this, this.options)) {
|
|
137
|
-
yield {
|
|
138
|
-
...entry,
|
|
139
|
-
path: this.path
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async function * flush (bucket: Bucket<Dir | InProgressImportResult>, blockstore: PutStore, shardRoot: DirSharded | null, options: PersistOptions): AsyncIterable<ImportResult> {
|
|
146
|
-
const children = bucket._children
|
|
147
|
-
const links: PBLink[] = []
|
|
148
|
-
let childrenSize = 0n
|
|
149
|
-
|
|
150
|
-
for (let i = 0; i < children.length; i++) {
|
|
151
|
-
const child = children.get(i)
|
|
152
|
-
|
|
153
|
-
if (child == null) {
|
|
154
|
-
continue
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const labelPrefix = i.toString(16).toUpperCase().padStart(2, '0')
|
|
158
|
-
|
|
159
|
-
if (child instanceof Bucket) {
|
|
160
|
-
let shard
|
|
161
|
-
|
|
162
|
-
for await (const subShard of flush(child, blockstore, null, options)) {
|
|
163
|
-
shard = subShard
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (shard == null) {
|
|
167
|
-
throw new Error('Could not flush sharded directory, no sub-shard found')
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
links.push({
|
|
171
|
-
Name: labelPrefix,
|
|
172
|
-
Tsize: Number(shard.size),
|
|
173
|
-
Hash: shard.cid
|
|
174
|
-
})
|
|
175
|
-
childrenSize += shard.size
|
|
176
|
-
} else if (isDir(child.value)) {
|
|
177
|
-
const dir = child.value
|
|
178
|
-
let flushedDir: ImportResult | undefined
|
|
179
|
-
|
|
180
|
-
for await (const entry of dir.flush(blockstore)) {
|
|
181
|
-
flushedDir = entry
|
|
182
|
-
|
|
183
|
-
yield flushedDir
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (flushedDir == null) {
|
|
187
|
-
throw new Error('Did not flush dir')
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
const label = labelPrefix + child.key
|
|
191
|
-
links.push({
|
|
192
|
-
Name: label,
|
|
193
|
-
Tsize: Number(flushedDir.size),
|
|
194
|
-
Hash: flushedDir.cid
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
childrenSize += flushedDir.size
|
|
198
|
-
} else {
|
|
199
|
-
const value = child.value
|
|
200
|
-
|
|
201
|
-
if (value.cid == null) {
|
|
202
|
-
continue
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const label = labelPrefix + child.key
|
|
206
|
-
const size = value.size
|
|
207
|
-
|
|
208
|
-
links.push({
|
|
209
|
-
Name: label,
|
|
210
|
-
Tsize: Number(size),
|
|
211
|
-
Hash: value.cid
|
|
212
|
-
})
|
|
213
|
-
childrenSize += BigInt(size ?? 0)
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// go-ipfs uses little endian, that's why we have to
|
|
218
|
-
// reverse the bit field before storing it
|
|
219
|
-
const data = Uint8Array.from(children.bitField().reverse())
|
|
220
|
-
const dir = new UnixFS({
|
|
221
|
-
type: 'hamt-sharded-directory',
|
|
222
|
-
data,
|
|
223
|
-
fanout: BigInt(bucket.tableSize()),
|
|
224
|
-
hashType: hamtHashCode,
|
|
225
|
-
mtime: shardRoot?.mtime,
|
|
226
|
-
mode: shardRoot?.mode
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
const node = {
|
|
230
|
-
Data: dir.marshal(),
|
|
231
|
-
Links: links
|
|
232
|
-
}
|
|
233
|
-
const buffer = encode(prepare(node))
|
|
234
|
-
const cid = await persist(buffer, blockstore, options)
|
|
235
|
-
const size = BigInt(buffer.byteLength) + childrenSize
|
|
236
|
-
|
|
237
|
-
yield {
|
|
238
|
-
cid,
|
|
239
|
-
unixfs: dir,
|
|
240
|
-
size
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function isDir (obj: any): obj is Dir {
|
|
245
|
-
return typeof obj.flush === 'function'
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
function calculateSize (bucket: Bucket<any>, shardRoot: DirSharded | null, options: PersistOptions): number {
|
|
249
|
-
const children = bucket._children
|
|
250
|
-
const links: PBLink[] = []
|
|
251
|
-
|
|
252
|
-
for (let i = 0; i < children.length; i++) {
|
|
253
|
-
const child = children.get(i)
|
|
254
|
-
|
|
255
|
-
if (child == null) {
|
|
256
|
-
continue
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
const labelPrefix = i.toString(16).toUpperCase().padStart(2, '0')
|
|
260
|
-
|
|
261
|
-
if (child instanceof Bucket) {
|
|
262
|
-
const size = calculateSize(child, null, options)
|
|
263
|
-
|
|
264
|
-
links.push({
|
|
265
|
-
Name: labelPrefix,
|
|
266
|
-
Tsize: Number(size),
|
|
267
|
-
Hash: options.cidVersion === 0 ? CID_V0 : CID_V1
|
|
268
|
-
})
|
|
269
|
-
} else if (typeof child.value.flush === 'function') {
|
|
270
|
-
const dir = child.value
|
|
271
|
-
const size = dir.nodeSize()
|
|
272
|
-
|
|
273
|
-
links.push({
|
|
274
|
-
Name: labelPrefix + child.key,
|
|
275
|
-
Tsize: Number(size),
|
|
276
|
-
Hash: options.cidVersion === 0 ? CID_V0 : CID_V1
|
|
277
|
-
})
|
|
278
|
-
} else {
|
|
279
|
-
const value = child.value
|
|
280
|
-
|
|
281
|
-
if (value.cid == null) {
|
|
282
|
-
continue
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const label = labelPrefix + child.key
|
|
286
|
-
const size = value.size
|
|
287
|
-
|
|
288
|
-
links.push({
|
|
289
|
-
Name: label,
|
|
290
|
-
Tsize: Number(size),
|
|
291
|
-
Hash: value.cid
|
|
292
|
-
})
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
// go-ipfs uses little endian, that's why we have to
|
|
297
|
-
// reverse the bit field before storing it
|
|
298
|
-
const data = Uint8Array.from(children.bitField().reverse())
|
|
299
|
-
const dir = new UnixFS({
|
|
300
|
-
type: 'hamt-sharded-directory',
|
|
301
|
-
data,
|
|
302
|
-
fanout: BigInt(bucket.tableSize()),
|
|
303
|
-
hashType: hamtHashCode,
|
|
304
|
-
mtime: shardRoot?.mtime,
|
|
305
|
-
mode: shardRoot?.mode
|
|
306
|
-
})
|
|
307
|
-
|
|
308
|
-
const buffer = encode(prepare({
|
|
309
|
-
Data: dir.marshal(),
|
|
310
|
-
Links: links
|
|
311
|
-
}))
|
|
312
|
-
|
|
313
|
-
return buffer.length
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
// we use these to calculate the node size to use as a check for whether a directory
|
|
317
|
-
// should be sharded or not. Since CIDs have a constant length and We're only
|
|
318
|
-
// interested in the data length and not the actual content identifier we can use
|
|
319
|
-
// any old CID instead of having to hash the data which is expensive.
|
|
320
|
-
export const CID_V0 = CID.parse('QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn')
|
|
321
|
-
export const CID_V1 = CID.parse('zdj7WbTaiJT1fgatdet9Ei9iDB5hdCxkbVyhyh8YTUnXMiwYi')
|