diff --git a/lib/zlib.js b/lib/zlib.js index 4d482addeac8f9..24242ca10113c4 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -242,15 +242,11 @@ 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 @@ -258,6 +254,13 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) { 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')) { @@ -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',