* Create a bare Zlib handle (gzip, gunzip, deflate, inflate). * @returns {{ handle: object, writeState: Uint32Array, chunkSize: number }}
(mode, options, processCallback, onError)
| 164 | * @returns {{ handle: object, writeState: Uint32Array, chunkSize: number }} |
| 165 | */ |
| 166 | function 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. |
no test coverage detected
searching dependent graphs…