summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/_brotli.js
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2024-02-07 21:53:32 +0530
committerGitHub <noreply@github.com>2024-02-07 21:53:32 +0530
commita32e7f0eb23fa17f5af2fc4c8abfd79762934244 (patch)
treef1c0a23a800974f8311dc45f044692b04868fb23 /ext/node/polyfills/_brotli.js
parente5ae142fbeb83ec5b335a0a3fcb7a564cbf65bd4 (diff)
fix(node): handle brotli compression end chunk sizes (#22322)
Fixes https://github.com/denoland/deno/issues/22259
Diffstat (limited to 'ext/node/polyfills/_brotli.js')
-rw-r--r--ext/node/polyfills/_brotli.js15
1 files changed, 10 insertions, 5 deletions
diff --git a/ext/node/polyfills/_brotli.js b/ext/node/polyfills/_brotli.js
index c815add22..b019836cf 100644
--- a/ext/node/polyfills/_brotli.js
+++ b/ext/node/polyfills/_brotli.js
@@ -51,7 +51,7 @@ export class BrotliDecompress extends Transform {
// TODO(littledivy): use `encoding` argument
transform(chunk, _encoding, callback) {
const input = toU8(chunk);
- const output = new Uint8Array(1024);
+ const output = new Uint8Array(chunk.byteLength);
const avail = op_brotli_decompress_stream(context, input, output);
this.push(output.slice(0, avail));
callback();
@@ -76,14 +76,19 @@ export class BrotliCompress extends Transform {
transform(chunk, _encoding, callback) {
const input = toU8(chunk);
const output = new Uint8Array(brotliMaxCompressedSize(input.length));
- const avail = op_brotli_compress_stream(context, input, output);
- this.push(output.slice(0, avail));
+ const written = op_brotli_compress_stream(context, input, output);
+ if (written > 0) {
+ this.push(output.slice(0, written));
+ }
callback();
},
flush(callback) {
const output = new Uint8Array(1024);
- const avail = op_brotli_compress_stream_end(context, output);
- this.push(output.slice(0, avail));
+ let avail;
+ while ((avail = op_brotli_compress_stream_end(context, output)) > 0) {
+ this.push(output.slice(0, avail));
+ }
+ core.close(context);
callback();
},
});