Skip to content

Commit

Permalink
fix(js): don't use the spread operator to append a large array (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
btwiuse authored Aug 15, 2024
1 parent dc5cf13 commit 6d3c16c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions js/compress-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ const main = async () => {

const compressedReadableStream = new Response(buf).body.pipeThrough(cs);

const resultArr = [];

const reader = compressedReadableStream.getReader();

let resultArr = [];

while (true) {
const read = await reader.read();

if (read.done) break;

resultArr.push(...read.value);
resultArr = resultArr.concat(Array.from(read.value));
}

const base64Bytes = Buffer.from(Uint8Array.from(resultArr).buffer).toString('base64');
Expand Down
4 changes: 2 additions & 2 deletions js/src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ export class WasmParser {
const decompressed = new Response(binaryBase64).body.pipeThrough<Uint8Array>(ds);

const reader = decompressed.getReader();
const bytes = [];
let bytes = [];

while (true) {
const { value, done } = await reader.read();

if (done) break;

bytes.push(...value);
bytes = bytes.concat(Array.from(value));
}

return new Uint8Array(bytes).buffer;
Expand Down

0 comments on commit 6d3c16c

Please sign in to comment.