Skip to content

Commit 5702db3

Browse files
committed
f
1 parent b4420d5 commit 5702db3

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/zlib.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,22 +242,25 @@ const FLUSH_BOUND = [
242242
[ Z_NO_FLUSH, Z_BLOCK ],
243243
[ BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_EMIT_METADATA ],
244244
];
245-
function isBrotliHandle(handle) {
246-
return ((handle instanceof binding.BrotliEncoder) ||
247-
(handle instanceof binding.BrotliDecoder)) ? 1 : 0;
248-
}
245+
const FLUSH_BOUND_IDX_NORMAL = 0;
246+
const FLUSH_BOUND_IDX_BROTLI = 1;
249247

250248
// The base class for all Zlib-style streams.
251249
function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
252-
const isBrotli = isBrotliHandle(handle);
253-
254250
let chunkSize = Z_DEFAULT_CHUNK;
255251
let maxOutputLength = kMaxLength;
256252
// The ZlibBase class is not exported to user land, the mode should only be
257253
// passed in by us.
258254
assert(typeof mode === 'number');
259255
assert(mode >= DEFLATE && mode <= BROTLI_ENCODE);
260256

257+
let flushBoundIdx;
258+
if (mode !== BROTLI_ENCODE && mode !== BROTLI_DECODE) {
259+
flushBoundIdx = FLUSH_BOUND_IDX_NORMAL;
260+
} else {
261+
flushBoundIdx = FLUSH_BOUND_IDX_BROTLI;
262+
}
263+
261264
if (opts) {
262265
chunkSize = opts.chunkSize;
263266
if (!checkFiniteNumber(chunkSize, 'options.chunkSize')) {
@@ -269,11 +272,11 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
269272

270273
flush = checkRangesOrGetDefault(
271274
opts.flush, 'options.flush',
272-
FLUSH_BOUND[isBrotli][0], FLUSH_BOUND[isBrotli][1], flush);
275+
FLUSH_BOUND[flushBoundIdx][0], FLUSH_BOUND[flushBoundIdx][1], flush);
273276

274277
finishFlush = checkRangesOrGetDefault(
275278
opts.finishFlush, 'options.finishFlush',
276-
FLUSH_BOUND[isBrotli][0], FLUSH_BOUND[isBrotli][1], finishFlush);
279+
FLUSH_BOUND[flushBoundIdx][0], FLUSH_BOUND[flushBoundIdx][1], finishFlush);
277280

278281
maxOutputLength = checkRangesOrGetDefault(
279282
opts.maxOutputLength, 'options.maxOutputLength',

0 commit comments

Comments
 (0)