@@ -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,6 +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+ ] ;
245+ const FLUSH_BOUND_IDX_NORMAL = 0 ;
246+ const FLUSH_BOUND_IDX_BROTLI = 1 ;
247+
241248// The base class for all Zlib-style streams.
242249function ZlibBase ( opts , mode , handle , { flush, finishFlush, fullFlush } ) {
243250 let chunkSize = Z_DEFAULT_CHUNK ;
@@ -247,6 +254,13 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
247254 assert ( typeof mode === 'number' ) ;
248255 assert ( mode >= DEFLATE && mode <= BROTLI_ENCODE ) ;
249256
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+
250264 if ( opts ) {
251265 chunkSize = opts . chunkSize ;
252266 if ( ! checkFiniteNumber ( chunkSize , 'options.chunkSize' ) ) {
@@ -258,11 +272,12 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
258272
259273 flush = checkRangesOrGetDefault (
260274 opts . flush , 'options.flush' ,
261- Z_NO_FLUSH , Z_BLOCK , flush ) ;
275+ FLUSH_BOUND [ flushBoundIdx ] [ 0 ] , FLUSH_BOUND [ flushBoundIdx ] [ 1 ] , flush ) ;
262276
263277 finishFlush = checkRangesOrGetDefault (
264278 opts . finishFlush , 'options.finishFlush' ,
265- Z_NO_FLUSH , Z_BLOCK , finishFlush ) ;
279+ FLUSH_BOUND [ flushBoundIdx ] [ 0 ] , FLUSH_BOUND [ flushBoundIdx ] [ 1 ] ,
280+ finishFlush ) ;
266281
267282 maxOutputLength = checkRangesOrGetDefault (
268283 opts . maxOutputLength , 'options.maxOutputLength' ,
0 commit comments