@@ -86,7 +86,7 @@ const {
86
86
BROTLI_DECODE , BROTLI_ENCODE ,
87
87
// Brotli operations (~flush levels)
88
88
BROTLI_OPERATION_PROCESS , BROTLI_OPERATION_FLUSH ,
89
- BROTLI_OPERATION_FINISH
89
+ BROTLI_OPERATION_FINISH , BROTLI_OPERATION_EMIT_METADATA ,
90
90
} = constants ;
91
91
92
92
// Translation table for return codes.
@@ -236,6 +236,13 @@ const checkRangesOrGetDefault = hideStackFrames(
236
236
}
237
237
) ;
238
238
239
+ const FLUSH_BOUND = [
240
+ [ Z_NO_FLUSH , Z_BLOCK ] ,
241
+ [ BROTLI_OPERATION_PROCESS , BROTLI_OPERATION_EMIT_METADATA ] ,
242
+ ] ;
243
+ const FLUSH_BOUND_IDX_NORMAL = 0 ;
244
+ const FLUSH_BOUND_IDX_BROTLI = 1 ;
245
+
239
246
// The base class for all Zlib-style streams.
240
247
function ZlibBase ( opts , mode , handle , { flush, finishFlush, fullFlush } ) {
241
248
let chunkSize = Z_DEFAULT_CHUNK ;
@@ -245,6 +252,13 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
245
252
assert ( typeof mode === 'number' ) ;
246
253
assert ( mode >= DEFLATE && mode <= BROTLI_ENCODE ) ;
247
254
255
+ let flushBoundIdx ;
256
+ if ( mode !== BROTLI_ENCODE && mode !== BROTLI_DECODE ) {
257
+ flushBoundIdx = FLUSH_BOUND_IDX_NORMAL ;
258
+ } else {
259
+ flushBoundIdx = FLUSH_BOUND_IDX_BROTLI ;
260
+ }
261
+
248
262
if ( opts ) {
249
263
chunkSize = opts . chunkSize ;
250
264
if ( ! checkFiniteNumber ( chunkSize , 'options.chunkSize' ) ) {
@@ -256,11 +270,12 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
256
270
257
271
flush = checkRangesOrGetDefault (
258
272
opts . flush , 'options.flush' ,
259
- Z_NO_FLUSH , Z_BLOCK , flush ) ;
273
+ FLUSH_BOUND [ flushBoundIdx ] [ 0 ] , FLUSH_BOUND [ flushBoundIdx ] [ 1 ] , flush ) ;
260
274
261
275
finishFlush = checkRangesOrGetDefault (
262
276
opts . finishFlush , 'options.finishFlush' ,
263
- Z_NO_FLUSH , Z_BLOCK , finishFlush ) ;
277
+ FLUSH_BOUND [ flushBoundIdx ] [ 0 ] , FLUSH_BOUND [ flushBoundIdx ] [ 1 ] ,
278
+ finishFlush ) ;
264
279
265
280
maxOutputLength = checkRangesOrGetDefault (
266
281
opts . maxOutputLength , 'options.maxOutputLength' ,
0 commit comments