summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/_brotli.js
diff options
context:
space:
mode:
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();
},
});