@@ -242,22 +242,25 @@ const FLUSH_BOUND = [
242
242
[ Z_NO_FLUSH , Z_BLOCK ] ,
243
243
[ BROTLI_OPERATION_PROCESS , BROTLI_OPERATION_EMIT_METADATA ] ,
244
244
] ;
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 ;
249
247
250
248
// The base class for all Zlib-style streams.
251
249
function ZlibBase ( opts , mode , handle , { flush, finishFlush, fullFlush } ) {
252
- const isBrotli = isBrotliHandle ( handle ) ;
253
-
254
250
let chunkSize = Z_DEFAULT_CHUNK ;
255
251
let maxOutputLength = kMaxLength ;
256
252
// The ZlibBase class is not exported to user land, the mode should only be
257
253
// passed in by us.
258
254
assert ( typeof mode === 'number' ) ;
259
255
assert ( mode >= DEFLATE && mode <= BROTLI_ENCODE ) ;
260
256
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
+
261
264
if ( opts ) {
262
265
chunkSize = opts . chunkSize ;
263
266
if ( ! checkFiniteNumber ( chunkSize , 'options.chunkSize' ) ) {
@@ -269,11 +272,11 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
269
272
270
273
flush = checkRangesOrGetDefault (
271
274
opts . flush , 'options.flush' ,
272
- FLUSH_BOUND [ isBrotli ] [ 0 ] , FLUSH_BOUND [ isBrotli ] [ 1 ] , flush ) ;
275
+ FLUSH_BOUND [ flushBoundIdx ] [ 0 ] , FLUSH_BOUND [ flushBoundIdx ] [ 1 ] , flush ) ;
273
276
274
277
finishFlush = checkRangesOrGetDefault (
275
278
opts . finishFlush , 'options.finishFlush' ,
276
- FLUSH_BOUND [ isBrotli ] [ 0 ] , FLUSH_BOUND [ isBrotli ] [ 1 ] , finishFlush ) ;
279
+ FLUSH_BOUND [ flushBoundIdx ] [ 0 ] , FLUSH_BOUND [ flushBoundIdx ] [ 1 ] , finishFlush ) ;
277
280
278
281
maxOutputLength = checkRangesOrGetDefault (
279
282
opts . maxOutputLength , 'options.maxOutputLength' ,
0 commit comments