@helia/unixfs 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/src/commands/utils/add-link.d.ts +0 -7
- package/dist/src/commands/utils/add-link.d.ts.map +1 -1
- package/dist/src/commands/utils/add-link.js +97 -128
- package/dist/src/commands/utils/add-link.js.map +1 -1
- package/dist/src/commands/utils/consumable-hash.d.ts +25 -0
- package/dist/src/commands/utils/consumable-hash.d.ts.map +1 -0
- package/dist/src/commands/utils/consumable-hash.js +136 -0
- package/dist/src/commands/utils/consumable-hash.js.map +1 -0
- package/dist/src/commands/utils/hamt-utils.d.ts +17 -20
- package/dist/src/commands/utils/hamt-utils.d.ts.map +1 -1
- package/dist/src/commands/utils/hamt-utils.js +105 -163
- package/dist/src/commands/utils/hamt-utils.js.map +1 -1
- package/dist/src/commands/utils/remove-link.d.ts.map +1 -1
- package/dist/src/commands/utils/remove-link.js +35 -91
- package/dist/src/commands/utils/remove-link.js.map +1 -1
- package/dist/src/commands/utils/resolve.d.ts.map +1 -1
- package/dist/src/commands/utils/resolve.js +5 -2
- package/dist/src/commands/utils/resolve.js.map +1 -1
- package/package.json +3 -3
- package/src/commands/utils/add-link.ts +107 -170
- package/src/commands/utils/consumable-hash.ts +174 -0
- package/src/commands/utils/hamt-utils.ts +138 -224
- package/src/commands/utils/remove-link.ts +38 -110
- package/src/commands/utils/resolve.ts +8 -3
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { CID, Version } from 'multiformats/cid';
|
|
2
2
|
import type { PBNode, PBLink } from '@ipld/dag-pb/interface';
|
|
3
|
-
import type { Bucket } from 'hamt-sharding';
|
|
4
3
|
import type { AbortOptions } from '@libp2p/interfaces';
|
|
5
4
|
import type { Directory } from './cid-to-directory.js';
|
|
6
5
|
import type { Blockstore } from 'interface-blockstore';
|
|
7
6
|
export interface AddLinkResult {
|
|
8
7
|
node: PBNode;
|
|
9
8
|
cid: CID;
|
|
10
|
-
size: number;
|
|
11
9
|
}
|
|
12
10
|
export interface AddLinkOptions extends AbortOptions {
|
|
13
11
|
allowOverwriting: boolean;
|
|
@@ -15,9 +13,4 @@ export interface AddLinkOptions extends AbortOptions {
|
|
|
15
13
|
cidVersion: Version;
|
|
16
14
|
}
|
|
17
15
|
export declare function addLink(parent: Directory, child: Required<PBLink>, blockstore: Blockstore, options: AddLinkOptions): Promise<AddLinkResult>;
|
|
18
|
-
export interface BucketPath {
|
|
19
|
-
bucket: Bucket<any>;
|
|
20
|
-
prefix: string;
|
|
21
|
-
node?: PBNode;
|
|
22
|
-
}
|
|
23
16
|
//# sourceMappingURL=add-link.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-link.d.ts","sourceRoot":"","sources":["../../../../src/commands/utils/add-link.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"add-link.d.ts","sourceRoot":"","sources":["../../../../src/commands/utils/add-link.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAS/C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAA;AAI5D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACtD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAUtD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE,GAAG,CAAA;CACT;AAED,MAAM,WAAW,cAAe,SAAQ,YAAY;IAClD,gBAAgB,EAAE,OAAO,CAAA;IACzB,wBAAwB,EAAE,MAAM,CAAA;IAChC,UAAU,EAAE,OAAO,CAAA;CACpB;AAED,wBAAsB,OAAO,CAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CA0BlJ"}
|
|
@@ -2,12 +2,15 @@ import * as dagPB from '@ipld/dag-pb';
|
|
|
2
2
|
import { CID } from 'multiformats/cid';
|
|
3
3
|
import { logger } from '@libp2p/logger';
|
|
4
4
|
import { UnixFS } from 'ipfs-unixfs';
|
|
5
|
-
import {
|
|
6
|
-
import { updateHamtDirectory, recreateHamtLevel, recreateInitialHamtLevel, createShard, toPrefix, addLinksToHamtBucket } from './hamt-utils.js';
|
|
7
|
-
import last from 'it-last';
|
|
5
|
+
import { createShard, recreateShardedDirectory, toPrefix, updateShardedDirectory } from './hamt-utils.js';
|
|
8
6
|
import { sha256 } from 'multiformats/hashes/sha2';
|
|
9
7
|
import { AlreadyExistsError, InvalidParametersError, InvalidPBNodeError } from './errors.js';
|
|
10
8
|
import { isOverShardThreshold } from './is-over-shard-threshold.js';
|
|
9
|
+
import { hamtBucketBits, hamtHashFn } from './hamt-constants.js';
|
|
10
|
+
// @ts-expect-error no types
|
|
11
|
+
import SparseArray from 'sparse-array';
|
|
12
|
+
import { wrapHash } from './consumable-hash.js';
|
|
13
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
11
14
|
const log = logger('helia:unixfs:components:utils:add-link');
|
|
12
15
|
export async function addLink(parent, child, blockstore, options) {
|
|
13
16
|
if (parent.node.Data == null) {
|
|
@@ -42,7 +45,7 @@ const convertToShardedDirectory = async (parent, blockstore) => {
|
|
|
42
45
|
mtime: unixfs.mtime,
|
|
43
46
|
cidVersion: parent.cid.version
|
|
44
47
|
});
|
|
45
|
-
log(`
|
|
48
|
+
log(`converted directory to sharded directory ${result.cid}`);
|
|
46
49
|
return result;
|
|
47
50
|
};
|
|
48
51
|
const addToDirectory = async (parent, child, blockstore, options) => {
|
|
@@ -84,141 +87,107 @@ const addToDirectory = async (parent, child, blockstore, options) => {
|
|
|
84
87
|
await blockstore.put(cid, buf);
|
|
85
88
|
return {
|
|
86
89
|
node: parent.node,
|
|
87
|
-
cid
|
|
88
|
-
size: buf.length
|
|
90
|
+
cid
|
|
89
91
|
};
|
|
90
92
|
};
|
|
91
93
|
const addToShardedDirectory = async (parent, child, blockstore, options) => {
|
|
92
|
-
const {
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
throw new Error('
|
|
94
|
+
const { path, hash } = await recreateShardedDirectory(parent.cid, child.Name, blockstore, options);
|
|
95
|
+
const finalSegment = path[path.length - 1];
|
|
96
|
+
if (finalSegment == null) {
|
|
97
|
+
throw new Error('Invalid HAMT, could not generate path');
|
|
96
98
|
}
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return await updateHamtDirectory({
|
|
110
|
-
Data: parent.node.Data,
|
|
111
|
-
Links: parentLinks
|
|
112
|
-
}, blockstore, path[0].bucket, options);
|
|
113
|
-
};
|
|
114
|
-
const addFileToShardedDirectory = async (parent, child, blockstore, options) => {
|
|
115
|
-
if (parent.node.Data == null) {
|
|
116
|
-
throw new InvalidPBNodeError('Parent node with no data passed to addFileToShardedDirectory');
|
|
117
|
-
}
|
|
118
|
-
// start at the root bucket and descend, loading nodes as we go
|
|
119
|
-
const rootBucket = await recreateInitialHamtLevel(parent.node.Links);
|
|
120
|
-
const node = UnixFS.unmarshal(parent.node.Data);
|
|
121
|
-
const shard = new DirSharded({
|
|
122
|
-
root: true,
|
|
123
|
-
dir: true,
|
|
124
|
-
parent: undefined,
|
|
125
|
-
parentKey: undefined,
|
|
126
|
-
path: '',
|
|
127
|
-
dirty: true,
|
|
128
|
-
flat: false,
|
|
129
|
-
mode: node.mode
|
|
130
|
-
}, {
|
|
131
|
-
...options,
|
|
132
|
-
cidVersion: parent.cid.version
|
|
133
|
-
});
|
|
134
|
-
shard._bucket = rootBucket;
|
|
135
|
-
if (node.mtime != null) {
|
|
136
|
-
// update mtime if previously set
|
|
137
|
-
shard.mtime = {
|
|
138
|
-
secs: BigInt(Math.round(Date.now() / 1000))
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
// load subshards until the bucket & position no longer changes
|
|
142
|
-
const position = await rootBucket._findNewBucketAndPos(child.Name);
|
|
143
|
-
const path = toBucketPath(position);
|
|
144
|
-
path[0].node = parent.node;
|
|
145
|
-
let index = 0;
|
|
146
|
-
while (index < path.length) {
|
|
147
|
-
const segment = path[index];
|
|
148
|
-
index++;
|
|
149
|
-
const node = segment.node;
|
|
150
|
-
if (node == null) {
|
|
151
|
-
throw new Error('Segment had no node');
|
|
152
|
-
}
|
|
153
|
-
const link = node.Links
|
|
154
|
-
.find(link => (link.Name ?? '').substring(0, 2) === segment.prefix);
|
|
155
|
-
if (link == null) {
|
|
156
|
-
// prefix is new, file will be added to the current bucket
|
|
157
|
-
log(`Link ${segment.prefix}${child.Name} will be added`);
|
|
158
|
-
index = path.length;
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
if (link.Name === `${segment.prefix}${child.Name}`) {
|
|
99
|
+
// find the next prefix
|
|
100
|
+
// const index = await hash.take(hamtBucketBits)
|
|
101
|
+
const prefix = finalSegment.prefix;
|
|
102
|
+
const index = parseInt(prefix, 16);
|
|
103
|
+
log('next prefix for %s is %s', child.Name, prefix);
|
|
104
|
+
const linkName = `${prefix}${child.Name}`;
|
|
105
|
+
const existingLink = finalSegment.node.Links.find(l => (l.Name ?? '').startsWith(prefix));
|
|
106
|
+
if (existingLink != null) {
|
|
107
|
+
log('link %s was present in shard', linkName);
|
|
108
|
+
// link is already present in shard
|
|
109
|
+
if (existingLink.Name === linkName) {
|
|
110
|
+
// file with same name is already present in shard
|
|
162
111
|
if (!options.allowOverwriting) {
|
|
163
112
|
throw new AlreadyExistsError();
|
|
164
113
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
114
|
+
log('overwriting %s in subshard', child.Name);
|
|
115
|
+
finalSegment.node.Links = finalSegment.node.Links.filter(l => l.Name !== linkName);
|
|
116
|
+
finalSegment.node.Links.push({
|
|
117
|
+
Name: linkName,
|
|
118
|
+
Hash: child.Hash,
|
|
119
|
+
Tsize: child.Tsize
|
|
120
|
+
});
|
|
169
121
|
}
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
log(`Link ${link.Name} ${link.Hash} will be replaced with a subshard`);
|
|
173
|
-
index = path.length;
|
|
174
|
-
break;
|
|
122
|
+
else if (existingLink.Name?.length === 2) {
|
|
123
|
+
throw new Error('Existing link was subshard?!');
|
|
175
124
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
}
|
|
190
|
-
|
|
125
|
+
else {
|
|
126
|
+
// conflict, add a new HAMT segment
|
|
127
|
+
log('prefix %s already exists, creating new subshard', prefix);
|
|
128
|
+
// find the sibling we are going to replace
|
|
129
|
+
const index = finalSegment.node.Links.findIndex(l => l.Name?.startsWith(prefix));
|
|
130
|
+
const sibling = finalSegment.node.Links.splice(index, 1)[0];
|
|
131
|
+
// give the sibling a new HAMT prefix
|
|
132
|
+
const siblingName = (sibling.Name ?? '').substring(2);
|
|
133
|
+
const wrapped = wrapHash(hamtHashFn);
|
|
134
|
+
const siblingHash = wrapped(uint8ArrayFromString(siblingName));
|
|
135
|
+
// discard hash bits until we reach the subshard depth
|
|
136
|
+
for (let i = 0; i < path.length; i++) {
|
|
137
|
+
await siblingHash.take(hamtBucketBits);
|
|
138
|
+
}
|
|
139
|
+
while (true) {
|
|
140
|
+
const siblingIndex = await siblingHash.take(hamtBucketBits);
|
|
141
|
+
const siblingPrefix = toPrefix(siblingIndex);
|
|
142
|
+
sibling.Name = `${siblingPrefix}${siblingName}`;
|
|
143
|
+
// calculate the target file's HAMT prefix in the new sub-shard
|
|
144
|
+
const newIndex = await hash.take(hamtBucketBits);
|
|
145
|
+
const newPrefix = toPrefix(newIndex);
|
|
146
|
+
if (siblingPrefix === newPrefix) {
|
|
147
|
+
// the two sibling names have caused another conflict - add an intermediate node to
|
|
148
|
+
// the HAMT and try again
|
|
149
|
+
// create the child locations
|
|
150
|
+
const children = new SparseArray();
|
|
151
|
+
children.set(newIndex, true);
|
|
152
|
+
path.push({
|
|
153
|
+
prefix: newPrefix,
|
|
154
|
+
children,
|
|
155
|
+
node: {
|
|
156
|
+
Links: []
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
// create the child locations
|
|
162
|
+
const children = new SparseArray();
|
|
163
|
+
children.set(newIndex, true);
|
|
164
|
+
children.set(siblingIndex, true);
|
|
165
|
+
// add our new segment
|
|
166
|
+
path.push({
|
|
167
|
+
prefix,
|
|
168
|
+
children,
|
|
169
|
+
node: {
|
|
170
|
+
Links: [
|
|
171
|
+
sibling, {
|
|
172
|
+
Name: `${newPrefix}${child.Name}`,
|
|
173
|
+
Hash: child.Hash,
|
|
174
|
+
Tsize: child.Tsize
|
|
175
|
+
}
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
191
181
|
}
|
|
192
|
-
const nextSegment = path[index];
|
|
193
|
-
// add next levels worth of links to bucket
|
|
194
|
-
await addLinksToHamtBucket(blockstore, subShard.Links, nextSegment.bucket, rootBucket, options);
|
|
195
|
-
nextSegment.node = subShard;
|
|
196
182
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
shard,
|
|
204
|
-
};
|
|
205
|
-
};
|
|
206
|
-
const toBucketPath = (position) => {
|
|
207
|
-
const path = [{
|
|
208
|
-
bucket: position.bucket,
|
|
209
|
-
prefix: toPrefix(position.pos)
|
|
210
|
-
}];
|
|
211
|
-
let bucket = position.bucket._parent;
|
|
212
|
-
let positionInBucket = position.bucket._posAtParent;
|
|
213
|
-
while (bucket != null) {
|
|
214
|
-
path.push({
|
|
215
|
-
bucket,
|
|
216
|
-
prefix: toPrefix(positionInBucket)
|
|
217
|
-
});
|
|
218
|
-
positionInBucket = bucket._posAtParent;
|
|
219
|
-
bucket = bucket._parent;
|
|
183
|
+
else {
|
|
184
|
+
log('link %s was not present in sub-shard', linkName);
|
|
185
|
+
// add new link to shard
|
|
186
|
+
child.Name = linkName;
|
|
187
|
+
finalSegment.node.Links.push(child);
|
|
188
|
+
finalSegment.children.set(index, true);
|
|
189
|
+
log('adding %s to existing sub-shard', linkName);
|
|
220
190
|
}
|
|
221
|
-
path
|
|
222
|
-
return path;
|
|
191
|
+
return await updateShardedDirectory(path, blockstore, options);
|
|
223
192
|
};
|
|
224
193
|
//# sourceMappingURL=add-link.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-link.js","sourceRoot":"","sources":["../../../../src/commands/utils/add-link.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,GAAG,EAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,
|
|
1
|
+
{"version":3,"file":"add-link.js","sourceRoot":"","sources":["../../../../src/commands/utils/add-link.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AACrC,OAAO,EAAE,GAAG,EAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,gB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ACR,MAAM,EAAE,SAAS;wBACjB,QAAQ;wBACR,IAAI,EAAE;4BACJ,KAAK,EAAE,EAAE;yBACV;qBACF,CAAC,CAAA;oBAEF,SAAQ;iBACT;gBAED,6BAA6B;gBAC7B,MAAM,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAA;gBAClC,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAA;gBAC5B,QAAQ,CAAC,GAAG,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;gBAEhC,sBAAsB;gBACtB,IAAI,CAAC,IAAI,CAAC;oBACR,MAAM;oBACN,QAAQ;oBACR,IAAI,EAAE;wBACJ,KAAK,EAAE;4BACL,OAAO,EAAE;gCACP,IAAI,EAAE,GAAG,SAAS,GAAG,KAAK,CAAC,IAAI,EAAE;gCACjC,IAAI,EAAE,KAAK,CAAC,IAAI;gCAChB,KAAK,EAAE,KAAK,CAAC,KAAK;6BACnB;yBACF;qBACF;iBACF,CAAC,CAAA;gBAEF,MAAK;aACN;SACF;KACF;SAAM;QACL,GAAG,CAAC,sCAAsC,EAAE,QAAQ,CAAC,CAAA;QAErD,wBAAwB;QACxB,KAAK,CAAC,IAAI,GAAG,QAAQ,CAAA;QACrB,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACnC,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;QAEtC,GAAG,CAAC,iCAAiC,EAAE,QAAQ,CAAC,CAAA;KACjD;IAED,OAAO,MAAM,sBAAsB,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;AAChE,CAAC,CAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export declare function wrapHash(hashFn: (value: Uint8Array) => Promise<Uint8Array>): (value: InfiniteHash | Uint8Array) => InfiniteHash;
|
|
2
|
+
export declare class InfiniteHash {
|
|
3
|
+
_value: Uint8Array;
|
|
4
|
+
_hashFn: (value: Uint8Array) => Promise<Uint8Array>;
|
|
5
|
+
_depth: number;
|
|
6
|
+
_availableBits: number;
|
|
7
|
+
_currentBufferIndex: number;
|
|
8
|
+
_buffers: ConsumableBuffer[];
|
|
9
|
+
constructor(value: Uint8Array, hashFn: (value: Uint8Array) => Promise<Uint8Array>);
|
|
10
|
+
take(bits: number): Promise<number>;
|
|
11
|
+
untake(bits: number): void;
|
|
12
|
+
_produceMoreBits(): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
export declare class ConsumableBuffer {
|
|
15
|
+
_value: Uint8Array;
|
|
16
|
+
_currentBytePos: number;
|
|
17
|
+
_currentBitPos: number;
|
|
18
|
+
constructor(value: Uint8Array);
|
|
19
|
+
availableBits(): number;
|
|
20
|
+
totalBits(): number;
|
|
21
|
+
take(bits: number): number;
|
|
22
|
+
untake(bits: number): void;
|
|
23
|
+
_haveBits(): boolean;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=consumable-hash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumable-hash.d.ts","sourceRoot":"","sources":["../../../../src/commands/utils/consumable-hash.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAE,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,GAAG,UAAU,KAAK,YAAY,CAWhI;AAED,qBAAa,YAAY;IACvB,MAAM,EAAE,UAAU,CAAA;IAClB,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;IACnD,MAAM,EAAE,MAAM,CAAA;IACd,cAAc,EAAE,MAAM,CAAA;IACtB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,QAAQ,EAAE,gBAAgB,EAAE,CAAA;gBAEf,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,OAAO,CAAC,UAAU,CAAC;IAa5E,IAAI,CAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAyB1C,MAAM,CAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAiBrB,gBAAgB,IAAK,OAAO,CAAC,IAAI,CAAC;CAUzC;AAwBD,qBAAa,gBAAgB;IAC3B,MAAM,EAAE,UAAU,CAAA;IAClB,eAAe,EAAE,MAAM,CAAA;IACvB,cAAc,EAAE,MAAM,CAAA;gBAET,KAAK,EAAE,UAAU;IAM9B,aAAa,IAAK,MAAM;IAIxB,SAAS,IAAK,MAAM;IAIpB,IAAI,CAAE,IAAI,EAAE,MAAM,GAAG,MAAM;IAsB3B,MAAM,CAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAQ3B,SAAS,IAAK,OAAO;CAGtB"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
|
2
|
+
export function wrapHash(hashFn) {
|
|
3
|
+
function hashing(value) {
|
|
4
|
+
if (value instanceof InfiniteHash) {
|
|
5
|
+
// already a hash. return it
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
return new InfiniteHash(value, hashFn);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return hashing;
|
|
13
|
+
}
|
|
14
|
+
export class InfiniteHash {
|
|
15
|
+
constructor(value, hashFn) {
|
|
16
|
+
if (!(value instanceof Uint8Array)) {
|
|
17
|
+
throw new Error('can only hash Uint8Arrays');
|
|
18
|
+
}
|
|
19
|
+
this._value = value;
|
|
20
|
+
this._hashFn = hashFn;
|
|
21
|
+
this._depth = -1;
|
|
22
|
+
this._availableBits = 0;
|
|
23
|
+
this._currentBufferIndex = 0;
|
|
24
|
+
this._buffers = [];
|
|
25
|
+
}
|
|
26
|
+
async take(bits) {
|
|
27
|
+
let pendingBits = bits;
|
|
28
|
+
while (this._availableBits < pendingBits) {
|
|
29
|
+
await this._produceMoreBits();
|
|
30
|
+
}
|
|
31
|
+
let result = 0;
|
|
32
|
+
while (pendingBits > 0) {
|
|
33
|
+
const hash = this._buffers[this._currentBufferIndex];
|
|
34
|
+
const available = Math.min(hash.availableBits(), pendingBits);
|
|
35
|
+
const took = hash.take(available);
|
|
36
|
+
result = (result << available) + took;
|
|
37
|
+
pendingBits -= available;
|
|
38
|
+
this._availableBits -= available;
|
|
39
|
+
if (hash.availableBits() === 0) {
|
|
40
|
+
this._currentBufferIndex++;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
untake(bits) {
|
|
46
|
+
let pendingBits = bits;
|
|
47
|
+
while (pendingBits > 0) {
|
|
48
|
+
const hash = this._buffers[this._currentBufferIndex];
|
|
49
|
+
const availableForUntake = Math.min(hash.totalBits() - hash.availableBits(), pendingBits);
|
|
50
|
+
hash.untake(availableForUntake);
|
|
51
|
+
pendingBits -= availableForUntake;
|
|
52
|
+
this._availableBits += availableForUntake;
|
|
53
|
+
if (this._currentBufferIndex > 0 && hash.totalBits() === hash.availableBits()) {
|
|
54
|
+
this._depth--;
|
|
55
|
+
this._currentBufferIndex--;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async _produceMoreBits() {
|
|
60
|
+
this._depth++;
|
|
61
|
+
const value = this._depth > 0 ? uint8ArrayConcat([this._value, Uint8Array.from([this._depth])]) : this._value;
|
|
62
|
+
const hashValue = await this._hashFn(value);
|
|
63
|
+
const buffer = new ConsumableBuffer(hashValue);
|
|
64
|
+
this._buffers.push(buffer);
|
|
65
|
+
this._availableBits += buffer.availableBits();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const START_MASKS = [
|
|
69
|
+
0b11111111,
|
|
70
|
+
0b11111110,
|
|
71
|
+
0b11111100,
|
|
72
|
+
0b11111000,
|
|
73
|
+
0b11110000,
|
|
74
|
+
0b11100000,
|
|
75
|
+
0b11000000,
|
|
76
|
+
0b10000000
|
|
77
|
+
];
|
|
78
|
+
const STOP_MASKS = [
|
|
79
|
+
0b00000001,
|
|
80
|
+
0b00000011,
|
|
81
|
+
0b00000111,
|
|
82
|
+
0b00001111,
|
|
83
|
+
0b00011111,
|
|
84
|
+
0b00111111,
|
|
85
|
+
0b01111111,
|
|
86
|
+
0b11111111
|
|
87
|
+
];
|
|
88
|
+
export class ConsumableBuffer {
|
|
89
|
+
constructor(value) {
|
|
90
|
+
this._value = value;
|
|
91
|
+
this._currentBytePos = value.length - 1;
|
|
92
|
+
this._currentBitPos = 7;
|
|
93
|
+
}
|
|
94
|
+
availableBits() {
|
|
95
|
+
return this._currentBitPos + 1 + this._currentBytePos * 8;
|
|
96
|
+
}
|
|
97
|
+
totalBits() {
|
|
98
|
+
return this._value.length * 8;
|
|
99
|
+
}
|
|
100
|
+
take(bits) {
|
|
101
|
+
let pendingBits = bits;
|
|
102
|
+
let result = 0;
|
|
103
|
+
while (pendingBits > 0 && this._haveBits()) {
|
|
104
|
+
const byte = this._value[this._currentBytePos];
|
|
105
|
+
const availableBits = this._currentBitPos + 1;
|
|
106
|
+
const taking = Math.min(availableBits, pendingBits);
|
|
107
|
+
const value = byteBitsToInt(byte, availableBits - taking, taking);
|
|
108
|
+
result = (result << taking) + value;
|
|
109
|
+
pendingBits -= taking;
|
|
110
|
+
this._currentBitPos -= taking;
|
|
111
|
+
if (this._currentBitPos < 0) {
|
|
112
|
+
this._currentBitPos = 7;
|
|
113
|
+
this._currentBytePos--;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
untake(bits) {
|
|
119
|
+
this._currentBitPos += bits;
|
|
120
|
+
while (this._currentBitPos > 7) {
|
|
121
|
+
this._currentBitPos -= 8;
|
|
122
|
+
this._currentBytePos += 1;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
_haveBits() {
|
|
126
|
+
return this._currentBytePos >= 0;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function byteBitsToInt(byte, start, length) {
|
|
130
|
+
const mask = maskFor(start, length);
|
|
131
|
+
return (byte & mask) >>> start;
|
|
132
|
+
}
|
|
133
|
+
function maskFor(start, length) {
|
|
134
|
+
return START_MASKS[start] & STOP_MASKS[Math.min(length + start - 1, 7)];
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=consumable-hash.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consumable-hash.js","sourceRoot":"","sources":["../../../../src/commands/utils/consumable-hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE/D,MAAM,UAAU,QAAQ,CAAE,MAAkD;IAC1E,SAAS,OAAO,CAAE,KAAgC;QAChD,IAAI,KAAK,YAAY,YAAY,EAAE;YACjC,4BAA4B;YAC5B,OAAO,KAAK,CAAA;SACb;aAAM;YACL,OAAO,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;SACvC;IACH,CAAC;IAED,OAAO,OAAO,CAAA;AAChB,CAAC;AAED,MAAM,OAAO,YAAY;IAQvB,YAAa,KAAiB,EAAE,MAAkD;QAChF,IAAI,CAAC,CAAC,KAAK,YAAY,UAAU,CAAC,EAAE;YAClC,MAAM,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAA;SAC7C;QAED,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QACrB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAChB,IAAI,CAAC,cAAc,GAAG,CAAC,CAAA;QACvB,IAAI,CAAC,mBAAmB,GAAG,CAAC,CAAA;QAC5B,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAA;IACpB,CAAC;IAED,KAAK,CAAC,IAAI,CAAE,IAAY;QACtB,IAAI,WAAW,GAAG,IAAI,CAAA;Q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AAM,IAAI,GAAG,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IACnC,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,KAAK,CAAA;AAChC,CAAC;AAED,SAAS,OAAO,CAAE,KAAa,EAAE,MAAc;IAC7C,OAAO,WAAW,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AACzE,CAAC"}
|
|
@@ -1,32 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as dagPB from '@ipld/dag-pb';
|
|
2
2
|
import type { CID, Version } from 'multiformats/cid';
|
|
3
|
-
import type { PBLink, PBNode } from '@ipld/dag-pb/interface';
|
|
4
3
|
import type { Blockstore } from 'interface-blockstore';
|
|
5
4
|
import type { Mtime } from 'ipfs-unixfs';
|
|
6
|
-
import type { Directory } from './cid-to-directory.js';
|
|
7
5
|
import type { AbortOptions } from '@libp2p/interfaces';
|
|
8
6
|
import type { ImportResult } from 'ipfs-unixfs-importer';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
size: number;
|
|
13
|
-
}
|
|
7
|
+
import { InfiniteHash } from './consumable-hash.js';
|
|
8
|
+
import SparseArray from 'sparse-array';
|
|
9
|
+
import type { PersistOptions } from './persist.js';
|
|
14
10
|
export interface UpdateHamtDirectoryOptions extends AbortOptions {
|
|
15
11
|
cidVersion: Version;
|
|
16
12
|
}
|
|
17
|
-
export declare const updateHamtDirectory: (pbNode: PBNode, blockstore: Blockstore, bucket: Bucket<any>, options: UpdateHamtDirectoryOptions) => Promise<UpdateHamtResult>;
|
|
18
|
-
export declare const recreateHamtLevel: (blockstore: Blockstore, links: PBLink[], rootBucket: Bucket<any>, parentBucket: Bucket<any>, positionAtParent: number, options: AbortOptions) => Promise<Bucket<any>>;
|
|
19
|
-
export declare const recreateInitialHamtLevel: (links: PBLink[]) => Promise<Bucket<any>>;
|
|
20
|
-
export declare const addLinksToHamtBucket: (blockstore: Blockstore, links: PBLink[], bucket: Bucket<any>, rootBucket: Bucket<any>, options: AbortOptions) => Promise<void>;
|
|
21
13
|
export declare const toPrefix: (position: number) => string;
|
|
22
|
-
export interface HamtPathSegment {
|
|
23
|
-
bucket?: Bucket<any>;
|
|
24
|
-
prefix?: string;
|
|
25
|
-
node?: PBNode;
|
|
26
|
-
cid?: CID;
|
|
27
|
-
size?: number;
|
|
28
|
-
}
|
|
29
|
-
export declare const generatePath: (root: Directory, name: string, blockstore: Blockstore, options: AbortOptions) => Promise<HamtPathSegment[]>;
|
|
30
14
|
export interface CreateShardOptions {
|
|
31
15
|
mtime?: Mtime;
|
|
32
16
|
mode?: number;
|
|
@@ -37,4 +21,17 @@ export declare const createShard: (blockstore: Blockstore, contents: Array<{
|
|
|
37
21
|
size: bigint;
|
|
38
22
|
cid: CID;
|
|
39
23
|
}>, options: CreateShardOptions) => Promise<ImportResult>;
|
|
24
|
+
export interface HAMTPath {
|
|
25
|
+
prefix: string;
|
|
26
|
+
children: SparseArray;
|
|
27
|
+
node: dagPB.PBNode;
|
|
28
|
+
}
|
|
29
|
+
export declare const updateShardedDirectory: (path: HAMTPath[], blockstore: Blockstore, options: PersistOptions) => Promise<{
|
|
30
|
+
cid: CID;
|
|
31
|
+
node: dagPB.PBNode;
|
|
32
|
+
}>;
|
|
33
|
+
export declare const recreateShardedDirectory: (cid: CID, fileName: string, blockstore: Blockstore, options: AbortOptions) => Promise<{
|
|
34
|
+
path: HAMTPath[];
|
|
35
|
+
hash: InfiniteHash;
|
|
36
|
+
}>;
|
|
40
37
|
//# sourceMappingURL=hamt-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hamt-utils.d.ts","sourceRoot":"","sources":["../../../../src/commands/utils/hamt-utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hamt-utils.d.ts","sourceRoot":"","sources":["../../../../src/commands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