Skip to content

Commit

Permalink
chore: hoist idx_boundary
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr committed May 17, 2023
1 parent 129e785 commit 4f49f56
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/browser.ts
Expand Up @@ -16,13 +16,14 @@ async function* generate<T>(
let buffer = '';
let is_preamble = true;
let payloads = [];
let idx_boundary = 0;

try {
let result: ReadableStreamReadResult<Uint8Array>;
outer: while (!(result = await reader.read()).done) {
const chunk = decoder.decode(result.value);

let idx_boundary = buffer.length;
idx_boundary = buffer.length;
buffer += chunk;

const idx_chunk = chunk.indexOf(boundary);
Expand Down
3 changes: 2 additions & 1 deletion src/node.ts
Expand Up @@ -15,9 +15,10 @@ async function* generate<T>(
let buffer = Buffer.alloc(0);
let is_preamble = true;
let payloads = [];
let idx_boundary = 0;

outer: for await (const chunk of stream) {
let idx_boundary = buffer.byteLength;
idx_boundary = buffer.byteLength;
buffer = Buffer.concat([buffer, chunk]);

const idx_chunk = (chunk as Buffer).indexOf(boundary);
Expand Down

0 comments on commit 4f49f56

Please sign in to comment.