@hashtree/core 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/bep52.d.ts +179 -0
- package/dist/bep52.d.ts.map +1 -0
- package/dist/bep52.js +384 -0
- package/dist/bep52.js.map +1 -0
- package/dist/builder.d.ts +137 -0
- package/dist/builder.d.ts.map +1 -0
- package/dist/builder.js +281 -0
- package/dist/builder.js.map +1 -0
- package/dist/codec.d.ts +37 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +109 -0
- package/dist/codec.js.map +1 -0
- package/dist/crypto.d.ts +92 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +212 -0
- package/dist/crypto.js.map +1 -0
- package/dist/encrypted.d.ts +114 -0
- package/dist/encrypted.d.ts.map +1 -0
- package/dist/encrypted.js +446 -0
- package/dist/encrypted.js.map +1 -0
- package/dist/hash.d.ts +14 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +27 -0
- package/dist/hash.js.map +1 -0
- package/dist/hashtree.d.ts +237 -0
- package/dist/hashtree.d.ts.map +1 -0
- package/dist/hashtree.js +557 -0
- package/dist/hashtree.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/nhash.d.ts +94 -0
- package/dist/nhash.d.ts.map +1 -0
- package/dist/nhash.js +293 -0
- package/dist/nhash.js.map +1 -0
- package/dist/resolver/index.d.ts +5 -0
- package/dist/resolver/index.d.ts.map +1 -0
- package/dist/resolver/index.js +5 -0
- package/dist/resolver/index.js.map +1 -0
- package/dist/resolver/nostr.d.ts +82 -0
- package/dist/resolver/nostr.d.ts.map +1 -0
- package/dist/resolver/nostr.js +868 -0
- package/dist/resolver/nostr.js.map +1 -0
- package/dist/store/blossom.d.ts +100 -0
- package/dist/store/blossom.d.ts.map +1 -0
- package/dist/store/blossom.js +355 -0
- package/dist/store/blossom.js.map +1 -0
- package/dist/store/dexie.d.ts +44 -0
- package/dist/store/dexie.d.ts.map +1 -0
- package/dist/store/dexie.js +196 -0
- package/dist/store/dexie.js.map +1 -0
- package/dist/store/fallback.d.ts +40 -0
- package/dist/store/fallback.d.ts.map +1 -0
- package/dist/store/fallback.js +71 -0
- package/dist/store/fallback.js.map +1 -0
- package/dist/store/index.d.ts +6 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/index.js +6 -0
- package/dist/store/index.js.map +1 -0
- package/dist/store/memory.d.ts +29 -0
- package/dist/store/memory.d.ts.map +1 -0
- package/dist/store/memory.js +66 -0
- package/dist/store/memory.js.map +1 -0
- package/dist/store/opfs.d.ts +56 -0
- package/dist/store/opfs.d.ts.map +1 -0
- package/dist/store/opfs.js +200 -0
- package/dist/store/opfs.js.map +1 -0
- package/dist/streaming.d.ts +74 -0
- package/dist/streaming.d.ts.map +1 -0
- package/dist/streaming.js +199 -0
- package/dist/streaming.js.map +1 -0
- package/dist/tree/create.d.ts +35 -0
- package/dist/tree/create.d.ts.map +1 -0
- package/dist/tree/create.js +90 -0
- package/dist/tree/create.js.map +1 -0
- package/dist/tree/edit.d.ts +28 -0
- package/dist/tree/edit.d.ts.map +1 -0
- package/dist/tree/edit.js +115 -0
- package/dist/tree/edit.js.map +1 -0
- package/dist/tree/editEncrypted.d.ts +46 -0
- package/dist/tree/editEncrypted.d.ts.map +1 -0
- package/dist/tree/editEncrypted.js +225 -0
- package/dist/tree/editEncrypted.js.map +1 -0
- package/dist/tree/index.d.ts +7 -0
- package/dist/tree/index.d.ts.map +1 -0
- package/dist/tree/index.js +7 -0
- package/dist/tree/index.js.map +1 -0
- package/dist/tree/read.d.ts +75 -0
- package/dist/tree/read.d.ts.map +1 -0
- package/dist/tree/read.js +389 -0
- package/dist/tree/read.js.map +1 -0
- package/dist/tree/writeAt.d.ts +44 -0
- package/dist/tree/writeAt.d.ts.map +1 -0
- package/dist/tree/writeAt.js +282 -0
- package/dist/tree/writeAt.js.map +1 -0
- package/dist/types.d.ts +274 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +47 -0
- package/dist/types.js.map +1 -0
- package/dist/verify.d.ts +12 -0
- package/dist/verify.d.ts.map +1 -0
- package/dist/verify.js +32 -0
- package/dist/verify.js.map +1 -0
- package/dist/visibility.d.ts +50 -0
- package/dist/visibility.d.ts.map +1 -0
- package/dist/visibility.js +111 -0
- package/dist/visibility.js.map +1 -0
- package/dist/webrtc/index.d.ts +4 -0
- package/dist/webrtc/index.d.ts.map +1 -0
- package/dist/webrtc/index.js +4 -0
- package/dist/webrtc/index.js.map +1 -0
- package/dist/webrtc/lruCache.d.ts +20 -0
- package/dist/webrtc/lruCache.d.ts.map +1 -0
- package/dist/webrtc/lruCache.js +59 -0
- package/dist/webrtc/lruCache.js.map +1 -0
- package/dist/webrtc/peer.d.ts +122 -0
- package/dist/webrtc/peer.d.ts.map +1 -0
- package/dist/webrtc/peer.js +583 -0
- package/dist/webrtc/peer.js.map +1 -0
- package/dist/webrtc/protocol.d.ts +76 -0
- package/dist/webrtc/protocol.d.ts.map +1 -0
- package/dist/webrtc/protocol.js +167 -0
- package/dist/webrtc/protocol.js.map +1 -0
- package/dist/webrtc/store.d.ts +190 -0
- package/dist/webrtc/store.d.ts.map +1 -0
- package/dist/webrtc/store.js +1043 -0
- package/dist/webrtc/store.js.map +1 -0
- package/dist/webrtc/types.d.ts +196 -0
- package/dist/webrtc/types.d.ts.map +1 -0
- package/dist/webrtc/types.js +46 -0
- package/dist/webrtc/types.js.map +1 -0
- package/dist/worker/protocol.d.ts +493 -0
- package/dist/worker/protocol.d.ts.map +1 -0
- package/dist/worker/protocol.js +15 -0
- package/dist/worker/protocol.js.map +1 -0
- package/package.json +59 -0
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree reading operations
|
|
3
|
+
*/
|
|
4
|
+
import { LinkType, toHex, cid } from '../types.js';
|
|
5
|
+
import { decodeTreeNode, tryDecodeTreeNode, getNodeType } from '../codec.js';
|
|
6
|
+
/**
|
|
7
|
+
* Get raw data by hash
|
|
8
|
+
*/
|
|
9
|
+
export async function getBlob(store, hash) {
|
|
10
|
+
return store.get(hash);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Get and decode a tree node
|
|
14
|
+
*/
|
|
15
|
+
export async function getTreeNode(store, hash) {
|
|
16
|
+
const data = await store.get(hash);
|
|
17
|
+
if (!data)
|
|
18
|
+
return null;
|
|
19
|
+
return tryDecodeTreeNode(data);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Get the type of a chunk by hash: File, Dir, or Blob
|
|
23
|
+
*/
|
|
24
|
+
export async function getType(store, hash) {
|
|
25
|
+
if (!hash)
|
|
26
|
+
return LinkType.Blob;
|
|
27
|
+
const data = await store.get(hash);
|
|
28
|
+
if (!data)
|
|
29
|
+
return LinkType.Blob;
|
|
30
|
+
return getNodeType(data);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Check if hash points to a directory (tree with named links)
|
|
34
|
+
*/
|
|
35
|
+
export async function isDirectory(store, hash) {
|
|
36
|
+
if (!hash)
|
|
37
|
+
return false;
|
|
38
|
+
const data = await store.get(hash);
|
|
39
|
+
if (!data)
|
|
40
|
+
return false;
|
|
41
|
+
const node = tryDecodeTreeNode(data);
|
|
42
|
+
return node?.type === LinkType.Dir;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Read a complete file (reassemble chunks if needed)
|
|
46
|
+
*/
|
|
47
|
+
export async function readFile(store, hash) {
|
|
48
|
+
if (!hash)
|
|
49
|
+
return null;
|
|
50
|
+
const data = await store.get(hash);
|
|
51
|
+
if (!data)
|
|
52
|
+
return null;
|
|
53
|
+
const node = tryDecodeTreeNode(data);
|
|
54
|
+
if (!node) {
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
57
|
+
return assembleChunks(store, node);
|
|
58
|
+
}
|
|
59
|
+
async function assembleChunks(store, node) {
|
|
60
|
+
// Fetch all children in parallel
|
|
61
|
+
const childPromises = node.links.map(async (link) => {
|
|
62
|
+
const childData = await store.get(link.hash);
|
|
63
|
+
if (!childData) {
|
|
64
|
+
throw new Error(`Missing chunk: ${toHex(link.hash)}`);
|
|
65
|
+
}
|
|
66
|
+
if (link.type !== LinkType.Blob) {
|
|
67
|
+
// Intermediate tree node - decode and recurse (parallel recursion)
|
|
68
|
+
const childNode = decodeTreeNode(childData);
|
|
69
|
+
return assembleChunks(store, childNode);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// Leaf chunk - raw blob
|
|
73
|
+
return childData;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
// Wait for all children to complete
|
|
77
|
+
const parts = await Promise.all(childPromises);
|
|
78
|
+
const totalLength = parts.reduce((sum, p) => sum + p.length, 0);
|
|
79
|
+
const result = new Uint8Array(totalLength);
|
|
80
|
+
let offset = 0;
|
|
81
|
+
for (const part of parts) {
|
|
82
|
+
result.set(part, offset);
|
|
83
|
+
offset += part.length;
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Read a file with streaming
|
|
89
|
+
* Supports prefetching for better network performance
|
|
90
|
+
*/
|
|
91
|
+
export async function* readFileStream(store, hash, options = {}) {
|
|
92
|
+
const { offset = 0, prefetch = 1 } = options;
|
|
93
|
+
const data = await store.get(hash);
|
|
94
|
+
if (!data)
|
|
95
|
+
return;
|
|
96
|
+
const node = tryDecodeTreeNode(data);
|
|
97
|
+
if (!node) {
|
|
98
|
+
if (offset >= data.length)
|
|
99
|
+
return;
|
|
100
|
+
yield offset > 0 ? data.slice(offset) : data;
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
yield* streamChunksWithOffset(store, node, offset, prefetch);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Stream chunks starting from an offset with prefetching
|
|
107
|
+
* Uses link.size to efficiently skip chunks before offset
|
|
108
|
+
* Prefetches N chunks ahead for better network performance
|
|
109
|
+
*/
|
|
110
|
+
async function* streamChunksWithOffset(store, node, offset, prefetch = 1) {
|
|
111
|
+
let position = 0;
|
|
112
|
+
// Find first link index that we need (skip those before offset)
|
|
113
|
+
let startIdx = 0;
|
|
114
|
+
for (let i = 0; i < node.links.length; i++) {
|
|
115
|
+
const linkSize = node.links[i].size ?? 0;
|
|
116
|
+
if (linkSize > 0 && position + linkSize <= offset) {
|
|
117
|
+
position += linkSize;
|
|
118
|
+
startIdx = i + 1;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Build list of links to process
|
|
125
|
+
const linksToProcess = node.links.slice(startIdx);
|
|
126
|
+
if (linksToProcess.length === 0)
|
|
127
|
+
return;
|
|
128
|
+
const prefetchQueue = [];
|
|
129
|
+
// Start initial prefetch
|
|
130
|
+
let prefetchPosition = position;
|
|
131
|
+
for (let i = 0; i < Math.min(prefetch, linksToProcess.length); i++) {
|
|
132
|
+
const link = linksToProcess[i];
|
|
133
|
+
prefetchQueue.push({
|
|
134
|
+
promise: store.get(link.hash),
|
|
135
|
+
link,
|
|
136
|
+
position: prefetchPosition,
|
|
137
|
+
});
|
|
138
|
+
prefetchPosition += link.size ?? 0;
|
|
139
|
+
}
|
|
140
|
+
// Process links
|
|
141
|
+
let nextPrefetchIdx = prefetch;
|
|
142
|
+
for (const link of linksToProcess) {
|
|
143
|
+
// Get data from prefetch queue (should be first item)
|
|
144
|
+
const entry = prefetchQueue.shift();
|
|
145
|
+
if (!entry) {
|
|
146
|
+
throw new Error('Prefetch queue empty unexpectedly');
|
|
147
|
+
}
|
|
148
|
+
const childData = await entry.promise;
|
|
149
|
+
if (!childData) {
|
|
150
|
+
throw new Error(`Missing chunk: ${toHex(link.hash)}`);
|
|
151
|
+
}
|
|
152
|
+
// Start prefetching next chunk
|
|
153
|
+
if (nextPrefetchIdx < linksToProcess.length) {
|
|
154
|
+
const nextLink = linksToProcess[nextPrefetchIdx];
|
|
155
|
+
prefetchQueue.push({
|
|
156
|
+
promise: store.get(nextLink.hash),
|
|
157
|
+
link: nextLink,
|
|
158
|
+
position: prefetchPosition,
|
|
159
|
+
});
|
|
160
|
+
prefetchPosition += nextLink.size ?? 0;
|
|
161
|
+
nextPrefetchIdx++;
|
|
162
|
+
}
|
|
163
|
+
if (link.type !== LinkType.Blob) {
|
|
164
|
+
// Intermediate tree node - decode and recurse with prefetch
|
|
165
|
+
const childNode = decodeTreeNode(childData);
|
|
166
|
+
const childOffset = Math.max(0, offset - entry.position);
|
|
167
|
+
yield* streamChunksWithOffset(store, childNode, childOffset, prefetch);
|
|
168
|
+
position = entry.position + (link.size ?? 0);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
// Leaf chunk - raw blob
|
|
172
|
+
const chunkStart = entry.position;
|
|
173
|
+
const chunkEnd = entry.position + childData.length;
|
|
174
|
+
position = chunkEnd;
|
|
175
|
+
if (chunkEnd <= offset) {
|
|
176
|
+
// Entire chunk is before offset, skip
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
if (chunkStart >= offset) {
|
|
180
|
+
// Entire chunk is after offset, yield all
|
|
181
|
+
yield childData;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
// Partial chunk - slice from offset
|
|
185
|
+
const sliceStart = offset - chunkStart;
|
|
186
|
+
yield childData.slice(sliceStart);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Read a range of bytes from a file
|
|
193
|
+
*/
|
|
194
|
+
export async function readFileRange(store, hash, start, end) {
|
|
195
|
+
const data = await store.get(hash);
|
|
196
|
+
if (!data)
|
|
197
|
+
return null;
|
|
198
|
+
const node = tryDecodeTreeNode(data);
|
|
199
|
+
if (!node) {
|
|
200
|
+
// Single blob
|
|
201
|
+
if (start >= data.length)
|
|
202
|
+
return new Uint8Array(0);
|
|
203
|
+
const actualEnd = end !== undefined ? Math.min(end, data.length) : data.length;
|
|
204
|
+
return data.slice(start, actualEnd);
|
|
205
|
+
}
|
|
206
|
+
return readRangeFromNode(store, node, start, end);
|
|
207
|
+
}
|
|
208
|
+
async function readRangeFromNode(store, node, start, end) {
|
|
209
|
+
const parts = [];
|
|
210
|
+
let position = 0;
|
|
211
|
+
let bytesCollected = 0;
|
|
212
|
+
const maxBytes = end !== undefined ? end - start : Infinity;
|
|
213
|
+
for (const link of node.links) {
|
|
214
|
+
if (bytesCollected >= maxBytes)
|
|
215
|
+
break;
|
|
216
|
+
const linkSize = link.size ?? 0;
|
|
217
|
+
// Skip chunks entirely before start
|
|
218
|
+
if (linkSize > 0 && position + linkSize <= start) {
|
|
219
|
+
position += linkSize;
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
const childData = await store.get(link.hash);
|
|
223
|
+
if (!childData) {
|
|
224
|
+
throw new Error(`Missing chunk: ${toHex(link.hash)}`);
|
|
225
|
+
}
|
|
226
|
+
if (link.type !== LinkType.Blob) {
|
|
227
|
+
// Intermediate tree node - decode and recurse
|
|
228
|
+
const childNode = decodeTreeNode(childData);
|
|
229
|
+
const childStart = Math.max(0, start - position);
|
|
230
|
+
const childEnd = end !== undefined ? end - position : undefined;
|
|
231
|
+
const childData2 = await readRangeFromNode(store, childNode, childStart, childEnd);
|
|
232
|
+
if (childData2.length > 0) {
|
|
233
|
+
const take = Math.min(childData2.length, maxBytes - bytesCollected);
|
|
234
|
+
parts.push(childData2.slice(0, take));
|
|
235
|
+
bytesCollected += take;
|
|
236
|
+
}
|
|
237
|
+
position += linkSize;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
// Leaf chunk - raw blob
|
|
241
|
+
const chunkStart = position;
|
|
242
|
+
const chunkEnd = position + childData.length;
|
|
243
|
+
position = chunkEnd;
|
|
244
|
+
if (chunkEnd <= start) {
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
// Calculate slice bounds within this chunk
|
|
248
|
+
const sliceStart = Math.max(0, start - chunkStart);
|
|
249
|
+
const sliceEnd = end !== undefined
|
|
250
|
+
? Math.min(childData.length, end - chunkStart)
|
|
251
|
+
: childData.length;
|
|
252
|
+
if (sliceStart < sliceEnd) {
|
|
253
|
+
const take = Math.min(sliceEnd - sliceStart, maxBytes - bytesCollected);
|
|
254
|
+
parts.push(childData.slice(sliceStart, sliceStart + take));
|
|
255
|
+
bytesCollected += take;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
// Concatenate parts
|
|
260
|
+
const totalLength = parts.reduce((sum, p) => sum + p.length, 0);
|
|
261
|
+
const result = new Uint8Array(totalLength);
|
|
262
|
+
let offset = 0;
|
|
263
|
+
for (const part of parts) {
|
|
264
|
+
result.set(part, offset);
|
|
265
|
+
offset += part.length;
|
|
266
|
+
}
|
|
267
|
+
return result;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Get directory node, handling chunked directories
|
|
271
|
+
*
|
|
272
|
+
* For chunked directories (encoded blob > chunkSize), the chunks are assembled
|
|
273
|
+
* first, then decoded as a TreeNode.
|
|
274
|
+
*/
|
|
275
|
+
async function getDirectoryNode(store, hash) {
|
|
276
|
+
const data = await store.get(hash);
|
|
277
|
+
if (!data)
|
|
278
|
+
return null;
|
|
279
|
+
const node = tryDecodeTreeNode(data);
|
|
280
|
+
if (!node) {
|
|
281
|
+
return null; // Not a tree node at all
|
|
282
|
+
}
|
|
283
|
+
// Check if it's a directory (has named links) vs chunked blob (no names)
|
|
284
|
+
if (node.type === LinkType.Dir) {
|
|
285
|
+
return node;
|
|
286
|
+
}
|
|
287
|
+
// It's a chunked blob - could be a chunked directory
|
|
288
|
+
// Assemble the chunks and check if result is a directory
|
|
289
|
+
const assembled = await assembleChunks(store, node);
|
|
290
|
+
const assembledNode = tryDecodeTreeNode(assembled);
|
|
291
|
+
if (assembledNode?.type === LinkType.Dir) {
|
|
292
|
+
return assembledNode;
|
|
293
|
+
}
|
|
294
|
+
return null; // Not a directory
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* List directory entries
|
|
298
|
+
*
|
|
299
|
+
* Handles both small directories (single node) and large directories
|
|
300
|
+
* (chunked by bytes like files - reassembled then decoded).
|
|
301
|
+
*/
|
|
302
|
+
export async function listDirectory(store, hash) {
|
|
303
|
+
const node = await getDirectoryNode(store, hash);
|
|
304
|
+
if (!node)
|
|
305
|
+
return [];
|
|
306
|
+
const entries = [];
|
|
307
|
+
for (const link of node.links) {
|
|
308
|
+
if (!link.name)
|
|
309
|
+
continue; // Skip unnamed links (shouldn't happen in directories)
|
|
310
|
+
entries.push({
|
|
311
|
+
name: link.name,
|
|
312
|
+
cid: cid(link.hash, link.key),
|
|
313
|
+
size: link.size,
|
|
314
|
+
type: link.type,
|
|
315
|
+
meta: link.meta,
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
return entries;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Resolve a path within a tree
|
|
322
|
+
*
|
|
323
|
+
* Handles chunked directories (reassembles bytes to get the full TreeNode).
|
|
324
|
+
*/
|
|
325
|
+
export async function resolvePath(store, rootHash, path) {
|
|
326
|
+
const parts = path.split('/').filter(p => p.length > 0);
|
|
327
|
+
let currentHash = rootHash;
|
|
328
|
+
for (const part of parts) {
|
|
329
|
+
const node = await getDirectoryNode(store, currentHash);
|
|
330
|
+
if (!node)
|
|
331
|
+
return null;
|
|
332
|
+
const link = node.links.find(l => l.name === part);
|
|
333
|
+
if (!link)
|
|
334
|
+
return null;
|
|
335
|
+
currentHash = link.hash;
|
|
336
|
+
}
|
|
337
|
+
return currentHash;
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Get total size of a tree
|
|
341
|
+
*/
|
|
342
|
+
export async function getSize(store, hash) {
|
|
343
|
+
const data = await store.get(hash);
|
|
344
|
+
if (!data)
|
|
345
|
+
return 0;
|
|
346
|
+
const node = tryDecodeTreeNode(data);
|
|
347
|
+
if (!node) {
|
|
348
|
+
return data.length;
|
|
349
|
+
}
|
|
350
|
+
let total = 0;
|
|
351
|
+
for (const link of node.links) {
|
|
352
|
+
total += link.size;
|
|
353
|
+
}
|
|
354
|
+
return total;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Walk entire tree depth-first
|
|
358
|
+
*
|
|
359
|
+
* Handles chunked directories (reassembles bytes to get the full TreeNode).
|
|
360
|
+
*/
|
|
361
|
+
export async function* walk(store, hash, path = '') {
|
|
362
|
+
const data = await store.get(hash);
|
|
363
|
+
if (!data)
|
|
364
|
+
return;
|
|
365
|
+
// Check if it's a directory
|
|
366
|
+
const dirNode = await getDirectoryNode(store, hash);
|
|
367
|
+
if (dirNode) {
|
|
368
|
+
const dirSize = dirNode.links.reduce((sum, l) => sum + l.size, 0);
|
|
369
|
+
yield { path, hash, type: LinkType.Dir, size: dirSize };
|
|
370
|
+
for (const link of dirNode.links) {
|
|
371
|
+
if (!link.name)
|
|
372
|
+
continue;
|
|
373
|
+
const childPath = path ? `${path}/${link.name}` : link.name;
|
|
374
|
+
yield* walk(store, link.hash, childPath);
|
|
375
|
+
}
|
|
376
|
+
return;
|
|
377
|
+
}
|
|
378
|
+
// Not a directory - could be a file (single blob or chunked)
|
|
379
|
+
const node = tryDecodeTreeNode(data);
|
|
380
|
+
if (!node) {
|
|
381
|
+
// Single blob file
|
|
382
|
+
yield { path, hash, type: LinkType.Blob, size: data.length };
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
// Chunked file - sum link sizes
|
|
386
|
+
const fileSize = node.links.reduce((sum, l) => sum + l.size, 0);
|
|
387
|
+
yield { path, hash, type: LinkType.File, size: fileSize };
|
|
388
|
+
}
|
|
389
|
+
//# sourceMappingURL=read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/tree/read.ts"],"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AO,EAAE,CAAC;QAExD,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YACjC,IAAI,CAAC,IAAI,CAAC,IAAI;gBAAE,SAAS;YAEzB,MAAM,SAAS,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YAC5D,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO;IACT,CAAC;IAED,6DAA6D;IAC7D,MAAM,IAAI,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;IACrC,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,mBAAmB;QACnB,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC;QAC7D,OAAO;IACT,CAAC;IAED,gCAAgC;IAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;IAChE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAC5D,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* writeAt - Efficiently patch bytes at a specific offset without rewriting entire file
|
|
3
|
+
*
|
|
4
|
+
* Only affected chunks and their parent nodes are rewritten.
|
|
5
|
+
* For a large file with a small patch, this is much more efficient than putFile.
|
|
6
|
+
*/
|
|
7
|
+
import { Store, Hash } from '../types.js';
|
|
8
|
+
import { type EncryptionKey } from '../crypto.js';
|
|
9
|
+
export interface WriteAtConfig {
|
|
10
|
+
store: Store;
|
|
11
|
+
chunkSize: number;
|
|
12
|
+
}
|
|
13
|
+
export interface WriteAtResult {
|
|
14
|
+
/** New root hash after modification */
|
|
15
|
+
hash: Hash;
|
|
16
|
+
/** Total file size (unchanged) */
|
|
17
|
+
size: number;
|
|
18
|
+
}
|
|
19
|
+
export interface WriteAtEncryptedResult extends WriteAtResult {
|
|
20
|
+
/** New encryption key for the root */
|
|
21
|
+
key: EncryptionKey;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Write data at a specific offset in an unencrypted file
|
|
25
|
+
*
|
|
26
|
+
* @param config - Tree configuration
|
|
27
|
+
* @param rootHash - Current root hash of the file
|
|
28
|
+
* @param offset - Byte offset to write at
|
|
29
|
+
* @param data - Data to write
|
|
30
|
+
* @returns New root hash
|
|
31
|
+
*/
|
|
32
|
+
export declare function writeAt(config: WriteAtConfig, rootHash: Hash, offset: number, data: Uint8Array): Promise<WriteAtResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Write data at a specific offset in an encrypted file
|
|
35
|
+
*
|
|
36
|
+
* @param config - Tree configuration
|
|
37
|
+
* @param rootHash - Current root hash of the encrypted file
|
|
38
|
+
* @param rootKey - Current encryption key for the root
|
|
39
|
+
* @param offset - Byte offset to write at
|
|
40
|
+
* @param data - Data to write (plaintext)
|
|
41
|
+
* @returns New root hash and key
|
|
42
|
+
*/
|
|
43
|
+
export declare function writeAtEncrypted(config: WriteAtConfig, rootHash: Hash, rootKey: EncryptionKey, offset: number, data: Uint8Array): Promise<WriteAtEncryptedResult>;
|
|
44
|
+
//# sourceMappingURL=writeAt.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeAt.d.ts","sourceRoot":"","sources":["../../src/tree/writeAt.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,KAAK,EAAE,IAAI,EAAmC,MAAM,aAAa,CAAC;AAG3E,OAAO,EAA0B,KAAK,aAAa,EAAE,MAAM,cAAc,CAAC;AAE1E,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,KAAK,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,uCAAuC;IACvC,IAAI,EAAE,IAAI,CAAC;IACX,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,sBAAuB,SAAQ,aAAa;IAC3D,sCAAsC;IACtC,GAAG,EAAE,aAAa,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAsB,OAAO,CAC3B,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,IAAI,EACd,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,aAAa,CAAC,CAuCxB;AAED;;;;;;;;;GASG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,IAAI,EACd,OAAO,EAAE,aAAa,EACtB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,UAAU,GACf,OAAO,CAAC,sBAAsB,CAAC,CA2CjC"}
|