rac-delta 1.0.13 → 1.0.15

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.
@@ -80,7 +80,7 @@ class StorageChunkSource {
80
80
  if (!stream) {
81
81
  throw new exceptions_1.ChunkNotFoundException(`${hash} not found in storage`);
82
82
  }
83
- const pass = new stream_1.PassThrough({ highWaterMark: 64 * 1024 });
83
+ const pass = new stream_1.PassThrough({ highWaterMark: 1024 * 1024 });
84
84
  stream.on('error', (err) => {
85
85
  workerError = err instanceof Error ? err : new Error(String(err));
86
86
  controller.abort();
@@ -1 +1 @@
1
- {"version":3,"file":"memory-reconstruction-service.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/services/memory-reconstruction-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAyB,MAAM,QAAQ,CAAC;AAIzD,OAAO,EACL,WAAW,EAEX,aAAa,EACb,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAS,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,qBAAa,2BAA4B,YAAW,qBAAqB;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAE5C,cAAc,CAClB,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,GACvC,OAAO,CAAC,IAAI,CAAC;IAmFV,eAAe,CACnB,KAAK,EAAE,SAAS,EAChB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,WAAW,EACxB,OAAO,GAAE,qBAIR,GACA,OAAO,CAAC,IAAI,CAAC;IAgDV,mBAAmB,CACvB,KAAK,EAAE,SAAS,EAChB,WAAW,EAAE,WAAW,EACxB,cAAc,GAAE,MAAU,GACzB,OAAO,CAAC,QAAQ,CAAC;YAmCN,UAAU;IASxB,oEAAoE;YACtD,kBAAkB;IAiChC,oFAAoF;YACtE,iBAAiB;IAmF/B;;;OAGG;YACW,qBAAqB;YA2BrB,YAAY;YAcZ,aAAa;YAuDZ,gBAAgB;CAmChC"}
1
+ {"version":3,"file":"memory-reconstruction-service.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/services/memory-reconstruction-service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAyB,MAAM,QAAQ,CAAC;AAIzD,OAAO,EACL,WAAW,EAEX,aAAa,EACb,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAS,MAAM,mBAAmB,CAAC;AAEhE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,qBAAa,2BAA4B,YAAW,qBAAqB;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,aAAa;IAE5C,cAAc,CAClB,IAAI,EAAE,SAAS,EACf,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,WAAW,EACxB,OAAO,CAAC,EAAE,OAAO,CAAC,qBAAqB,CAAC,GACvC,OAAO,CAAC,IAAI,CAAC;IAmFV,eAAe,CACnB,KAAK,EAAE,SAAS,EAChB,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,WAAW,EACxB,OAAO,GAAE,qBAIR,GACA,OAAO,CAAC,IAAI,CAAC;IAgDV,mBAAmB,CACvB,KAAK,EAAE,SAAS,EAChB,WAAW,EAAE,WAAW,EACxB,cAAc,GAAE,MAAU,GACzB,OAAO,CAAC,QAAQ,CAAC;YA6CN,UAAU;IASxB,oEAAoE;YACtD,kBAAkB;IAiChC,oFAAoF;YACtE,iBAAiB;IAmF/B;;;OAGG;YACW,qBAAqB;YA2BrB,YAAY;YAcZ,aAAa;YAyCZ,gBAAgB;CAmChC"}
@@ -112,31 +112,42 @@ class MemoryReconstructionService {
112
112
  }
113
113
  // This will reconstruct to stream, not to disk
114
114
  async reconstructToStream(entry, chunkSource, maxConcurrency = 5) {
115
- const output = new stream_1.PassThrough({ highWaterMark: 1024 * 1024 });
116
115
  const chunks = entry.chunks ?? [];
117
- // Starts async reconstruction without blocking stream return
118
- const processChunks = async () => {
116
+ const iterator = this.fetchChunksSmart(chunks, chunkSource, true);
117
+ const pass = new stream_1.PassThrough({ highWaterMark: 2 * 1024 * 1024 });
118
+ (async () => {
119
119
  try {
120
120
  const active = new Set();
121
- for await (const { data } of this.fetchChunksSmart(chunks, chunkSource)) {
121
+ for await (const { data } of iterator) {
122
122
  const task = (async () => {
123
- await this.writeToStream(data, output);
123
+ if (Buffer.isBuffer(data)) {
124
+ if (!pass.write(data)) {
125
+ await new Promise((resolve) => pass.once('drain', resolve));
126
+ }
127
+ }
128
+ else {
129
+ await new Promise((resolve, reject) => {
130
+ data.on('error', reject);
131
+ pass.on('error', reject);
132
+ data.pipe(pass, { end: false });
133
+ data.on('end', resolve);
134
+ });
135
+ }
124
136
  })();
125
- task.finally(() => active.delete(task));
126
137
  active.add(task);
138
+ task.finally(() => active.delete(task));
127
139
  if (active.size >= maxConcurrency) {
128
- await Promise.race(active);
140
+ const finished = await Promise.race(active);
129
141
  }
130
142
  }
131
143
  await Promise.all(active);
132
- output.end();
144
+ pass.end();
133
145
  }
134
146
  catch (err) {
135
- output.destroy(err instanceof Error ? err : new Error(String(err)));
147
+ pass.destroy(err instanceof Error ? err : new Error(String(err)));
136
148
  }
137
- };
138
- void processChunks();
139
- return output;
149
+ })();
150
+ return pass;
140
151
  }
141
152
  async fileExists(path) {
142
153
  try {
@@ -272,41 +283,28 @@ class MemoryReconstructionService {
272
283
  return;
273
284
  }
274
285
  if (Buffer.isBuffer(data)) {
275
- const canContinue = stream.write(data);
276
- if (!canContinue) {
286
+ if (!stream.write(data)) {
277
287
  await new Promise((resolve) => stream.once('drain', resolve));
278
288
  }
279
289
  onFinish?.(data.length);
280
290
  return;
281
291
  }
282
292
  let totalBytes = 0;
283
- await new Promise((resolve, reject) => {
284
- const onError = (err) => {
285
- cleanup();
286
- reject(err instanceof Error ? err : new Error(String(err)));
287
- };
288
- const onEnd = () => {
289
- cleanup();
290
- onFinish?.(totalBytes);
291
- resolve();
292
- };
293
- const cleanup = () => {
294
- data.off('error', onError);
295
- data.off('end', onEnd);
296
- stream.off('error', onError);
297
- };
298
- data.on('error', onError);
299
- stream.on('error', onError);
300
- data.on('end', onEnd);
301
- data.on('data', (chunk) => {
293
+ await (0, promises_2.pipeline)(data, new stream_1.Writable({
294
+ write(chunk, _encoding, callBack) {
302
295
  totalBytes += chunk.length;
303
- const canContinue = stream.write(chunk);
304
- if (!canContinue) {
305
- data.pause();
306
- stream.once('drain', () => data.resume());
296
+ if (!stream.write(chunk)) {
297
+ stream.once('drain', callBack);
307
298
  }
308
- });
309
- });
299
+ else {
300
+ callBack();
301
+ }
302
+ },
303
+ final(callBack) {
304
+ callBack();
305
+ },
306
+ }));
307
+ onFinish?.(totalBytes);
310
308
  }
311
309
  async *fetchChunksSmart(chunks, chunkSource, preserveOrder = true) {
312
310
  const hashes = chunks.map((c) => c.hash);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rac-delta",
3
3
  "description": "Storage agnostic delta patching implementation of rac-delta protocol for NodeJs. With streaming support and file reconstruction.",
4
- "version": "1.0.13",
4
+ "version": "1.0.15",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "repository": {