11cb0ef41Sopenharmony_ci// Copyright Joyent, Inc. and other Node contributors. 21cb0ef41Sopenharmony_ci// 31cb0ef41Sopenharmony_ci// Permission is hereby granted, free of charge, to any person obtaining a 41cb0ef41Sopenharmony_ci// copy of this software and associated documentation files (the 51cb0ef41Sopenharmony_ci// "Software"), to deal in the Software without restriction, including 61cb0ef41Sopenharmony_ci// without limitation the rights to use, copy, modify, merge, publish, 71cb0ef41Sopenharmony_ci// distribute, sublicense, and/or sell copies of the Software, and to permit 81cb0ef41Sopenharmony_ci// persons to whom the Software is furnished to do so, subject to the 91cb0ef41Sopenharmony_ci// following conditions: 101cb0ef41Sopenharmony_ci// 111cb0ef41Sopenharmony_ci// The above copyright notice and this permission notice shall be included 121cb0ef41Sopenharmony_ci// in all copies or substantial portions of the Software. 131cb0ef41Sopenharmony_ci// 141cb0ef41Sopenharmony_ci// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 151cb0ef41Sopenharmony_ci// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 161cb0ef41Sopenharmony_ci// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 171cb0ef41Sopenharmony_ci// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 181cb0ef41Sopenharmony_ci// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 191cb0ef41Sopenharmony_ci// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 201cb0ef41Sopenharmony_ci// USE OR OTHER DEALINGS IN THE SOFTWARE. 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci'use strict'; 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ciconst { 251cb0ef41Sopenharmony_ci ArrayBuffer, 261cb0ef41Sopenharmony_ci ArrayPrototypeForEach, 271cb0ef41Sopenharmony_ci ArrayPrototypeMap, 281cb0ef41Sopenharmony_ci ArrayPrototypePush, 291cb0ef41Sopenharmony_ci FunctionPrototypeBind, 301cb0ef41Sopenharmony_ci MathMaxApply, 311cb0ef41Sopenharmony_ci NumberIsFinite, 321cb0ef41Sopenharmony_ci NumberIsNaN, 331cb0ef41Sopenharmony_ci ObjectDefineProperties, 341cb0ef41Sopenharmony_ci ObjectDefineProperty, 351cb0ef41Sopenharmony_ci ObjectFreeze, 361cb0ef41Sopenharmony_ci ObjectKeys, 371cb0ef41Sopenharmony_ci ObjectSetPrototypeOf, 381cb0ef41Sopenharmony_ci ReflectApply, 391cb0ef41Sopenharmony_ci StringPrototypeStartsWith, 401cb0ef41Sopenharmony_ci Symbol, 411cb0ef41Sopenharmony_ci TypedArrayPrototypeFill, 421cb0ef41Sopenharmony_ci Uint32Array, 431cb0ef41Sopenharmony_ci} = primordials; 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ciconst { 461cb0ef41Sopenharmony_ci codes: { 471cb0ef41Sopenharmony_ci ERR_BROTLI_INVALID_PARAM, 481cb0ef41Sopenharmony_ci ERR_BUFFER_TOO_LARGE, 491cb0ef41Sopenharmony_ci ERR_INVALID_ARG_TYPE, 501cb0ef41Sopenharmony_ci ERR_OUT_OF_RANGE, 511cb0ef41Sopenharmony_ci ERR_ZLIB_INITIALIZATION_FAILED, 521cb0ef41Sopenharmony_ci }, 531cb0ef41Sopenharmony_ci genericNodeError, 541cb0ef41Sopenharmony_ci hideStackFrames, 551cb0ef41Sopenharmony_ci} = require('internal/errors'); 561cb0ef41Sopenharmony_ciconst { Transform, finished } = require('stream'); 571cb0ef41Sopenharmony_ciconst { 581cb0ef41Sopenharmony_ci deprecate, 591cb0ef41Sopenharmony_ci} = require('internal/util'); 601cb0ef41Sopenharmony_ciconst { 611cb0ef41Sopenharmony_ci isArrayBufferView, 621cb0ef41Sopenharmony_ci isAnyArrayBuffer, 631cb0ef41Sopenharmony_ci isUint8Array, 641cb0ef41Sopenharmony_ci} = require('internal/util/types'); 651cb0ef41Sopenharmony_ciconst binding = internalBinding('zlib'); 661cb0ef41Sopenharmony_ciconst assert = require('internal/assert'); 671cb0ef41Sopenharmony_ciconst { 681cb0ef41Sopenharmony_ci Buffer, 691cb0ef41Sopenharmony_ci kMaxLength, 701cb0ef41Sopenharmony_ci} = require('buffer'); 711cb0ef41Sopenharmony_ciconst { owner_symbol } = require('internal/async_hooks').symbols; 721cb0ef41Sopenharmony_ciconst { 731cb0ef41Sopenharmony_ci validateFunction, 741cb0ef41Sopenharmony_ci validateNumber, 751cb0ef41Sopenharmony_ci} = require('internal/validators'); 761cb0ef41Sopenharmony_ci 771cb0ef41Sopenharmony_ciconst kFlushFlag = Symbol('kFlushFlag'); 781cb0ef41Sopenharmony_ciconst kError = Symbol('kError'); 791cb0ef41Sopenharmony_ci 801cb0ef41Sopenharmony_ciconst constants = internalBinding('constants').zlib; 811cb0ef41Sopenharmony_ciconst { 821cb0ef41Sopenharmony_ci // Zlib flush levels 831cb0ef41Sopenharmony_ci Z_NO_FLUSH, Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH, 841cb0ef41Sopenharmony_ci // Zlib option values 851cb0ef41Sopenharmony_ci Z_MIN_CHUNK, Z_MIN_WINDOWBITS, Z_MAX_WINDOWBITS, Z_MIN_LEVEL, Z_MAX_LEVEL, 861cb0ef41Sopenharmony_ci Z_MIN_MEMLEVEL, Z_MAX_MEMLEVEL, Z_DEFAULT_CHUNK, Z_DEFAULT_COMPRESSION, 871cb0ef41Sopenharmony_ci Z_DEFAULT_STRATEGY, Z_DEFAULT_WINDOWBITS, Z_DEFAULT_MEMLEVEL, Z_FIXED, 881cb0ef41Sopenharmony_ci // Node's compression stream modes (node_zlib_mode) 891cb0ef41Sopenharmony_ci DEFLATE, DEFLATERAW, INFLATE, INFLATERAW, GZIP, GUNZIP, UNZIP, 901cb0ef41Sopenharmony_ci BROTLI_DECODE, BROTLI_ENCODE, 911cb0ef41Sopenharmony_ci // Brotli operations (~flush levels) 921cb0ef41Sopenharmony_ci BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_FLUSH, 931cb0ef41Sopenharmony_ci BROTLI_OPERATION_FINISH, BROTLI_OPERATION_EMIT_METADATA, 941cb0ef41Sopenharmony_ci} = constants; 951cb0ef41Sopenharmony_ci 961cb0ef41Sopenharmony_ci// Translation table for return codes. 971cb0ef41Sopenharmony_ciconst codes = { 981cb0ef41Sopenharmony_ci Z_OK: constants.Z_OK, 991cb0ef41Sopenharmony_ci Z_STREAM_END: constants.Z_STREAM_END, 1001cb0ef41Sopenharmony_ci Z_NEED_DICT: constants.Z_NEED_DICT, 1011cb0ef41Sopenharmony_ci Z_ERRNO: constants.Z_ERRNO, 1021cb0ef41Sopenharmony_ci Z_STREAM_ERROR: constants.Z_STREAM_ERROR, 1031cb0ef41Sopenharmony_ci Z_DATA_ERROR: constants.Z_DATA_ERROR, 1041cb0ef41Sopenharmony_ci Z_MEM_ERROR: constants.Z_MEM_ERROR, 1051cb0ef41Sopenharmony_ci Z_BUF_ERROR: constants.Z_BUF_ERROR, 1061cb0ef41Sopenharmony_ci Z_VERSION_ERROR: constants.Z_VERSION_ERROR, 1071cb0ef41Sopenharmony_ci}; 1081cb0ef41Sopenharmony_ci 1091cb0ef41Sopenharmony_cifor (const ckey of ObjectKeys(codes)) { 1101cb0ef41Sopenharmony_ci codes[codes[ckey]] = ckey; 1111cb0ef41Sopenharmony_ci} 1121cb0ef41Sopenharmony_ci 1131cb0ef41Sopenharmony_cifunction zlibBuffer(engine, buffer, callback) { 1141cb0ef41Sopenharmony_ci validateFunction(callback, 'callback'); 1151cb0ef41Sopenharmony_ci // Streams do not support non-Uint8Array ArrayBufferViews yet. Convert it to a 1161cb0ef41Sopenharmony_ci // Buffer without copying. 1171cb0ef41Sopenharmony_ci if (isArrayBufferView(buffer) && !isUint8Array(buffer)) { 1181cb0ef41Sopenharmony_ci buffer = Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength); 1191cb0ef41Sopenharmony_ci } else if (isAnyArrayBuffer(buffer)) { 1201cb0ef41Sopenharmony_ci buffer = Buffer.from(buffer); 1211cb0ef41Sopenharmony_ci } 1221cb0ef41Sopenharmony_ci engine.buffers = null; 1231cb0ef41Sopenharmony_ci engine.nread = 0; 1241cb0ef41Sopenharmony_ci engine.cb = callback; 1251cb0ef41Sopenharmony_ci engine.on('data', zlibBufferOnData); 1261cb0ef41Sopenharmony_ci engine.on('error', zlibBufferOnError); 1271cb0ef41Sopenharmony_ci engine.on('end', zlibBufferOnEnd); 1281cb0ef41Sopenharmony_ci engine.end(buffer); 1291cb0ef41Sopenharmony_ci} 1301cb0ef41Sopenharmony_ci 1311cb0ef41Sopenharmony_cifunction zlibBufferOnData(chunk) { 1321cb0ef41Sopenharmony_ci if (!this.buffers) 1331cb0ef41Sopenharmony_ci this.buffers = [chunk]; 1341cb0ef41Sopenharmony_ci else 1351cb0ef41Sopenharmony_ci ArrayPrototypePush(this.buffers, chunk); 1361cb0ef41Sopenharmony_ci this.nread += chunk.length; 1371cb0ef41Sopenharmony_ci if (this.nread > this._maxOutputLength) { 1381cb0ef41Sopenharmony_ci this.close(); 1391cb0ef41Sopenharmony_ci this.removeAllListeners('end'); 1401cb0ef41Sopenharmony_ci this.cb(new ERR_BUFFER_TOO_LARGE(this._maxOutputLength)); 1411cb0ef41Sopenharmony_ci } 1421cb0ef41Sopenharmony_ci} 1431cb0ef41Sopenharmony_ci 1441cb0ef41Sopenharmony_cifunction zlibBufferOnError(err) { 1451cb0ef41Sopenharmony_ci this.removeAllListeners('end'); 1461cb0ef41Sopenharmony_ci this.cb(err); 1471cb0ef41Sopenharmony_ci} 1481cb0ef41Sopenharmony_ci 1491cb0ef41Sopenharmony_cifunction zlibBufferOnEnd() { 1501cb0ef41Sopenharmony_ci let buf; 1511cb0ef41Sopenharmony_ci if (this.nread === 0) { 1521cb0ef41Sopenharmony_ci buf = Buffer.alloc(0); 1531cb0ef41Sopenharmony_ci } else { 1541cb0ef41Sopenharmony_ci const bufs = this.buffers; 1551cb0ef41Sopenharmony_ci buf = (bufs.length === 1 ? bufs[0] : Buffer.concat(bufs, this.nread)); 1561cb0ef41Sopenharmony_ci } 1571cb0ef41Sopenharmony_ci this.close(); 1581cb0ef41Sopenharmony_ci if (this._info) 1591cb0ef41Sopenharmony_ci this.cb(null, { buffer: buf, engine: this }); 1601cb0ef41Sopenharmony_ci else 1611cb0ef41Sopenharmony_ci this.cb(null, buf); 1621cb0ef41Sopenharmony_ci} 1631cb0ef41Sopenharmony_ci 1641cb0ef41Sopenharmony_cifunction zlibBufferSync(engine, buffer) { 1651cb0ef41Sopenharmony_ci if (typeof buffer === 'string') { 1661cb0ef41Sopenharmony_ci buffer = Buffer.from(buffer); 1671cb0ef41Sopenharmony_ci } else if (!isArrayBufferView(buffer)) { 1681cb0ef41Sopenharmony_ci if (isAnyArrayBuffer(buffer)) { 1691cb0ef41Sopenharmony_ci buffer = Buffer.from(buffer); 1701cb0ef41Sopenharmony_ci } else { 1711cb0ef41Sopenharmony_ci throw new ERR_INVALID_ARG_TYPE( 1721cb0ef41Sopenharmony_ci 'buffer', 1731cb0ef41Sopenharmony_ci ['string', 'Buffer', 'TypedArray', 'DataView', 'ArrayBuffer'], 1741cb0ef41Sopenharmony_ci buffer, 1751cb0ef41Sopenharmony_ci ); 1761cb0ef41Sopenharmony_ci } 1771cb0ef41Sopenharmony_ci } 1781cb0ef41Sopenharmony_ci buffer = processChunkSync(engine, buffer, engine._finishFlushFlag); 1791cb0ef41Sopenharmony_ci if (engine._info) 1801cb0ef41Sopenharmony_ci return { buffer, engine }; 1811cb0ef41Sopenharmony_ci return buffer; 1821cb0ef41Sopenharmony_ci} 1831cb0ef41Sopenharmony_ci 1841cb0ef41Sopenharmony_cifunction zlibOnError(message, errno, code) { 1851cb0ef41Sopenharmony_ci const self = this[owner_symbol]; 1861cb0ef41Sopenharmony_ci // There is no way to cleanly recover. 1871cb0ef41Sopenharmony_ci // Continuing only obscures problems. 1881cb0ef41Sopenharmony_ci 1891cb0ef41Sopenharmony_ci const error = genericNodeError(message, { errno, code }); 1901cb0ef41Sopenharmony_ci error.errno = errno; 1911cb0ef41Sopenharmony_ci error.code = code; 1921cb0ef41Sopenharmony_ci self.destroy(error); 1931cb0ef41Sopenharmony_ci self[kError] = error; 1941cb0ef41Sopenharmony_ci} 1951cb0ef41Sopenharmony_ci 1961cb0ef41Sopenharmony_ci// 1. Returns false for undefined and NaN 1971cb0ef41Sopenharmony_ci// 2. Returns true for finite numbers 1981cb0ef41Sopenharmony_ci// 3. Throws ERR_INVALID_ARG_TYPE for non-numbers 1991cb0ef41Sopenharmony_ci// 4. Throws ERR_OUT_OF_RANGE for infinite numbers 2001cb0ef41Sopenharmony_ciconst checkFiniteNumber = hideStackFrames((number, name) => { 2011cb0ef41Sopenharmony_ci // Common case 2021cb0ef41Sopenharmony_ci if (number === undefined) { 2031cb0ef41Sopenharmony_ci return false; 2041cb0ef41Sopenharmony_ci } 2051cb0ef41Sopenharmony_ci 2061cb0ef41Sopenharmony_ci if (NumberIsFinite(number)) { 2071cb0ef41Sopenharmony_ci return true; // Is a valid number 2081cb0ef41Sopenharmony_ci } 2091cb0ef41Sopenharmony_ci 2101cb0ef41Sopenharmony_ci if (NumberIsNaN(number)) { 2111cb0ef41Sopenharmony_ci return false; 2121cb0ef41Sopenharmony_ci } 2131cb0ef41Sopenharmony_ci 2141cb0ef41Sopenharmony_ci validateNumber(number, name); 2151cb0ef41Sopenharmony_ci 2161cb0ef41Sopenharmony_ci // Infinite numbers 2171cb0ef41Sopenharmony_ci throw new ERR_OUT_OF_RANGE(name, 'a finite number', number); 2181cb0ef41Sopenharmony_ci}); 2191cb0ef41Sopenharmony_ci 2201cb0ef41Sopenharmony_ci// 1. Returns def for number when it's undefined or NaN 2211cb0ef41Sopenharmony_ci// 2. Returns number for finite numbers >= lower and <= upper 2221cb0ef41Sopenharmony_ci// 3. Throws ERR_INVALID_ARG_TYPE for non-numbers 2231cb0ef41Sopenharmony_ci// 4. Throws ERR_OUT_OF_RANGE for infinite numbers or numbers > upper or < lower 2241cb0ef41Sopenharmony_ciconst checkRangesOrGetDefault = hideStackFrames( 2251cb0ef41Sopenharmony_ci (number, name, lower, upper, def) => { 2261cb0ef41Sopenharmony_ci if (!checkFiniteNumber(number, name)) { 2271cb0ef41Sopenharmony_ci return def; 2281cb0ef41Sopenharmony_ci } 2291cb0ef41Sopenharmony_ci if (number < lower || number > upper) { 2301cb0ef41Sopenharmony_ci throw new ERR_OUT_OF_RANGE(name, 2311cb0ef41Sopenharmony_ci `>= ${lower} and <= ${upper}`, number); 2321cb0ef41Sopenharmony_ci } 2331cb0ef41Sopenharmony_ci return number; 2341cb0ef41Sopenharmony_ci }, 2351cb0ef41Sopenharmony_ci); 2361cb0ef41Sopenharmony_ci 2371cb0ef41Sopenharmony_ciconst FLUSH_BOUND = [ 2381cb0ef41Sopenharmony_ci [ Z_NO_FLUSH, Z_BLOCK ], 2391cb0ef41Sopenharmony_ci [ BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_EMIT_METADATA ], 2401cb0ef41Sopenharmony_ci]; 2411cb0ef41Sopenharmony_ciconst FLUSH_BOUND_IDX_NORMAL = 0; 2421cb0ef41Sopenharmony_ciconst FLUSH_BOUND_IDX_BROTLI = 1; 2431cb0ef41Sopenharmony_ci 2441cb0ef41Sopenharmony_ci// The base class for all Zlib-style streams. 2451cb0ef41Sopenharmony_cifunction ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) { 2461cb0ef41Sopenharmony_ci let chunkSize = Z_DEFAULT_CHUNK; 2471cb0ef41Sopenharmony_ci let maxOutputLength = kMaxLength; 2481cb0ef41Sopenharmony_ci // The ZlibBase class is not exported to user land, the mode should only be 2491cb0ef41Sopenharmony_ci // passed in by us. 2501cb0ef41Sopenharmony_ci assert(typeof mode === 'number'); 2511cb0ef41Sopenharmony_ci assert(mode >= DEFLATE && mode <= BROTLI_ENCODE); 2521cb0ef41Sopenharmony_ci 2531cb0ef41Sopenharmony_ci let flushBoundIdx; 2541cb0ef41Sopenharmony_ci if (mode !== BROTLI_ENCODE && mode !== BROTLI_DECODE) { 2551cb0ef41Sopenharmony_ci flushBoundIdx = FLUSH_BOUND_IDX_NORMAL; 2561cb0ef41Sopenharmony_ci } else { 2571cb0ef41Sopenharmony_ci flushBoundIdx = FLUSH_BOUND_IDX_BROTLI; 2581cb0ef41Sopenharmony_ci } 2591cb0ef41Sopenharmony_ci 2601cb0ef41Sopenharmony_ci if (opts) { 2611cb0ef41Sopenharmony_ci chunkSize = opts.chunkSize; 2621cb0ef41Sopenharmony_ci if (!checkFiniteNumber(chunkSize, 'options.chunkSize')) { 2631cb0ef41Sopenharmony_ci chunkSize = Z_DEFAULT_CHUNK; 2641cb0ef41Sopenharmony_ci } else if (chunkSize < Z_MIN_CHUNK) { 2651cb0ef41Sopenharmony_ci throw new ERR_OUT_OF_RANGE('options.chunkSize', 2661cb0ef41Sopenharmony_ci `>= ${Z_MIN_CHUNK}`, chunkSize); 2671cb0ef41Sopenharmony_ci } 2681cb0ef41Sopenharmony_ci 2691cb0ef41Sopenharmony_ci flush = checkRangesOrGetDefault( 2701cb0ef41Sopenharmony_ci opts.flush, 'options.flush', 2711cb0ef41Sopenharmony_ci FLUSH_BOUND[flushBoundIdx][0], FLUSH_BOUND[flushBoundIdx][1], flush); 2721cb0ef41Sopenharmony_ci 2731cb0ef41Sopenharmony_ci finishFlush = checkRangesOrGetDefault( 2741cb0ef41Sopenharmony_ci opts.finishFlush, 'options.finishFlush', 2751cb0ef41Sopenharmony_ci FLUSH_BOUND[flushBoundIdx][0], FLUSH_BOUND[flushBoundIdx][1], 2761cb0ef41Sopenharmony_ci finishFlush); 2771cb0ef41Sopenharmony_ci 2781cb0ef41Sopenharmony_ci maxOutputLength = checkRangesOrGetDefault( 2791cb0ef41Sopenharmony_ci opts.maxOutputLength, 'options.maxOutputLength', 2801cb0ef41Sopenharmony_ci 1, kMaxLength, kMaxLength); 2811cb0ef41Sopenharmony_ci 2821cb0ef41Sopenharmony_ci if (opts.encoding || opts.objectMode || opts.writableObjectMode) { 2831cb0ef41Sopenharmony_ci opts = { ...opts }; 2841cb0ef41Sopenharmony_ci opts.encoding = null; 2851cb0ef41Sopenharmony_ci opts.objectMode = false; 2861cb0ef41Sopenharmony_ci opts.writableObjectMode = false; 2871cb0ef41Sopenharmony_ci } 2881cb0ef41Sopenharmony_ci } 2891cb0ef41Sopenharmony_ci 2901cb0ef41Sopenharmony_ci ReflectApply(Transform, this, [{ autoDestroy: true, ...opts }]); 2911cb0ef41Sopenharmony_ci this[kError] = null; 2921cb0ef41Sopenharmony_ci this.bytesWritten = 0; 2931cb0ef41Sopenharmony_ci this._handle = handle; 2941cb0ef41Sopenharmony_ci handle[owner_symbol] = this; 2951cb0ef41Sopenharmony_ci // Used by processCallback() and zlibOnError() 2961cb0ef41Sopenharmony_ci handle.onerror = zlibOnError; 2971cb0ef41Sopenharmony_ci this._outBuffer = Buffer.allocUnsafe(chunkSize); 2981cb0ef41Sopenharmony_ci this._outOffset = 0; 2991cb0ef41Sopenharmony_ci 3001cb0ef41Sopenharmony_ci this._chunkSize = chunkSize; 3011cb0ef41Sopenharmony_ci this._defaultFlushFlag = flush; 3021cb0ef41Sopenharmony_ci this._finishFlushFlag = finishFlush; 3031cb0ef41Sopenharmony_ci this._defaultFullFlushFlag = fullFlush; 3041cb0ef41Sopenharmony_ci this._info = opts && opts.info; 3051cb0ef41Sopenharmony_ci this._maxOutputLength = maxOutputLength; 3061cb0ef41Sopenharmony_ci} 3071cb0ef41Sopenharmony_ciObjectSetPrototypeOf(ZlibBase.prototype, Transform.prototype); 3081cb0ef41Sopenharmony_ciObjectSetPrototypeOf(ZlibBase, Transform); 3091cb0ef41Sopenharmony_ci 3101cb0ef41Sopenharmony_ciObjectDefineProperty(ZlibBase.prototype, '_closed', { 3111cb0ef41Sopenharmony_ci __proto__: null, 3121cb0ef41Sopenharmony_ci configurable: true, 3131cb0ef41Sopenharmony_ci enumerable: true, 3141cb0ef41Sopenharmony_ci get() { 3151cb0ef41Sopenharmony_ci return !this._handle; 3161cb0ef41Sopenharmony_ci }, 3171cb0ef41Sopenharmony_ci}); 3181cb0ef41Sopenharmony_ci 3191cb0ef41Sopenharmony_ci// `bytesRead` made sense as a name when looking from the zlib engine's 3201cb0ef41Sopenharmony_ci// perspective, but it is inconsistent with all other streams exposed by Node.js 3211cb0ef41Sopenharmony_ci// that have this concept, where it stands for the number of bytes read 3221cb0ef41Sopenharmony_ci// *from* the stream (that is, net.Socket/tls.Socket & file system streams). 3231cb0ef41Sopenharmony_ciObjectDefineProperty(ZlibBase.prototype, 'bytesRead', { 3241cb0ef41Sopenharmony_ci __proto__: null, 3251cb0ef41Sopenharmony_ci configurable: true, 3261cb0ef41Sopenharmony_ci enumerable: true, 3271cb0ef41Sopenharmony_ci get: deprecate(function() { 3281cb0ef41Sopenharmony_ci return this.bytesWritten; 3291cb0ef41Sopenharmony_ci }, 'zlib.bytesRead is deprecated and will change its meaning in the ' + 3301cb0ef41Sopenharmony_ci 'future. Use zlib.bytesWritten instead.', 'DEP0108'), 3311cb0ef41Sopenharmony_ci set: deprecate(function(value) { 3321cb0ef41Sopenharmony_ci this.bytesWritten = value; 3331cb0ef41Sopenharmony_ci }, 'Setting zlib.bytesRead is deprecated. ' + 3341cb0ef41Sopenharmony_ci 'This feature will be removed in the future.', 'DEP0108'), 3351cb0ef41Sopenharmony_ci}); 3361cb0ef41Sopenharmony_ci 3371cb0ef41Sopenharmony_ciZlibBase.prototype.reset = function() { 3381cb0ef41Sopenharmony_ci if (!this._handle) 3391cb0ef41Sopenharmony_ci assert(false, 'zlib binding closed'); 3401cb0ef41Sopenharmony_ci return this._handle.reset(); 3411cb0ef41Sopenharmony_ci}; 3421cb0ef41Sopenharmony_ci 3431cb0ef41Sopenharmony_ci// This is the _flush function called by the transform class, 3441cb0ef41Sopenharmony_ci// internally, when the last chunk has been written. 3451cb0ef41Sopenharmony_ciZlibBase.prototype._flush = function(callback) { 3461cb0ef41Sopenharmony_ci this._transform(Buffer.alloc(0), '', callback); 3471cb0ef41Sopenharmony_ci}; 3481cb0ef41Sopenharmony_ci 3491cb0ef41Sopenharmony_ci// Force Transform compat behavior. 3501cb0ef41Sopenharmony_ciZlibBase.prototype._final = function(callback) { 3511cb0ef41Sopenharmony_ci callback(); 3521cb0ef41Sopenharmony_ci}; 3531cb0ef41Sopenharmony_ci 3541cb0ef41Sopenharmony_ci// If a flush is scheduled while another flush is still pending, a way to figure 3551cb0ef41Sopenharmony_ci// out which one is the "stronger" flush is needed. 3561cb0ef41Sopenharmony_ci// This is currently only used to figure out which flush flag to use for the 3571cb0ef41Sopenharmony_ci// last chunk. 3581cb0ef41Sopenharmony_ci// Roughly, the following holds: 3591cb0ef41Sopenharmony_ci// Z_NO_FLUSH (< Z_TREES) < Z_BLOCK < Z_PARTIAL_FLUSH < 3601cb0ef41Sopenharmony_ci// Z_SYNC_FLUSH < Z_FULL_FLUSH < Z_FINISH 3611cb0ef41Sopenharmony_ciconst flushiness = []; 3621cb0ef41Sopenharmony_cilet i = 0; 3631cb0ef41Sopenharmony_ciconst kFlushFlagList = [Z_NO_FLUSH, Z_BLOCK, Z_PARTIAL_FLUSH, 3641cb0ef41Sopenharmony_ci Z_SYNC_FLUSH, Z_FULL_FLUSH, Z_FINISH]; 3651cb0ef41Sopenharmony_cifor (const flushFlag of kFlushFlagList) { 3661cb0ef41Sopenharmony_ci flushiness[flushFlag] = i++; 3671cb0ef41Sopenharmony_ci} 3681cb0ef41Sopenharmony_ci 3691cb0ef41Sopenharmony_cifunction maxFlush(a, b) { 3701cb0ef41Sopenharmony_ci return flushiness[a] > flushiness[b] ? a : b; 3711cb0ef41Sopenharmony_ci} 3721cb0ef41Sopenharmony_ci 3731cb0ef41Sopenharmony_ci// Set up a list of 'special' buffers that can be written using .write() 3741cb0ef41Sopenharmony_ci// from the .flush() code as a way of introducing flushing operations into the 3751cb0ef41Sopenharmony_ci// write sequence. 3761cb0ef41Sopenharmony_ciconst kFlushBuffers = []; 3771cb0ef41Sopenharmony_ci{ 3781cb0ef41Sopenharmony_ci const dummyArrayBuffer = new ArrayBuffer(); 3791cb0ef41Sopenharmony_ci for (const flushFlag of kFlushFlagList) { 3801cb0ef41Sopenharmony_ci kFlushBuffers[flushFlag] = Buffer.from(dummyArrayBuffer); 3811cb0ef41Sopenharmony_ci kFlushBuffers[flushFlag][kFlushFlag] = flushFlag; 3821cb0ef41Sopenharmony_ci } 3831cb0ef41Sopenharmony_ci} 3841cb0ef41Sopenharmony_ci 3851cb0ef41Sopenharmony_ciZlibBase.prototype.flush = function(kind, callback) { 3861cb0ef41Sopenharmony_ci if (typeof kind === 'function' || (kind === undefined && !callback)) { 3871cb0ef41Sopenharmony_ci callback = kind; 3881cb0ef41Sopenharmony_ci kind = this._defaultFullFlushFlag; 3891cb0ef41Sopenharmony_ci } 3901cb0ef41Sopenharmony_ci 3911cb0ef41Sopenharmony_ci if (this.writableFinished) { 3921cb0ef41Sopenharmony_ci if (callback) 3931cb0ef41Sopenharmony_ci process.nextTick(callback); 3941cb0ef41Sopenharmony_ci } else if (this.writableEnded) { 3951cb0ef41Sopenharmony_ci if (callback) 3961cb0ef41Sopenharmony_ci this.once('end', callback); 3971cb0ef41Sopenharmony_ci } else { 3981cb0ef41Sopenharmony_ci this.write(kFlushBuffers[kind], '', callback); 3991cb0ef41Sopenharmony_ci } 4001cb0ef41Sopenharmony_ci}; 4011cb0ef41Sopenharmony_ci 4021cb0ef41Sopenharmony_ciZlibBase.prototype.close = function(callback) { 4031cb0ef41Sopenharmony_ci if (callback) finished(this, callback); 4041cb0ef41Sopenharmony_ci this.destroy(); 4051cb0ef41Sopenharmony_ci}; 4061cb0ef41Sopenharmony_ci 4071cb0ef41Sopenharmony_ciZlibBase.prototype._destroy = function(err, callback) { 4081cb0ef41Sopenharmony_ci _close(this); 4091cb0ef41Sopenharmony_ci callback(err); 4101cb0ef41Sopenharmony_ci}; 4111cb0ef41Sopenharmony_ci 4121cb0ef41Sopenharmony_ciZlibBase.prototype._transform = function(chunk, encoding, cb) { 4131cb0ef41Sopenharmony_ci let flushFlag = this._defaultFlushFlag; 4141cb0ef41Sopenharmony_ci // We use a 'fake' zero-length chunk to carry information about flushes from 4151cb0ef41Sopenharmony_ci // the public API to the actual stream implementation. 4161cb0ef41Sopenharmony_ci if (typeof chunk[kFlushFlag] === 'number') { 4171cb0ef41Sopenharmony_ci flushFlag = chunk[kFlushFlag]; 4181cb0ef41Sopenharmony_ci } 4191cb0ef41Sopenharmony_ci 4201cb0ef41Sopenharmony_ci // For the last chunk, also apply `_finishFlushFlag`. 4211cb0ef41Sopenharmony_ci if (this.writableEnded && this.writableLength === chunk.byteLength) { 4221cb0ef41Sopenharmony_ci flushFlag = maxFlush(flushFlag, this._finishFlushFlag); 4231cb0ef41Sopenharmony_ci } 4241cb0ef41Sopenharmony_ci processChunk(this, chunk, flushFlag, cb); 4251cb0ef41Sopenharmony_ci}; 4261cb0ef41Sopenharmony_ci 4271cb0ef41Sopenharmony_ciZlibBase.prototype._processChunk = function(chunk, flushFlag, cb) { 4281cb0ef41Sopenharmony_ci // _processChunk() is left for backwards compatibility 4291cb0ef41Sopenharmony_ci if (typeof cb === 'function') 4301cb0ef41Sopenharmony_ci processChunk(this, chunk, flushFlag, cb); 4311cb0ef41Sopenharmony_ci else 4321cb0ef41Sopenharmony_ci return processChunkSync(this, chunk, flushFlag); 4331cb0ef41Sopenharmony_ci}; 4341cb0ef41Sopenharmony_ci 4351cb0ef41Sopenharmony_cifunction processChunkSync(self, chunk, flushFlag) { 4361cb0ef41Sopenharmony_ci let availInBefore = chunk.byteLength; 4371cb0ef41Sopenharmony_ci let availOutBefore = self._chunkSize - self._outOffset; 4381cb0ef41Sopenharmony_ci let inOff = 0; 4391cb0ef41Sopenharmony_ci let availOutAfter; 4401cb0ef41Sopenharmony_ci let availInAfter; 4411cb0ef41Sopenharmony_ci 4421cb0ef41Sopenharmony_ci let buffers = null; 4431cb0ef41Sopenharmony_ci let nread = 0; 4441cb0ef41Sopenharmony_ci let inputRead = 0; 4451cb0ef41Sopenharmony_ci const state = self._writeState; 4461cb0ef41Sopenharmony_ci const handle = self._handle; 4471cb0ef41Sopenharmony_ci let buffer = self._outBuffer; 4481cb0ef41Sopenharmony_ci let offset = self._outOffset; 4491cb0ef41Sopenharmony_ci const chunkSize = self._chunkSize; 4501cb0ef41Sopenharmony_ci 4511cb0ef41Sopenharmony_ci let error; 4521cb0ef41Sopenharmony_ci self.on('error', function onError(er) { 4531cb0ef41Sopenharmony_ci error = er; 4541cb0ef41Sopenharmony_ci }); 4551cb0ef41Sopenharmony_ci 4561cb0ef41Sopenharmony_ci while (true) { 4571cb0ef41Sopenharmony_ci handle.writeSync(flushFlag, 4581cb0ef41Sopenharmony_ci chunk, // in 4591cb0ef41Sopenharmony_ci inOff, // in_off 4601cb0ef41Sopenharmony_ci availInBefore, // in_len 4611cb0ef41Sopenharmony_ci buffer, // out 4621cb0ef41Sopenharmony_ci offset, // out_off 4631cb0ef41Sopenharmony_ci availOutBefore); // out_len 4641cb0ef41Sopenharmony_ci if (error) 4651cb0ef41Sopenharmony_ci throw error; 4661cb0ef41Sopenharmony_ci else if (self[kError]) 4671cb0ef41Sopenharmony_ci throw self[kError]; 4681cb0ef41Sopenharmony_ci 4691cb0ef41Sopenharmony_ci availOutAfter = state[0]; 4701cb0ef41Sopenharmony_ci availInAfter = state[1]; 4711cb0ef41Sopenharmony_ci 4721cb0ef41Sopenharmony_ci const inDelta = (availInBefore - availInAfter); 4731cb0ef41Sopenharmony_ci inputRead += inDelta; 4741cb0ef41Sopenharmony_ci 4751cb0ef41Sopenharmony_ci const have = availOutBefore - availOutAfter; 4761cb0ef41Sopenharmony_ci if (have > 0) { 4771cb0ef41Sopenharmony_ci const out = buffer.slice(offset, offset + have); 4781cb0ef41Sopenharmony_ci offset += have; 4791cb0ef41Sopenharmony_ci if (!buffers) 4801cb0ef41Sopenharmony_ci buffers = [out]; 4811cb0ef41Sopenharmony_ci else 4821cb0ef41Sopenharmony_ci ArrayPrototypePush(buffers, out); 4831cb0ef41Sopenharmony_ci nread += out.byteLength; 4841cb0ef41Sopenharmony_ci 4851cb0ef41Sopenharmony_ci if (nread > self._maxOutputLength) { 4861cb0ef41Sopenharmony_ci _close(self); 4871cb0ef41Sopenharmony_ci throw new ERR_BUFFER_TOO_LARGE(self._maxOutputLength); 4881cb0ef41Sopenharmony_ci } 4891cb0ef41Sopenharmony_ci 4901cb0ef41Sopenharmony_ci } else { 4911cb0ef41Sopenharmony_ci assert(have === 0, 'have should not go down'); 4921cb0ef41Sopenharmony_ci } 4931cb0ef41Sopenharmony_ci 4941cb0ef41Sopenharmony_ci // Exhausted the output buffer, or used all the input create a new one. 4951cb0ef41Sopenharmony_ci if (availOutAfter === 0 || offset >= chunkSize) { 4961cb0ef41Sopenharmony_ci availOutBefore = chunkSize; 4971cb0ef41Sopenharmony_ci offset = 0; 4981cb0ef41Sopenharmony_ci buffer = Buffer.allocUnsafe(chunkSize); 4991cb0ef41Sopenharmony_ci } 5001cb0ef41Sopenharmony_ci 5011cb0ef41Sopenharmony_ci if (availOutAfter === 0) { 5021cb0ef41Sopenharmony_ci // Not actually done. Need to reprocess. 5031cb0ef41Sopenharmony_ci // Also, update the availInBefore to the availInAfter value, 5041cb0ef41Sopenharmony_ci // so that if we have to hit it a third (fourth, etc.) time, 5051cb0ef41Sopenharmony_ci // it'll have the correct byte counts. 5061cb0ef41Sopenharmony_ci inOff += inDelta; 5071cb0ef41Sopenharmony_ci availInBefore = availInAfter; 5081cb0ef41Sopenharmony_ci } else { 5091cb0ef41Sopenharmony_ci break; 5101cb0ef41Sopenharmony_ci } 5111cb0ef41Sopenharmony_ci } 5121cb0ef41Sopenharmony_ci 5131cb0ef41Sopenharmony_ci self.bytesWritten = inputRead; 5141cb0ef41Sopenharmony_ci _close(self); 5151cb0ef41Sopenharmony_ci 5161cb0ef41Sopenharmony_ci if (nread === 0) 5171cb0ef41Sopenharmony_ci return Buffer.alloc(0); 5181cb0ef41Sopenharmony_ci 5191cb0ef41Sopenharmony_ci return (buffers.length === 1 ? buffers[0] : Buffer.concat(buffers, nread)); 5201cb0ef41Sopenharmony_ci} 5211cb0ef41Sopenharmony_ci 5221cb0ef41Sopenharmony_cifunction processChunk(self, chunk, flushFlag, cb) { 5231cb0ef41Sopenharmony_ci const handle = self._handle; 5241cb0ef41Sopenharmony_ci if (!handle) return process.nextTick(cb); 5251cb0ef41Sopenharmony_ci 5261cb0ef41Sopenharmony_ci handle.buffer = chunk; 5271cb0ef41Sopenharmony_ci handle.cb = cb; 5281cb0ef41Sopenharmony_ci handle.availOutBefore = self._chunkSize - self._outOffset; 5291cb0ef41Sopenharmony_ci handle.availInBefore = chunk.byteLength; 5301cb0ef41Sopenharmony_ci handle.inOff = 0; 5311cb0ef41Sopenharmony_ci handle.flushFlag = flushFlag; 5321cb0ef41Sopenharmony_ci 5331cb0ef41Sopenharmony_ci handle.write(flushFlag, 5341cb0ef41Sopenharmony_ci chunk, // in 5351cb0ef41Sopenharmony_ci 0, // in_off 5361cb0ef41Sopenharmony_ci handle.availInBefore, // in_len 5371cb0ef41Sopenharmony_ci self._outBuffer, // out 5381cb0ef41Sopenharmony_ci self._outOffset, // out_off 5391cb0ef41Sopenharmony_ci handle.availOutBefore); // out_len 5401cb0ef41Sopenharmony_ci} 5411cb0ef41Sopenharmony_ci 5421cb0ef41Sopenharmony_cifunction processCallback() { 5431cb0ef41Sopenharmony_ci // This callback's context (`this`) is the `_handle` (ZCtx) object. It is 5441cb0ef41Sopenharmony_ci // important to null out the values once they are no longer needed since 5451cb0ef41Sopenharmony_ci // `_handle` can stay in memory long after the buffer is needed. 5461cb0ef41Sopenharmony_ci const handle = this; 5471cb0ef41Sopenharmony_ci const self = this[owner_symbol]; 5481cb0ef41Sopenharmony_ci const state = self._writeState; 5491cb0ef41Sopenharmony_ci 5501cb0ef41Sopenharmony_ci if (self.destroyed) { 5511cb0ef41Sopenharmony_ci this.buffer = null; 5521cb0ef41Sopenharmony_ci this.cb(); 5531cb0ef41Sopenharmony_ci return; 5541cb0ef41Sopenharmony_ci } 5551cb0ef41Sopenharmony_ci 5561cb0ef41Sopenharmony_ci const availOutAfter = state[0]; 5571cb0ef41Sopenharmony_ci const availInAfter = state[1]; 5581cb0ef41Sopenharmony_ci 5591cb0ef41Sopenharmony_ci const inDelta = handle.availInBefore - availInAfter; 5601cb0ef41Sopenharmony_ci self.bytesWritten += inDelta; 5611cb0ef41Sopenharmony_ci 5621cb0ef41Sopenharmony_ci const have = handle.availOutBefore - availOutAfter; 5631cb0ef41Sopenharmony_ci let streamBufferIsFull = false; 5641cb0ef41Sopenharmony_ci if (have > 0) { 5651cb0ef41Sopenharmony_ci const out = self._outBuffer.slice(self._outOffset, self._outOffset + have); 5661cb0ef41Sopenharmony_ci self._outOffset += have; 5671cb0ef41Sopenharmony_ci streamBufferIsFull = !self.push(out); 5681cb0ef41Sopenharmony_ci } else { 5691cb0ef41Sopenharmony_ci assert(have === 0, 'have should not go down'); 5701cb0ef41Sopenharmony_ci } 5711cb0ef41Sopenharmony_ci 5721cb0ef41Sopenharmony_ci if (self.destroyed) { 5731cb0ef41Sopenharmony_ci this.cb(); 5741cb0ef41Sopenharmony_ci return; 5751cb0ef41Sopenharmony_ci } 5761cb0ef41Sopenharmony_ci 5771cb0ef41Sopenharmony_ci // Exhausted the output buffer, or used all the input create a new one. 5781cb0ef41Sopenharmony_ci if (availOutAfter === 0 || self._outOffset >= self._chunkSize) { 5791cb0ef41Sopenharmony_ci handle.availOutBefore = self._chunkSize; 5801cb0ef41Sopenharmony_ci self._outOffset = 0; 5811cb0ef41Sopenharmony_ci self._outBuffer = Buffer.allocUnsafe(self._chunkSize); 5821cb0ef41Sopenharmony_ci } 5831cb0ef41Sopenharmony_ci 5841cb0ef41Sopenharmony_ci if (availOutAfter === 0) { 5851cb0ef41Sopenharmony_ci // Not actually done. Need to reprocess. 5861cb0ef41Sopenharmony_ci // Also, update the availInBefore to the availInAfter value, 5871cb0ef41Sopenharmony_ci // so that if we have to hit it a third (fourth, etc.) time, 5881cb0ef41Sopenharmony_ci // it'll have the correct byte counts. 5891cb0ef41Sopenharmony_ci handle.inOff += inDelta; 5901cb0ef41Sopenharmony_ci handle.availInBefore = availInAfter; 5911cb0ef41Sopenharmony_ci 5921cb0ef41Sopenharmony_ci 5931cb0ef41Sopenharmony_ci if (!streamBufferIsFull) { 5941cb0ef41Sopenharmony_ci this.write(handle.flushFlag, 5951cb0ef41Sopenharmony_ci this.buffer, // in 5961cb0ef41Sopenharmony_ci handle.inOff, // in_off 5971cb0ef41Sopenharmony_ci handle.availInBefore, // in_len 5981cb0ef41Sopenharmony_ci self._outBuffer, // out 5991cb0ef41Sopenharmony_ci self._outOffset, // out_off 6001cb0ef41Sopenharmony_ci self._chunkSize); // out_len 6011cb0ef41Sopenharmony_ci } else { 6021cb0ef41Sopenharmony_ci const oldRead = self._read; 6031cb0ef41Sopenharmony_ci self._read = (n) => { 6041cb0ef41Sopenharmony_ci self._read = oldRead; 6051cb0ef41Sopenharmony_ci this.write(handle.flushFlag, 6061cb0ef41Sopenharmony_ci this.buffer, // in 6071cb0ef41Sopenharmony_ci handle.inOff, // in_off 6081cb0ef41Sopenharmony_ci handle.availInBefore, // in_len 6091cb0ef41Sopenharmony_ci self._outBuffer, // out 6101cb0ef41Sopenharmony_ci self._outOffset, // out_off 6111cb0ef41Sopenharmony_ci self._chunkSize); // out_len 6121cb0ef41Sopenharmony_ci self._read(n); 6131cb0ef41Sopenharmony_ci }; 6141cb0ef41Sopenharmony_ci } 6151cb0ef41Sopenharmony_ci return; 6161cb0ef41Sopenharmony_ci } 6171cb0ef41Sopenharmony_ci 6181cb0ef41Sopenharmony_ci if (availInAfter > 0) { 6191cb0ef41Sopenharmony_ci // If we have more input that should be written, but we also have output 6201cb0ef41Sopenharmony_ci // space available, that means that the compression library was not 6211cb0ef41Sopenharmony_ci // interested in receiving more data, and in particular that the input 6221cb0ef41Sopenharmony_ci // stream has ended early. 6231cb0ef41Sopenharmony_ci // This applies to streams where we don't check data past the end of 6241cb0ef41Sopenharmony_ci // what was consumed; that is, everything except Gunzip/Unzip. 6251cb0ef41Sopenharmony_ci self.push(null); 6261cb0ef41Sopenharmony_ci } 6271cb0ef41Sopenharmony_ci 6281cb0ef41Sopenharmony_ci // Finished with the chunk. 6291cb0ef41Sopenharmony_ci this.buffer = null; 6301cb0ef41Sopenharmony_ci this.cb(); 6311cb0ef41Sopenharmony_ci} 6321cb0ef41Sopenharmony_ci 6331cb0ef41Sopenharmony_cifunction _close(engine) { 6341cb0ef41Sopenharmony_ci // Caller may invoke .close after a zlib error (which will null _handle). 6351cb0ef41Sopenharmony_ci if (!engine._handle) 6361cb0ef41Sopenharmony_ci return; 6371cb0ef41Sopenharmony_ci 6381cb0ef41Sopenharmony_ci engine._handle.close(); 6391cb0ef41Sopenharmony_ci engine._handle = null; 6401cb0ef41Sopenharmony_ci} 6411cb0ef41Sopenharmony_ci 6421cb0ef41Sopenharmony_ciconst zlibDefaultOpts = { 6431cb0ef41Sopenharmony_ci flush: Z_NO_FLUSH, 6441cb0ef41Sopenharmony_ci finishFlush: Z_FINISH, 6451cb0ef41Sopenharmony_ci fullFlush: Z_FULL_FLUSH, 6461cb0ef41Sopenharmony_ci}; 6471cb0ef41Sopenharmony_ci// Base class for all streams actually backed by zlib and using zlib-specific 6481cb0ef41Sopenharmony_ci// parameters. 6491cb0ef41Sopenharmony_cifunction Zlib(opts, mode) { 6501cb0ef41Sopenharmony_ci let windowBits = Z_DEFAULT_WINDOWBITS; 6511cb0ef41Sopenharmony_ci let level = Z_DEFAULT_COMPRESSION; 6521cb0ef41Sopenharmony_ci let memLevel = Z_DEFAULT_MEMLEVEL; 6531cb0ef41Sopenharmony_ci let strategy = Z_DEFAULT_STRATEGY; 6541cb0ef41Sopenharmony_ci let dictionary; 6551cb0ef41Sopenharmony_ci 6561cb0ef41Sopenharmony_ci if (opts) { 6571cb0ef41Sopenharmony_ci // windowBits is special. On the compression side, 0 is an invalid value. 6581cb0ef41Sopenharmony_ci // But on the decompression side, a value of 0 for windowBits tells zlib 6591cb0ef41Sopenharmony_ci // to use the window size in the zlib header of the compressed stream. 6601cb0ef41Sopenharmony_ci if ((opts.windowBits == null || opts.windowBits === 0) && 6611cb0ef41Sopenharmony_ci (mode === INFLATE || 6621cb0ef41Sopenharmony_ci mode === GUNZIP || 6631cb0ef41Sopenharmony_ci mode === UNZIP)) { 6641cb0ef41Sopenharmony_ci windowBits = 0; 6651cb0ef41Sopenharmony_ci } else { 6661cb0ef41Sopenharmony_ci // `{ windowBits: 8 }` is valid for deflate but not gzip. 6671cb0ef41Sopenharmony_ci const min = Z_MIN_WINDOWBITS + (mode === GZIP ? 1 : 0); 6681cb0ef41Sopenharmony_ci windowBits = checkRangesOrGetDefault( 6691cb0ef41Sopenharmony_ci opts.windowBits, 'options.windowBits', 6701cb0ef41Sopenharmony_ci min, Z_MAX_WINDOWBITS, Z_DEFAULT_WINDOWBITS); 6711cb0ef41Sopenharmony_ci } 6721cb0ef41Sopenharmony_ci 6731cb0ef41Sopenharmony_ci level = checkRangesOrGetDefault( 6741cb0ef41Sopenharmony_ci opts.level, 'options.level', 6751cb0ef41Sopenharmony_ci Z_MIN_LEVEL, Z_MAX_LEVEL, Z_DEFAULT_COMPRESSION); 6761cb0ef41Sopenharmony_ci 6771cb0ef41Sopenharmony_ci memLevel = checkRangesOrGetDefault( 6781cb0ef41Sopenharmony_ci opts.memLevel, 'options.memLevel', 6791cb0ef41Sopenharmony_ci Z_MIN_MEMLEVEL, Z_MAX_MEMLEVEL, Z_DEFAULT_MEMLEVEL); 6801cb0ef41Sopenharmony_ci 6811cb0ef41Sopenharmony_ci strategy = checkRangesOrGetDefault( 6821cb0ef41Sopenharmony_ci opts.strategy, 'options.strategy', 6831cb0ef41Sopenharmony_ci Z_DEFAULT_STRATEGY, Z_FIXED, Z_DEFAULT_STRATEGY); 6841cb0ef41Sopenharmony_ci 6851cb0ef41Sopenharmony_ci dictionary = opts.dictionary; 6861cb0ef41Sopenharmony_ci if (dictionary !== undefined && !isArrayBufferView(dictionary)) { 6871cb0ef41Sopenharmony_ci if (isAnyArrayBuffer(dictionary)) { 6881cb0ef41Sopenharmony_ci dictionary = Buffer.from(dictionary); 6891cb0ef41Sopenharmony_ci } else { 6901cb0ef41Sopenharmony_ci throw new ERR_INVALID_ARG_TYPE( 6911cb0ef41Sopenharmony_ci 'options.dictionary', 6921cb0ef41Sopenharmony_ci ['Buffer', 'TypedArray', 'DataView', 'ArrayBuffer'], 6931cb0ef41Sopenharmony_ci dictionary, 6941cb0ef41Sopenharmony_ci ); 6951cb0ef41Sopenharmony_ci } 6961cb0ef41Sopenharmony_ci } 6971cb0ef41Sopenharmony_ci } 6981cb0ef41Sopenharmony_ci 6991cb0ef41Sopenharmony_ci const handle = new binding.Zlib(mode); 7001cb0ef41Sopenharmony_ci // Ideally, we could let ZlibBase() set up _writeState. I haven't been able 7011cb0ef41Sopenharmony_ci // to come up with a good solution that doesn't break our internal API, 7021cb0ef41Sopenharmony_ci // and with it all supported npm versions at the time of writing. 7031cb0ef41Sopenharmony_ci this._writeState = new Uint32Array(2); 7041cb0ef41Sopenharmony_ci handle.init(windowBits, 7051cb0ef41Sopenharmony_ci level, 7061cb0ef41Sopenharmony_ci memLevel, 7071cb0ef41Sopenharmony_ci strategy, 7081cb0ef41Sopenharmony_ci this._writeState, 7091cb0ef41Sopenharmony_ci processCallback, 7101cb0ef41Sopenharmony_ci dictionary); 7111cb0ef41Sopenharmony_ci 7121cb0ef41Sopenharmony_ci ReflectApply(ZlibBase, this, [opts, mode, handle, zlibDefaultOpts]); 7131cb0ef41Sopenharmony_ci 7141cb0ef41Sopenharmony_ci this._level = level; 7151cb0ef41Sopenharmony_ci this._strategy = strategy; 7161cb0ef41Sopenharmony_ci} 7171cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Zlib.prototype, ZlibBase.prototype); 7181cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Zlib, ZlibBase); 7191cb0ef41Sopenharmony_ci 7201cb0ef41Sopenharmony_ci// This callback is used by `.params()` to wait until a full flush happened 7211cb0ef41Sopenharmony_ci// before adjusting the parameters. In particular, the call to the native 7221cb0ef41Sopenharmony_ci// `params()` function should not happen while a write is currently in progress 7231cb0ef41Sopenharmony_ci// on the threadpool. 7241cb0ef41Sopenharmony_cifunction paramsAfterFlushCallback(level, strategy, callback) { 7251cb0ef41Sopenharmony_ci assert(this._handle, 'zlib binding closed'); 7261cb0ef41Sopenharmony_ci this._handle.params(level, strategy); 7271cb0ef41Sopenharmony_ci if (!this.destroyed) { 7281cb0ef41Sopenharmony_ci this._level = level; 7291cb0ef41Sopenharmony_ci this._strategy = strategy; 7301cb0ef41Sopenharmony_ci if (callback) callback(); 7311cb0ef41Sopenharmony_ci } 7321cb0ef41Sopenharmony_ci} 7331cb0ef41Sopenharmony_ci 7341cb0ef41Sopenharmony_ciZlib.prototype.params = function params(level, strategy, callback) { 7351cb0ef41Sopenharmony_ci checkRangesOrGetDefault(level, 'level', Z_MIN_LEVEL, Z_MAX_LEVEL); 7361cb0ef41Sopenharmony_ci checkRangesOrGetDefault(strategy, 'strategy', Z_DEFAULT_STRATEGY, Z_FIXED); 7371cb0ef41Sopenharmony_ci 7381cb0ef41Sopenharmony_ci if (this._level !== level || this._strategy !== strategy) { 7391cb0ef41Sopenharmony_ci this.flush(Z_SYNC_FLUSH, 7401cb0ef41Sopenharmony_ci FunctionPrototypeBind(paramsAfterFlushCallback, this, 7411cb0ef41Sopenharmony_ci level, strategy, callback)); 7421cb0ef41Sopenharmony_ci } else { 7431cb0ef41Sopenharmony_ci process.nextTick(callback); 7441cb0ef41Sopenharmony_ci } 7451cb0ef41Sopenharmony_ci}; 7461cb0ef41Sopenharmony_ci 7471cb0ef41Sopenharmony_ci// generic zlib 7481cb0ef41Sopenharmony_ci// minimal 2-byte header 7491cb0ef41Sopenharmony_cifunction Deflate(opts) { 7501cb0ef41Sopenharmony_ci if (!(this instanceof Deflate)) 7511cb0ef41Sopenharmony_ci return new Deflate(opts); 7521cb0ef41Sopenharmony_ci ReflectApply(Zlib, this, [opts, DEFLATE]); 7531cb0ef41Sopenharmony_ci} 7541cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Deflate.prototype, Zlib.prototype); 7551cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Deflate, Zlib); 7561cb0ef41Sopenharmony_ci 7571cb0ef41Sopenharmony_cifunction Inflate(opts) { 7581cb0ef41Sopenharmony_ci if (!(this instanceof Inflate)) 7591cb0ef41Sopenharmony_ci return new Inflate(opts); 7601cb0ef41Sopenharmony_ci ReflectApply(Zlib, this, [opts, INFLATE]); 7611cb0ef41Sopenharmony_ci} 7621cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Inflate.prototype, Zlib.prototype); 7631cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Inflate, Zlib); 7641cb0ef41Sopenharmony_ci 7651cb0ef41Sopenharmony_cifunction Gzip(opts) { 7661cb0ef41Sopenharmony_ci if (!(this instanceof Gzip)) 7671cb0ef41Sopenharmony_ci return new Gzip(opts); 7681cb0ef41Sopenharmony_ci ReflectApply(Zlib, this, [opts, GZIP]); 7691cb0ef41Sopenharmony_ci} 7701cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Gzip.prototype, Zlib.prototype); 7711cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Gzip, Zlib); 7721cb0ef41Sopenharmony_ci 7731cb0ef41Sopenharmony_cifunction Gunzip(opts) { 7741cb0ef41Sopenharmony_ci if (!(this instanceof Gunzip)) 7751cb0ef41Sopenharmony_ci return new Gunzip(opts); 7761cb0ef41Sopenharmony_ci ReflectApply(Zlib, this, [opts, GUNZIP]); 7771cb0ef41Sopenharmony_ci} 7781cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Gunzip.prototype, Zlib.prototype); 7791cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Gunzip, Zlib); 7801cb0ef41Sopenharmony_ci 7811cb0ef41Sopenharmony_cifunction DeflateRaw(opts) { 7821cb0ef41Sopenharmony_ci if (opts && opts.windowBits === 8) opts.windowBits = 9; 7831cb0ef41Sopenharmony_ci if (!(this instanceof DeflateRaw)) 7841cb0ef41Sopenharmony_ci return new DeflateRaw(opts); 7851cb0ef41Sopenharmony_ci ReflectApply(Zlib, this, [opts, DEFLATERAW]); 7861cb0ef41Sopenharmony_ci} 7871cb0ef41Sopenharmony_ciObjectSetPrototypeOf(DeflateRaw.prototype, Zlib.prototype); 7881cb0ef41Sopenharmony_ciObjectSetPrototypeOf(DeflateRaw, Zlib); 7891cb0ef41Sopenharmony_ci 7901cb0ef41Sopenharmony_cifunction InflateRaw(opts) { 7911cb0ef41Sopenharmony_ci if (!(this instanceof InflateRaw)) 7921cb0ef41Sopenharmony_ci return new InflateRaw(opts); 7931cb0ef41Sopenharmony_ci ReflectApply(Zlib, this, [opts, INFLATERAW]); 7941cb0ef41Sopenharmony_ci} 7951cb0ef41Sopenharmony_ciObjectSetPrototypeOf(InflateRaw.prototype, Zlib.prototype); 7961cb0ef41Sopenharmony_ciObjectSetPrototypeOf(InflateRaw, Zlib); 7971cb0ef41Sopenharmony_ci 7981cb0ef41Sopenharmony_cifunction Unzip(opts) { 7991cb0ef41Sopenharmony_ci if (!(this instanceof Unzip)) 8001cb0ef41Sopenharmony_ci return new Unzip(opts); 8011cb0ef41Sopenharmony_ci ReflectApply(Zlib, this, [opts, UNZIP]); 8021cb0ef41Sopenharmony_ci} 8031cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Unzip.prototype, Zlib.prototype); 8041cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Unzip, Zlib); 8051cb0ef41Sopenharmony_ci 8061cb0ef41Sopenharmony_cifunction createConvenienceMethod(ctor, sync) { 8071cb0ef41Sopenharmony_ci if (sync) { 8081cb0ef41Sopenharmony_ci return function syncBufferWrapper(buffer, opts) { 8091cb0ef41Sopenharmony_ci return zlibBufferSync(new ctor(opts), buffer); 8101cb0ef41Sopenharmony_ci }; 8111cb0ef41Sopenharmony_ci } 8121cb0ef41Sopenharmony_ci return function asyncBufferWrapper(buffer, opts, callback) { 8131cb0ef41Sopenharmony_ci if (typeof opts === 'function') { 8141cb0ef41Sopenharmony_ci callback = opts; 8151cb0ef41Sopenharmony_ci opts = {}; 8161cb0ef41Sopenharmony_ci } 8171cb0ef41Sopenharmony_ci return zlibBuffer(new ctor(opts), buffer, callback); 8181cb0ef41Sopenharmony_ci }; 8191cb0ef41Sopenharmony_ci} 8201cb0ef41Sopenharmony_ci 8211cb0ef41Sopenharmony_ciconst kMaxBrotliParam = MathMaxApply(ArrayPrototypeMap( 8221cb0ef41Sopenharmony_ci ObjectKeys(constants), 8231cb0ef41Sopenharmony_ci (key) => (StringPrototypeStartsWith(key, 'BROTLI_PARAM_') ? 8241cb0ef41Sopenharmony_ci constants[key] : 8251cb0ef41Sopenharmony_ci 0), 8261cb0ef41Sopenharmony_ci)); 8271cb0ef41Sopenharmony_ci 8281cb0ef41Sopenharmony_ciconst brotliInitParamsArray = new Uint32Array(kMaxBrotliParam + 1); 8291cb0ef41Sopenharmony_ci 8301cb0ef41Sopenharmony_ciconst brotliDefaultOpts = { 8311cb0ef41Sopenharmony_ci flush: BROTLI_OPERATION_PROCESS, 8321cb0ef41Sopenharmony_ci finishFlush: BROTLI_OPERATION_FINISH, 8331cb0ef41Sopenharmony_ci fullFlush: BROTLI_OPERATION_FLUSH, 8341cb0ef41Sopenharmony_ci}; 8351cb0ef41Sopenharmony_cifunction Brotli(opts, mode) { 8361cb0ef41Sopenharmony_ci assert(mode === BROTLI_DECODE || mode === BROTLI_ENCODE); 8371cb0ef41Sopenharmony_ci 8381cb0ef41Sopenharmony_ci TypedArrayPrototypeFill(brotliInitParamsArray, -1); 8391cb0ef41Sopenharmony_ci if (opts?.params) { 8401cb0ef41Sopenharmony_ci ArrayPrototypeForEach(ObjectKeys(opts.params), (origKey) => { 8411cb0ef41Sopenharmony_ci const key = +origKey; 8421cb0ef41Sopenharmony_ci if (NumberIsNaN(key) || key < 0 || key > kMaxBrotliParam || 8431cb0ef41Sopenharmony_ci (brotliInitParamsArray[key] | 0) !== -1) { 8441cb0ef41Sopenharmony_ci throw new ERR_BROTLI_INVALID_PARAM(origKey); 8451cb0ef41Sopenharmony_ci } 8461cb0ef41Sopenharmony_ci 8471cb0ef41Sopenharmony_ci const value = opts.params[origKey]; 8481cb0ef41Sopenharmony_ci if (typeof value !== 'number' && typeof value !== 'boolean') { 8491cb0ef41Sopenharmony_ci throw new ERR_INVALID_ARG_TYPE('options.params[key]', 8501cb0ef41Sopenharmony_ci 'number', opts.params[origKey]); 8511cb0ef41Sopenharmony_ci } 8521cb0ef41Sopenharmony_ci brotliInitParamsArray[key] = value; 8531cb0ef41Sopenharmony_ci }); 8541cb0ef41Sopenharmony_ci } 8551cb0ef41Sopenharmony_ci 8561cb0ef41Sopenharmony_ci const handle = mode === BROTLI_DECODE ? 8571cb0ef41Sopenharmony_ci new binding.BrotliDecoder(mode) : new binding.BrotliEncoder(mode); 8581cb0ef41Sopenharmony_ci 8591cb0ef41Sopenharmony_ci this._writeState = new Uint32Array(2); 8601cb0ef41Sopenharmony_ci // TODO(addaleax): Sometimes we generate better error codes in C++ land, 8611cb0ef41Sopenharmony_ci // e.g. ERR_BROTLI_PARAM_SET_FAILED -- it's hard to access them with 8621cb0ef41Sopenharmony_ci // the current bindings setup, though. 8631cb0ef41Sopenharmony_ci if (!handle.init(brotliInitParamsArray, 8641cb0ef41Sopenharmony_ci this._writeState, 8651cb0ef41Sopenharmony_ci processCallback)) { 8661cb0ef41Sopenharmony_ci throw new ERR_ZLIB_INITIALIZATION_FAILED(); 8671cb0ef41Sopenharmony_ci } 8681cb0ef41Sopenharmony_ci 8691cb0ef41Sopenharmony_ci ReflectApply(ZlibBase, this, [opts, mode, handle, brotliDefaultOpts]); 8701cb0ef41Sopenharmony_ci} 8711cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Brotli.prototype, Zlib.prototype); 8721cb0ef41Sopenharmony_ciObjectSetPrototypeOf(Brotli, Zlib); 8731cb0ef41Sopenharmony_ci 8741cb0ef41Sopenharmony_cifunction BrotliCompress(opts) { 8751cb0ef41Sopenharmony_ci if (!(this instanceof BrotliCompress)) 8761cb0ef41Sopenharmony_ci return new BrotliCompress(opts); 8771cb0ef41Sopenharmony_ci ReflectApply(Brotli, this, [opts, BROTLI_ENCODE]); 8781cb0ef41Sopenharmony_ci} 8791cb0ef41Sopenharmony_ciObjectSetPrototypeOf(BrotliCompress.prototype, Brotli.prototype); 8801cb0ef41Sopenharmony_ciObjectSetPrototypeOf(BrotliCompress, Brotli); 8811cb0ef41Sopenharmony_ci 8821cb0ef41Sopenharmony_cifunction BrotliDecompress(opts) { 8831cb0ef41Sopenharmony_ci if (!(this instanceof BrotliDecompress)) 8841cb0ef41Sopenharmony_ci return new BrotliDecompress(opts); 8851cb0ef41Sopenharmony_ci ReflectApply(Brotli, this, [opts, BROTLI_DECODE]); 8861cb0ef41Sopenharmony_ci} 8871cb0ef41Sopenharmony_ciObjectSetPrototypeOf(BrotliDecompress.prototype, Brotli.prototype); 8881cb0ef41Sopenharmony_ciObjectSetPrototypeOf(BrotliDecompress, Brotli); 8891cb0ef41Sopenharmony_ci 8901cb0ef41Sopenharmony_ci 8911cb0ef41Sopenharmony_cifunction createProperty(ctor) { 8921cb0ef41Sopenharmony_ci return { 8931cb0ef41Sopenharmony_ci __proto__: null, 8941cb0ef41Sopenharmony_ci configurable: true, 8951cb0ef41Sopenharmony_ci enumerable: true, 8961cb0ef41Sopenharmony_ci value: function(options) { 8971cb0ef41Sopenharmony_ci return new ctor(options); 8981cb0ef41Sopenharmony_ci }, 8991cb0ef41Sopenharmony_ci }; 9001cb0ef41Sopenharmony_ci} 9011cb0ef41Sopenharmony_ci 9021cb0ef41Sopenharmony_ci// Legacy alias on the C++ wrapper object. This is not public API, so we may 9031cb0ef41Sopenharmony_ci// want to runtime-deprecate it at some point. There's no hurry, though. 9041cb0ef41Sopenharmony_ciObjectDefineProperty(binding.Zlib.prototype, 'jsref', { 9051cb0ef41Sopenharmony_ci __proto__: null, 9061cb0ef41Sopenharmony_ci get() { return this[owner_symbol]; }, 9071cb0ef41Sopenharmony_ci set(v) { return this[owner_symbol] = v; }, 9081cb0ef41Sopenharmony_ci}); 9091cb0ef41Sopenharmony_ci 9101cb0ef41Sopenharmony_cimodule.exports = { 9111cb0ef41Sopenharmony_ci Deflate, 9121cb0ef41Sopenharmony_ci Inflate, 9131cb0ef41Sopenharmony_ci Gzip, 9141cb0ef41Sopenharmony_ci Gunzip, 9151cb0ef41Sopenharmony_ci DeflateRaw, 9161cb0ef41Sopenharmony_ci InflateRaw, 9171cb0ef41Sopenharmony_ci Unzip, 9181cb0ef41Sopenharmony_ci BrotliCompress, 9191cb0ef41Sopenharmony_ci BrotliDecompress, 9201cb0ef41Sopenharmony_ci 9211cb0ef41Sopenharmony_ci // Convenience methods. 9221cb0ef41Sopenharmony_ci // compress/decompress a string or buffer in one step. 9231cb0ef41Sopenharmony_ci deflate: createConvenienceMethod(Deflate, false), 9241cb0ef41Sopenharmony_ci deflateSync: createConvenienceMethod(Deflate, true), 9251cb0ef41Sopenharmony_ci gzip: createConvenienceMethod(Gzip, false), 9261cb0ef41Sopenharmony_ci gzipSync: createConvenienceMethod(Gzip, true), 9271cb0ef41Sopenharmony_ci deflateRaw: createConvenienceMethod(DeflateRaw, false), 9281cb0ef41Sopenharmony_ci deflateRawSync: createConvenienceMethod(DeflateRaw, true), 9291cb0ef41Sopenharmony_ci unzip: createConvenienceMethod(Unzip, false), 9301cb0ef41Sopenharmony_ci unzipSync: createConvenienceMethod(Unzip, true), 9311cb0ef41Sopenharmony_ci inflate: createConvenienceMethod(Inflate, false), 9321cb0ef41Sopenharmony_ci inflateSync: createConvenienceMethod(Inflate, true), 9331cb0ef41Sopenharmony_ci gunzip: createConvenienceMethod(Gunzip, false), 9341cb0ef41Sopenharmony_ci gunzipSync: createConvenienceMethod(Gunzip, true), 9351cb0ef41Sopenharmony_ci inflateRaw: createConvenienceMethod(InflateRaw, false), 9361cb0ef41Sopenharmony_ci inflateRawSync: createConvenienceMethod(InflateRaw, true), 9371cb0ef41Sopenharmony_ci brotliCompress: createConvenienceMethod(BrotliCompress, false), 9381cb0ef41Sopenharmony_ci brotliCompressSync: createConvenienceMethod(BrotliCompress, true), 9391cb0ef41Sopenharmony_ci brotliDecompress: createConvenienceMethod(BrotliDecompress, false), 9401cb0ef41Sopenharmony_ci brotliDecompressSync: createConvenienceMethod(BrotliDecompress, true), 9411cb0ef41Sopenharmony_ci}; 9421cb0ef41Sopenharmony_ci 9431cb0ef41Sopenharmony_ciObjectDefineProperties(module.exports, { 9441cb0ef41Sopenharmony_ci createDeflate: createProperty(Deflate), 9451cb0ef41Sopenharmony_ci createInflate: createProperty(Inflate), 9461cb0ef41Sopenharmony_ci createDeflateRaw: createProperty(DeflateRaw), 9471cb0ef41Sopenharmony_ci createInflateRaw: createProperty(InflateRaw), 9481cb0ef41Sopenharmony_ci createGzip: createProperty(Gzip), 9491cb0ef41Sopenharmony_ci createGunzip: createProperty(Gunzip), 9501cb0ef41Sopenharmony_ci createUnzip: createProperty(Unzip), 9511cb0ef41Sopenharmony_ci createBrotliCompress: createProperty(BrotliCompress), 9521cb0ef41Sopenharmony_ci createBrotliDecompress: createProperty(BrotliDecompress), 9531cb0ef41Sopenharmony_ci constants: { 9541cb0ef41Sopenharmony_ci __proto__: null, 9551cb0ef41Sopenharmony_ci configurable: false, 9561cb0ef41Sopenharmony_ci enumerable: true, 9571cb0ef41Sopenharmony_ci value: constants, 9581cb0ef41Sopenharmony_ci }, 9591cb0ef41Sopenharmony_ci codes: { 9601cb0ef41Sopenharmony_ci __proto__: null, 9611cb0ef41Sopenharmony_ci enumerable: true, 9621cb0ef41Sopenharmony_ci writable: false, 9631cb0ef41Sopenharmony_ci value: ObjectFreeze(codes), 9641cb0ef41Sopenharmony_ci }, 9651cb0ef41Sopenharmony_ci}); 9661cb0ef41Sopenharmony_ci 9671cb0ef41Sopenharmony_ci// These should be considered deprecated 9681cb0ef41Sopenharmony_ci// expose all the zlib constants 9691cb0ef41Sopenharmony_cifor (const bkey of ObjectKeys(constants)) { 9701cb0ef41Sopenharmony_ci if (StringPrototypeStartsWith(bkey, 'BROTLI')) continue; 9711cb0ef41Sopenharmony_ci ObjectDefineProperty(module.exports, bkey, { 9721cb0ef41Sopenharmony_ci __proto__: null, 9731cb0ef41Sopenharmony_ci enumerable: false, value: constants[bkey], writable: false, 9741cb0ef41Sopenharmony_ci }); 9751cb0ef41Sopenharmony_ci} 976