@@ -89,7 +89,7 @@ const {
89
89
BROTLI_DECODE , BROTLI_ENCODE ,
90
90
// Brotli operations (~flush levels)
91
91
BROTLI_OPERATION_PROCESS , BROTLI_OPERATION_FLUSH ,
92
- BROTLI_OPERATION_FINISH
92
+ BROTLI_OPERATION_FINISH , BROTLI_OPERATION_EMIT_METADATA ,
93
93
} = constants ;
94
94
95
95
// Translation table for return codes.
@@ -238,8 +238,15 @@ const checkRangesOrGetDefault = hideStackFrames(
238
238
}
239
239
) ;
240
240
241
+ function isBrotliHandle ( handle ) {
242
+ return ( handle instanceof binding . BrotliEncoder ) ||
243
+ ( handle instanceof binding . BrotliDecoder ) ;
244
+ }
245
+
241
246
// The base class for all Zlib-style streams.
242
247
function ZlibBase ( opts , mode , handle , { flush, finishFlush, fullFlush } ) {
248
+ const isBrotli = isBrotliHandle ( handle ) ;
249
+
243
250
let chunkSize = Z_DEFAULT_CHUNK ;
244
251
let maxOutputLength = kMaxLength ;
245
252
// 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 }) {
256
263
`>= ${ Z_MIN_CHUNK } ` , chunkSize ) ;
257
264
}
258
265
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 ) ;
262
270
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
+ }
266
287
267
288
maxOutputLength = checkRangesOrGetDefault (
268
289
opts . maxOutputLength , 'options.maxOutputLength' ,
0 commit comments