@@ -86,7 +86,7 @@ const {
8686 BROTLI_DECODE , BROTLI_ENCODE ,
8787 // Brotli operations (~flush levels)
8888 BROTLI_OPERATION_PROCESS , BROTLI_OPERATION_FLUSH ,
89- BROTLI_OPERATION_FINISH
89+ BROTLI_OPERATION_FINISH , BROTLI_OPERATION_EMIT_METADATA ,
9090} = constants ;
9191
9292// Translation table for return codes.
@@ -236,6 +236,13 @@ const checkRangesOrGetDefault = hideStackFrames(
236236 }
237237) ;
238238
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+
239246// The base class for all Zlib-style streams.
240247function ZlibBase ( opts , mode , handle , { flush, finishFlush, fullFlush } ) {
241248 let chunkSize = Z_DEFAULT_CHUNK ;
@@ -245,6 +252,13 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
245252 assert ( typeof mode === 'number' ) ;
246253 assert ( mode >= DEFLATE && mode <= BROTLI_ENCODE ) ;
247254
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+
248262 if ( opts ) {
249263 chunkSize = opts . chunkSize ;
250264 if ( ! checkFiniteNumber ( chunkSize , 'options.chunkSize' ) ) {
@@ -256,11 +270,12 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
256270
257271 flush = checkRangesOrGetDefault (
258272 opts . flush , 'options.flush' ,
259- Z_NO_FLUSH , Z_BLOCK , flush ) ;
273+ FLUSH_BOUND [ flushBoundIdx ] [ 0 ] , FLUSH_BOUND [ flushBoundIdx ] [ 1 ] , flush ) ;
260274
261275 finishFlush = checkRangesOrGetDefault (
262276 opts . finishFlush , 'options.finishFlush' ,
263- Z_NO_FLUSH , Z_BLOCK , finishFlush ) ;
277+ FLUSH_BOUND [ flushBoundIdx ] [ 0 ] , FLUSH_BOUND [ flushBoundIdx ] [ 1 ] ,
278+ finishFlush ) ;
264279
265280 maxOutputLength = checkRangesOrGetDefault (
266281 opts . maxOutputLength , 'options.maxOutputLength' ,
0 commit comments