Skip to content

Commit

Permalink
fix: update chunking methods to send at least a single chunk (#126)
Browse files Browse the repository at this point in the history
  • Loading branch information
TejasvOnly authored Sep 25, 2024
1 parent e0b4185 commit 9c229b0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/app-inheritance/src/utils/operationHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,16 @@ export class OperationHelper<Q extends QueryKey, R extends ResultKey> {
>(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 = {
chunk,
chunkIndex: i,
totalChunks: chunks.length,
totalChunks: Math.max(chunks.length, 1),
remainingSize,
};

Expand All @@ -121,7 +122,8 @@ export class OperationHelper<Q extends QueryKey, R extends ResultKey> {

assertOrThrowInvalidResult(chunkAck);
assertOrThrowInvalidResult(chunkAck.chunkIndex === i);
}
i += 1;
} while (i < chunks.length);
}

public async receiveInChunks<
Expand Down Expand Up @@ -152,7 +154,7 @@ export class OperationHelper<Q extends QueryKey, R extends ResultKey> {

if (
chunkPayload.remainingSize === 0 &&
chunkPayload.chunkIndex + 1 === chunkPayload.totalChunks
chunkPayload.chunkIndex + 1 >= chunkPayload.totalChunks
) {
break;
}
Expand Down

0 comments on commit 9c229b0

Please sign in to comment.