Skip to content

Commit 574990d

Browse files
committed
f
1 parent a3d06b6 commit 574990d

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

lib/zlib.js

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,13 @@ const checkRangesOrGetDefault = hideStackFrames(
238238
}
239239
);
240240

241+
const FLUSH_BOUND = [
242+
[ Z_NO_FLUSH, Z_BLOCK ],
243+
[ BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_EMIT_METADATA ],
244+
];
241245
function isBrotliHandle(handle) {
242-
return (handle instanceof binding.BrotliEncoder) ||
243-
(handle instanceof binding.BrotliDecoder);
246+
return ((handle instanceof binding.BrotliEncoder) ||
247+
(handle instanceof binding.BrotliDecoder)) ? 1 : 0;
244248
}
245249

246250
// The base class for all Zlib-style streams.
@@ -263,23 +267,13 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
263267
`>= ${Z_MIN_CHUNK}`, chunkSize);
264268
}
265269

266-
if (!isBrotli) {
267-
flush = checkRangesOrGetDefault(
268-
opts.flush, 'options.flush',
269-
Z_NO_FLUSH, Z_BLOCK, flush);
270+
flush = checkRangesOrGetDefault(
271+
opts.flush, 'options.flush',
272+
FLUSH_BOUND[isBrotli][0], FLUSH_BOUND[isBrotli][1], flush);
270273

271-
finishFlush = checkRangesOrGetDefault(
272-
opts.finishFlush, 'options.finishFlush',
273-
Z_NO_FLUSH, Z_BLOCK, finishFlush);
274-
} else {
275-
flush = checkRangesOrGetDefault(
276-
opts.flush, 'options.flush',
277-
BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_EMIT_METADATA, flush);
278-
279-
finishFlush = checkRangesOrGetDefault(
280-
opts.finishFlush, 'options.finishFlush',
281-
BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_EMIT_METADATA, finishFlush);
282-
}
274+
finishFlush = checkRangesOrGetDefault(
275+
opts.finishFlush, 'options.finishFlush',
276+
FLUSH_BOUND[isBrotli][0], FLUSH_BOUND[isBrotli][1], finishFlush);
283277

284278
maxOutputLength = checkRangesOrGetDefault(
285279
opts.maxOutputLength, 'options.maxOutputLength',

0 commit comments

Comments
 (0)