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

Function ZlibBase

lib/zlib.js:210–275  ·  view source on GitHub ↗

* The base class for all Zlib-style streams. * @class

(opts, mode, handle, { flush, finishFlush, fullFlush })

Source from the content-addressed store, hash-verified

208 * @class
209 */
210function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) {
211 let chunkSize = Z_DEFAULT_CHUNK;
212 let maxOutputLength = kMaxLength;
213 // The ZlibBase class is not exported to user land, the mode should only be
214 // passed in by us.
215 assert(typeof mode === 'number');
216 assert(mode >= DEFLATE && mode <= ZSTD_DECOMPRESS);
217
218 let flushBoundIdx;
219 if (mode === BROTLI_ENCODE || mode === BROTLI_DECODE) {
220 flushBoundIdx = FLUSH_BOUND_IDX_BROTLI;
221 } else if (mode === ZSTD_COMPRESS || mode === ZSTD_DECOMPRESS) {
222 flushBoundIdx = FLUSH_BOUND_IDX_ZSTD;
223 } else {
224 flushBoundIdx = FLUSH_BOUND_IDX_NORMAL;
225 }
226
227 if (opts) {
228 chunkSize = opts.chunkSize;
229 if (!validateFiniteNumber(chunkSize, 'options.chunkSize')) {
230 chunkSize = Z_DEFAULT_CHUNK;
231 } else if (chunkSize < Z_MIN_CHUNK) {
232 throw new ERR_OUT_OF_RANGE('options.chunkSize',
233 `>= ${Z_MIN_CHUNK}`, chunkSize);
234 }
235
236 flush = checkRangesOrGetDefault(
237 opts.flush, 'options.flush',
238 FLUSH_BOUND[flushBoundIdx][0], FLUSH_BOUND[flushBoundIdx][1], flush);
239
240 finishFlush = checkRangesOrGetDefault(
241 opts.finishFlush, 'options.finishFlush',
242 FLUSH_BOUND[flushBoundIdx][0], FLUSH_BOUND[flushBoundIdx][1],
243 finishFlush);
244
245 maxOutputLength = checkRangesOrGetDefault(
246 opts.maxOutputLength, 'options.maxOutputLength',
247 1, kMaxLength, kMaxLength);
248
249 if (opts.encoding || opts.objectMode || opts.writableObjectMode) {
250 opts = { ...opts };
251 opts.encoding = null;
252 opts.objectMode = false;
253 opts.writableObjectMode = false;
254 }
255 }
256
257 Transform.call(this, { autoDestroy: true, ...opts });
258 this[kError] = null;
259 this.bytesWritten = 0;
260 this._handle = handle;
261 handle[owner_symbol] = this;
262 // Used by processCallback() and zlibOnError()
263 handle.onerror = zlibOnError;
264 this._outBuffer = Buffer.allocUnsafe(chunkSize);
265 this._outOffset = 0;
266
267 this._chunkSize = chunkSize;

Callers

nothing calls this directly

Calls 2

assertFunction · 0.70
callMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…