From 86b7acdd4b96df5d2b9ab7c527b5b491c48d8964 Mon Sep 17 00:00:00 2001 From: Tejasv Sharma Date: Mon, 23 Sep 2024 15:56:05 +0530 Subject: [PATCH] fix: update chunking methods to send at least a single chunk --- packages/app-inheritance/src/utils/operationHelper.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/app-inheritance/src/utils/operationHelper.ts b/packages/app-inheritance/src/utils/operationHelper.ts index 81cd8f38..3287afbd 100644 --- a/packages/app-inheritance/src/utils/operationHelper.ts +++ b/packages/app-inheritance/src/utils/operationHelper.ts @@ -94,9 +94,10 @@ export class OperationHelper { >(data: Uint8Array, queryKey: QK, resultKey: RK) { const chunks = OperationHelper.splitIntoChunks(data); let remainingSize = data.length; + let i = 0; - for (let i = 0; i < chunks.length; i += 1) { - const chunk = chunks[i]; + do { + const chunk = chunks[i] ?? []; remainingSize -= chunk.length; const chunkPayload: ChunkPayload = { @@ -121,7 +122,8 @@ export class OperationHelper { assertOrThrowInvalidResult(chunkAck); assertOrThrowInvalidResult(chunkAck.chunkIndex === i); - } + i += 1; + } while (i < chunks.length); } public async receiveInChunks< @@ -152,7 +154,7 @@ export class OperationHelper { if ( chunkPayload.remainingSize === 0 && - chunkPayload.chunkIndex + 1 === chunkPayload.totalChunks + chunkPayload.chunkIndex + 1 >= chunkPayload.totalChunks ) { break; }