Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
XadillaX committed Apr 27, 2021
1 parent b4420d5 commit 5702db3
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/zlib.js
Expand Up @@ -242,22 +242,25 @@ const FLUSH_BOUND = [
[ Z_NO_FLUSH, Z_BLOCK ],
[ BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_EMIT_METADATA ],
];
function isBrotliHandle(handle) {
return ((handle instanceof binding.BrotliEncoder) ||
(handle instanceof binding.BrotliDecoder)) ? 1 : 0;
}
const FLUSH_BOUND_IDX_NORMAL = 0;
const FLUSH_BOUND_IDX_BROTLI = 1;

// 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
// passed in by us.
assert(typeof mode === 'number');
assert(mode >= DEFLATE && mode <= BROTLI_ENCODE);

let flushBoundIdx;
if (mode !== BROTLI_ENCODE && mode !== BROTLI_DECODE) {
flushBoundIdx = FLUSH_BOUND_IDX_NORMAL;
} else {
flushBoundIdx = FLUSH_BOUND_IDX_BROTLI;
}

if (opts) {
chunkSize = opts.chunkSize;
if (!checkFiniteNumber(chunkSize, 'options.chunkSize')) {
Expand All @@ -269,11 +272,11 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {

flush = checkRangesOrGetDefault(
opts.flush, 'options.flush',
FLUSH_BOUND[isBrotli][0], FLUSH_BOUND[isBrotli][1], flush);
FLUSH_BOUND[flushBoundIdx][0], FLUSH_BOUND[flushBoundIdx][1], flush);

finishFlush = checkRangesOrGetDefault(
opts.finishFlush, 'options.finishFlush',
FLUSH_BOUND[isBrotli][0], FLUSH_BOUND[isBrotli][1], finishFlush);
FLUSH_BOUND[flushBoundIdx][0], FLUSH_BOUND[flushBoundIdx][1], finishFlush);

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

0 comments on commit 5702db3

Please sign in to comment.