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

Function createBrotliHandle

lib/internal/streams/iter/transform.js:205–244  ·  view source on GitHub ↗

* Create a bare Brotli handle. * @returns {{ handle: object, writeState: Uint32Array, chunkSize: number }}

(mode, options, processCallback, onError)

Source from the content-addressed store, hash-verified

203 * @returns {{ handle: object, writeState: Uint32Array, chunkSize: number }}
204 */
205function createBrotliHandle(mode, options, processCallback, onError) {
206 // Validate before creating native handle.
207 const chunkSize = validateChunkSize(options);
208 const dictionary = validateDictionary(options.dictionary);
209 validateParams(options.params, kMaxBrotliParam, ERR_BROTLI_INVALID_PARAM);
210
211 const handle = mode === BROTLI_ENCODE ?
212 new binding.BrotliEncoder(mode) : new binding.BrotliDecoder(mode);
213 const writeState = new Uint32Array(2);
214
215 TypedArrayPrototypeFill(brotliInitParamsArray, -1);
216 // Streaming-appropriate defaults: quality 6 (not 11) and lgwin 20 (1MB,
217 // not 4MB). Quality 11 is intended for offline/build-time compression
218 // and allocates ~400MB of internal state. Quality 6 is ~10x faster with
219 // only ~10-15% worse compression ratio - the standard for dynamic HTTP
220 // content-encoding (nginx, Caddy, Cloudflare all use 4-6).
221 if (mode === BROTLI_ENCODE) {
222 brotliInitParamsArray[constants.BROTLI_PARAM_QUALITY] = 6;
223 brotliInitParamsArray[constants.BROTLI_PARAM_LGWIN] = 20;
224 }
225 if (options.params) {
226 // User-supplied params override the defaults above.
227 const params = options.params;
228 const keys = ObjectKeys(params);
229 for (let i = 0; i < keys.length; i++) {
230 const key = +keys[i];
231 brotliInitParamsArray[key] = params[keys[i]];
232 }
233 }
234
235 handle.onerror = onError;
236 handle.init(
237 brotliInitParamsArray,
238 writeState,
239 processCallback,
240 dictionary,
241 );
242
243 return { __proto__: null, handle, writeState, chunkSize };
244}
245
246/**
247 * Create a bare Zstd handle.

Callers 4

compressBrotliFunction · 0.85
decompressBrotliFunction · 0.85
compressBrotliSyncFunction · 0.85
decompressBrotliSyncFunction · 0.85

Calls 4

validateChunkSizeFunction · 0.85
validateDictionaryFunction · 0.85
validateParamsFunction · 0.85
initMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…