@@ -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,6 +238,13 @@ const checkRangesOrGetDefault = hideStackFrames(
238
238
}
239
239
) ;
240
240
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
+
241
248
// The base class for all Zlib-style streams.
242
249
function ZlibBase ( opts , mode , handle , { flush, finishFlush, fullFlush } ) {
243
250
let chunkSize = Z_DEFAULT_CHUNK ;
@@ -247,6 +254,13 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
247
254
assert ( typeof mode === 'number' ) ;
248
255
assert ( mode >= DEFLATE && mode <= BROTLI_ENCODE ) ;
249
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
+
250
264
if ( opts ) {
251
265
chunkSize = opts . chunkSize ;
252
266
if ( ! checkFiniteNumber ( chunkSize , 'options.chunkSize' ) ) {
@@ -258,11 +272,12 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
258
272
259
273
flush = checkRangesOrGetDefault (
260
274
opts . flush , 'options.flush' ,
261
- Z_NO_FLUSH , Z_BLOCK , flush ) ;
275
+ FLUSH_BOUND [ flushBoundIdx ] [ 0 ] , FLUSH_BOUND [ flushBoundIdx ] [ 1 ] , flush ) ;
262
276
263
277
finishFlush = checkRangesOrGetDefault (
264
278
opts . finishFlush , 'options.finishFlush' ,
265
- Z_NO_FLUSH , Z_BLOCK , finishFlush ) ;
279
+ FLUSH_BOUND [ flushBoundIdx ] [ 0 ] , FLUSH_BOUND [ flushBoundIdx ] [ 1 ] ,
280
+ finishFlush ) ;
266
281
267
282
maxOutputLength = checkRangesOrGetDefault (
268
283
opts . maxOutputLength , 'options.maxOutputLength' ,
0 commit comments