Skip to content

Commit c6be2f6

Browse files
committed
lib,zlib: fix brotli flush range
Refs: nodejs#38407
1 parent 55745a1 commit c6be2f6

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

lib/zlib.js

+28-7
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const {
8989
BROTLI_DECODE, BROTLI_ENCODE,
9090
// Brotli operations (~flush levels)
9191
BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_FLUSH,
92-
BROTLI_OPERATION_FINISH
92+
BROTLI_OPERATION_FINISH, BROTLI_OPERATION_EMIT_METADATA,
9393
} = constants;
9494

9595
// Translation table for return codes.
@@ -238,8 +238,15 @@ const checkRangesOrGetDefault = hideStackFrames(
238238
}
239239
);
240240

241+
function isBrotliHandle(handle) {
242+
return (handle instanceof binding.BrotliEncoder) ||
243+
(handle instanceof binding.BrotliDecoder);
244+
}
245+
241246
// The base class for all Zlib-style streams.
242247
function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
248+
const isBrotli = isBrotliHandle(handle);
249+
243250
let chunkSize = Z_DEFAULT_CHUNK;
244251
let maxOutputLength = kMaxLength;
245252
// The ZlibBase class is not exported to user land, the mode should only be
@@ -256,13 +263,27 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
256263
`>= ${Z_MIN_CHUNK}`, chunkSize);
257264
}
258265

259-
flush = checkRangesOrGetDefault(
260-
opts.flush, 'options.flush',
261-
Z_NO_FLUSH, Z_BLOCK, flush);
266+
if (!isBrotli) {
267+
flush = checkRangesOrGetDefault(
268+
opts.flush, 'options.flush',
269+
Z_NO_FLUSH, Z_BLOCK, flush);
262270

263-
finishFlush = checkRangesOrGetDefault(
264-
opts.finishFlush, 'options.finishFlush',
265-
Z_NO_FLUSH, Z_BLOCK, finishFlush);
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+
283+
fullFlush = checkRangesOrGetDefault(
284+
opts.finishFlush, 'options.finishFlush',
285+
BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_EMIT_METADATA, finishFlush);
286+
}
266287

267288
maxOutputLength = checkRangesOrGetDefault(
268289
opts.maxOutputLength, 'options.maxOutputLength',

0 commit comments

Comments
 (0)