Skip to content

Commit

Permalink
chore: added comments for stream ending prematurely
Browse files Browse the repository at this point in the history
  • Loading branch information
aryanjassal committed Aug 26, 2024
1 parent c2723ac commit 497e0e5
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/vaults/fileTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,17 +542,20 @@ function parserTransformStreamFactory(): TransformStream<
};
jsonParser.write(initialChunk);
};
let processed: boolean = false;
/* Check if any chunks have been processed. If the stream is being flushed
* without processing any chunks, then something went wrong with the stream.
*/
let processedChunks: boolean = false;
return new TransformStream<Uint8Array, TreeNode | ContentNode | Uint8Array>({
flush: (controller) => {
if (!processed) {
if (!processedChunks) {
controller.error(
new validationErrors.ErrorParse('Stream ended prematurely'),
);
}
},
transform: (chunk, controller) => {
if (chunk.byteLength > 0) processed = true;
if (chunk.byteLength > 0) processedChunks = true;
switch (phase) {
case 'START': {
workingBuffer = vaultsUtils.uint8ArrayConcat([workingBuffer, chunk]);
Expand Down

0 comments on commit 497e0e5

Please sign in to comment.