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

Function createZlibHandle

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

* Create a bare Zlib handle (gzip, gunzip, deflate, inflate). * @returns {{ handle: object, writeState: Uint32Array, chunkSize: number }}

(mode, options, processCallback, onError)

Source from the content-addressed store, hash-verified

164 * @returns {{ handle: object, writeState: Uint32Array, chunkSize: number }}
165 */
166function createZlibHandle(mode, options, processCallback, onError) {
167 // Validate all options before creating the native handle to avoid
168 // "close before init" assertion if validation throws.
169 const chunkSize = validateChunkSize(options);
170 const windowBits = checkRangesOrGetDefault(
171 options.windowBits, 'options.windowBits',
172 Z_MIN_WINDOWBITS, Z_MAX_WINDOWBITS, Z_DEFAULT_WINDOWBITS);
173 // Default compression level 4 (not Z_DEFAULT_COMPRESSION which maps to
174 // level 6). Level 4 is ~1.5x faster with only ~5-10% worse compression
175 // ratio - the sweet spot for streaming and HTTP content-encoding.
176 const level = checkRangesOrGetDefault(
177 options.level, 'options.level',
178 Z_MIN_LEVEL, Z_MAX_LEVEL, 4);
179 // memLevel 9 uses ~128KB more memory than 8 but provides faster hash
180 // lookups during compression. Negligible memory cost for the speed gain.
181 const memLevel = checkRangesOrGetDefault(
182 options.memLevel, 'options.memLevel',
183 Z_MIN_MEMLEVEL, Z_MAX_MEMLEVEL, 9);
184 const strategy = checkRangesOrGetDefault(
185 options.strategy, 'options.strategy',
186 Z_DEFAULT_STRATEGY, Z_FIXED, Z_DEFAULT_STRATEGY);
187 const dictionary = validateDictionary(options.dictionary);
188
189 const handle = new binding.Zlib(mode);
190 const writeState = new Uint32Array(2);
191
192 handle.onerror = onError;
193 handle.init(
194 windowBits, level, memLevel, strategy,
195 writeState, processCallback, dictionary,
196 );
197
198 return { __proto__: null, handle, writeState, chunkSize };
199}
200
201/**
202 * Create a bare Brotli handle.

Callers 8

compressGzipFunction · 0.85
compressDeflateFunction · 0.85
decompressGzipFunction · 0.85
decompressDeflateFunction · 0.85
compressGzipSyncFunction · 0.85
compressDeflateSyncFunction · 0.85
decompressGzipSyncFunction · 0.85
decompressDeflateSyncFunction · 0.85

Calls 3

validateChunkSizeFunction · 0.85
validateDictionaryFunction · 0.85
initMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…