| 810 | fullFlush: BROTLI_OPERATION_FLUSH, |
| 811 | }; |
| 812 | function Brotli(opts, mode) { |
| 813 | assert(mode === BROTLI_DECODE || mode === BROTLI_ENCODE); |
| 814 | |
| 815 | brotliInitParamsArray.fill(-1); |
| 816 | if (opts?.params) { |
| 817 | ObjectKeys(opts.params).forEach((origKey) => { |
| 818 | const key = +origKey; |
| 819 | if (NumberIsNaN(key) || key < 0 || key > kMaxBrotliParam || |
| 820 | (brotliInitParamsArray[key] | 0) !== -1) { |
| 821 | throw new ERR_BROTLI_INVALID_PARAM(origKey); |
| 822 | } |
| 823 | |
| 824 | const value = opts.params[origKey]; |
| 825 | if (typeof value !== 'number' && typeof value !== 'boolean') { |
| 826 | throw new ERR_INVALID_ARG_TYPE('options.params[key]', |
| 827 | 'number', opts.params[origKey]); |
| 828 | } |
| 829 | brotliInitParamsArray[key] = value; |
| 830 | }); |
| 831 | } |
| 832 | |
| 833 | let dictionary = opts?.dictionary; |
| 834 | if (dictionary !== undefined && !isArrayBufferView(dictionary)) { |
| 835 | if (isAnyArrayBuffer(dictionary)) { |
| 836 | dictionary = Buffer.from(dictionary); |
| 837 | } else { |
| 838 | throw new ERR_INVALID_ARG_TYPE( |
| 839 | 'options.dictionary', |
| 840 | ['Buffer', 'TypedArray', 'DataView', 'ArrayBuffer'], |
| 841 | dictionary, |
| 842 | ); |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | const handle = mode === BROTLI_DECODE ? |
| 847 | new binding.BrotliDecoder(mode) : new binding.BrotliEncoder(mode); |
| 848 | |
| 849 | this._writeState = new Uint32Array(2); |
| 850 | handle.init( |
| 851 | brotliInitParamsArray, |
| 852 | this._writeState, |
| 853 | processCallback, |
| 854 | dictionary, |
| 855 | ); |
| 856 | |
| 857 | ZlibBase.call(this, opts, mode, handle, brotliDefaultOpts); |
| 858 | } |
| 859 | ObjectSetPrototypeOf(Brotli.prototype, Zlib.prototype); |
| 860 | ObjectSetPrototypeOf(Brotli, Zlib); |
| 861 | |