@dignetwork/dig-sdk 0.0.1-alpha.16 → 0.0.1-alpha.17
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/DataIntegrityTree/DataIntegrityTree.d.ts +1 -1
- package/dist/DataIntegrityTree/DataIntegrityTree.d.ts.map +1 -1
- package/dist/DataIntegrityTree/DataIntegrityTree.js +17 -3
- package/dist/utils/directoryUtils.d.ts.map +1 -1
- package/dist/utils/directoryUtils.js +9 -12
- package/package.json +1 -1
|
@@ -106,7 +106,7 @@ declare class DataIntegrityTree {
|
|
|
106
106
|
* @param rootHash - The root hash of the tree. Defaults to the latest root hash.
|
|
107
107
|
* @returns The readable stream for the file.
|
|
108
108
|
*/
|
|
109
|
-
getValueStream(hexKey: string, rootHash?: string | null): Readable;
|
|
109
|
+
getValueStream(hexKey: string, rootHash?: string | null, byteOffset?: number | null, length?: number | null): Readable;
|
|
110
110
|
/**
|
|
111
111
|
* Delete all leaves from the Merkle tree.
|
|
112
112
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataIntegrityTree.d.ts","sourceRoot":"","sources":["../../src/DataIntegrityTree/DataIntegrityTree.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAuClC,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;GAEG;AACH,cAAM,iBAAiB;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAS;IACjB,K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ASG;IACH,MAAM,CAAC,mCAAmC,CACxC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,MAAM,EACtB,gBAAgB,EAAE,MAAM,GACvB,OAAO;CAgDX;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -423,7 +423,7 @@ class DataIntegrityTree {
|
|
|
423
423
|
* @param rootHash - The root hash of the tree. Defaults to the latest root hash.
|
|
424
424
|
* @returns The readable stream for the file.
|
|
425
425
|
*/
|
|
426
|
-
getValueStream(hexKey, rootHash = null) {
|
|
426
|
+
getValueStream(hexKey, rootHash = null, byteOffset = null, length = null) {
|
|
427
427
|
if (!isHexString(hexKey)) {
|
|
428
428
|
throw new Error("key must be a valid hex string");
|
|
429
429
|
}
|
|
@@ -446,8 +446,22 @@ class DataIntegrityTree {
|
|
|
446
446
|
if (!fs.existsSync(filePath)) {
|
|
447
447
|
throw new Error(`File at path ${filePath} does not exist`);
|
|
448
448
|
}
|
|
449
|
-
|
|
450
|
-
|
|
449
|
+
const fileSize = fs.statSync(filePath).size;
|
|
450
|
+
// Validate offset and length
|
|
451
|
+
if (byteOffset !== null && length !== null) {
|
|
452
|
+
if (byteOffset + length > fileSize) {
|
|
453
|
+
throw new Error(`Offset (${byteOffset}) and length (${length}) exceed the file size (${fileSize}).`);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
// Create the read stream with optional byte range
|
|
457
|
+
const options = {};
|
|
458
|
+
if (byteOffset !== null) {
|
|
459
|
+
options.start = byteOffset;
|
|
460
|
+
}
|
|
461
|
+
if (length !== null && byteOffset !== null) {
|
|
462
|
+
options.end = byteOffset + length - 1; // `end` is inclusive, hence `byteOffset + length - 1`
|
|
463
|
+
}
|
|
464
|
+
const readStream = fs.createReadStream(filePath, options);
|
|
451
465
|
const decompressStream = zlib.createGunzip();
|
|
452
466
|
// Return the combined stream as a generic Readable stream
|
|
453
467
|
return readStream.pipe(decompressStream);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"directoryUtils.d.ts","sourceRoot":"","sources":["../../src/utils/directoryUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"directoryUtils.d.ts","sourceRoot":"","sources":["../../src/utils/directoryUtils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AA+BzD,eAAO,MAAM,YAAY,cACZ,iBAAiB,WACnB,MAAM,YACN,MAAM,KACd,OAAO,CAAC,IAAI,CA4Cd,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,eAAgB,MAAM,KAAG,MAiBxD,CAAC"}
|
|
@@ -32,22 +32,23 @@ const fs = __importStar(require("fs"));
|
|
|
32
32
|
const ignore_1 = __importDefault(require("ignore"));
|
|
33
33
|
// Custom concurrency handler
|
|
34
34
|
const limitConcurrency = async (concurrencyLimit, tasks) => {
|
|
35
|
-
const results = [];
|
|
36
35
|
const executing = [];
|
|
37
36
|
for (const task of tasks) {
|
|
38
37
|
const p = task();
|
|
39
|
-
|
|
38
|
+
// Add the new task to the executing array
|
|
39
|
+
executing.push(p);
|
|
40
|
+
// When a task completes, remove it from the executing array
|
|
41
|
+
const cleanup = p.finally(() => {
|
|
42
|
+
executing.splice(executing.indexOf(cleanup), 1);
|
|
43
|
+
});
|
|
40
44
|
// Once the limit is reached, wait for one to complete
|
|
41
45
|
if (executing.length >= concurrencyLimit) {
|
|
46
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
42
47
|
await Promise.race(executing);
|
|
43
48
|
}
|
|
44
|
-
// Add the new task to the executing array
|
|
45
|
-
executing.push(p);
|
|
46
|
-
// When a task completes, remove it from the executing array
|
|
47
|
-
p.finally(() => executing.splice(executing.indexOf(p), 1));
|
|
48
49
|
}
|
|
49
50
|
// Wait for all remaining tasks to complete
|
|
50
|
-
return Promise.all(
|
|
51
|
+
return Promise.all(executing);
|
|
51
52
|
};
|
|
52
53
|
const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
53
54
|
const ig = (0, ignore_1.default)();
|
|
@@ -77,14 +78,10 @@ const addDirectory = async (datalayer, dirPath, baseDir = dirPath) => {
|
|
|
77
78
|
const stream = fs.createReadStream(filePath);
|
|
78
79
|
datalayer
|
|
79
80
|
.upsertKey(stream, Buffer.from(relativePath).toString("hex"))
|
|
80
|
-
.then(
|
|
81
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
82
|
-
resolve();
|
|
83
|
-
})
|
|
81
|
+
.then(() => resolve())
|
|
84
82
|
.catch(reject);
|
|
85
83
|
}));
|
|
86
84
|
}
|
|
87
|
-
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
88
85
|
}
|
|
89
86
|
// Run tasks with limited concurrency (set the concurrency limit as needed)
|
|
90
87
|
await limitConcurrency(10, tasks); // Adjust 10 based on your system limits
|