MCPcopy Index your code
hub / github.com/nodejs/node / Brotli

Function Brotli

lib/zlib.js:812–858  ·  view source on GitHub ↗
(opts, mode)

Source from the content-addressed store, hash-verified

810 fullFlush: BROTLI_OPERATION_FLUSH,
811};
812function 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}
859ObjectSetPrototypeOf(Brotli.prototype, Zlib.prototype);
860ObjectSetPrototypeOf(Brotli, Zlib);
861

Callers

nothing calls this directly

Calls 6

fillMethod · 0.80
assertFunction · 0.70
forEachMethod · 0.65
fromMethod · 0.45
initMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…