Skip to content

Commit

Permalink
lib,zlib: fix brotli flush range
Browse files Browse the repository at this point in the history
  • Loading branch information
XadillaX committed Apr 26, 2021
1 parent 55745a1 commit c6be2f6
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions lib/zlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const {
BROTLI_DECODE, BROTLI_ENCODE,
// Brotli operations (~flush levels)
BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_FLUSH,
BROTLI_OPERATION_FINISH
BROTLI_OPERATION_FINISH, BROTLI_OPERATION_EMIT_METADATA,
} = constants;

// Translation table for return codes.
Expand Down Expand Up @@ -238,8 +238,15 @@ const checkRangesOrGetDefault = hideStackFrames(
}
);

function isBrotliHandle(handle) {
return (handle instanceof binding.BrotliEncoder) ||
(handle instanceof binding.BrotliDecoder);
}

// The base class for all Zlib-style streams.
function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
const isBrotli = isBrotliHandle(handle);

let chunkSize = Z_DEFAULT_CHUNK;
let maxOutputLength = kMaxLength;
// The ZlibBase class is not exported to user land, the mode should only be
Expand All @@ -256,13 +263,27 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
`>= ${Z_MIN_CHUNK}`, chunkSize);
}

flush = checkRangesOrGetDefault(
opts.flush, 'options.flush',
Z_NO_FLUSH, Z_BLOCK, flush);
if (!isBrotli) {
flush = checkRangesOrGetDefault(
opts.flush, 'options.flush',
Z_NO_FLUSH, Z_BLOCK, flush);

finishFlush = checkRangesOrGetDefault(
opts.finishFlush, 'options.finishFlush',
Z_NO_FLUSH, Z_BLOCK, finishFlush);
finishFlush = checkRangesOrGetDefault(
opts.finishFlush, 'options.finishFlush',
Z_NO_FLUSH, Z_BLOCK, finishFlush);
} else {
flush = checkRangesOrGetDefault(
opts.flush, 'options.flush',
BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_EMIT_METADATA, flush);

finishFlush = checkRangesOrGetDefault(
opts.finishFlush, 'options.finishFlush',
BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_EMIT_METADATA, finishFlush);

fullFlush = checkRangesOrGetDefault(
opts.finishFlush, 'options.finishFlush',
BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_EMIT_METADATA, finishFlush);
}

maxOutputLength = checkRangesOrGetDefault(
opts.maxOutputLength, 'options.maxOutputLength',
Expand Down

0 comments on commit c6be2f6

Please sign in to comment.