11cb0ef41Sopenharmony_ci# Zlib
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ci<!--introduced_in=v0.10.0-->
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci> Stability: 2 - Stable
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ci<!-- source_link=lib/zlib.js -->
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciThe `node:zlib` module provides compression functionality implemented using
101cb0ef41Sopenharmony_ciGzip, Deflate/Inflate, and Brotli.
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciTo access it:
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci```js
151cb0ef41Sopenharmony_ciconst zlib = require('node:zlib');
161cb0ef41Sopenharmony_ci```
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciCompression and decompression are built around the Node.js [Streams API][].
191cb0ef41Sopenharmony_ci
201cb0ef41Sopenharmony_ciCompressing or decompressing a stream (such as a file) can be accomplished by
211cb0ef41Sopenharmony_cipiping the source stream through a `zlib` `Transform` stream into a destination
221cb0ef41Sopenharmony_cistream:
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci```js
251cb0ef41Sopenharmony_ciconst { createGzip } = require('node:zlib');
261cb0ef41Sopenharmony_ciconst { pipeline } = require('node:stream');
271cb0ef41Sopenharmony_ciconst {
281cb0ef41Sopenharmony_ci  createReadStream,
291cb0ef41Sopenharmony_ci  createWriteStream,
301cb0ef41Sopenharmony_ci} = require('node:fs');
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ciconst gzip = createGzip();
331cb0ef41Sopenharmony_ciconst source = createReadStream('input.txt');
341cb0ef41Sopenharmony_ciconst destination = createWriteStream('input.txt.gz');
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_cipipeline(source, gzip, destination, (err) => {
371cb0ef41Sopenharmony_ci  if (err) {
381cb0ef41Sopenharmony_ci    console.error('An error occurred:', err);
391cb0ef41Sopenharmony_ci    process.exitCode = 1;
401cb0ef41Sopenharmony_ci  }
411cb0ef41Sopenharmony_ci});
421cb0ef41Sopenharmony_ci
431cb0ef41Sopenharmony_ci// Or, Promisified
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ciconst { promisify } = require('node:util');
461cb0ef41Sopenharmony_ciconst pipe = promisify(pipeline);
471cb0ef41Sopenharmony_ci
481cb0ef41Sopenharmony_ciasync function do_gzip(input, output) {
491cb0ef41Sopenharmony_ci  const gzip = createGzip();
501cb0ef41Sopenharmony_ci  const source = createReadStream(input);
511cb0ef41Sopenharmony_ci  const destination = createWriteStream(output);
521cb0ef41Sopenharmony_ci  await pipe(source, gzip, destination);
531cb0ef41Sopenharmony_ci}
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_cido_gzip('input.txt', 'input.txt.gz')
561cb0ef41Sopenharmony_ci  .catch((err) => {
571cb0ef41Sopenharmony_ci    console.error('An error occurred:', err);
581cb0ef41Sopenharmony_ci    process.exitCode = 1;
591cb0ef41Sopenharmony_ci  });
601cb0ef41Sopenharmony_ci```
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ciIt is also possible to compress or decompress data in a single step:
631cb0ef41Sopenharmony_ci
641cb0ef41Sopenharmony_ci```js
651cb0ef41Sopenharmony_ciconst { deflate, unzip } = require('node:zlib');
661cb0ef41Sopenharmony_ci
671cb0ef41Sopenharmony_ciconst input = '.................................';
681cb0ef41Sopenharmony_cideflate(input, (err, buffer) => {
691cb0ef41Sopenharmony_ci  if (err) {
701cb0ef41Sopenharmony_ci    console.error('An error occurred:', err);
711cb0ef41Sopenharmony_ci    process.exitCode = 1;
721cb0ef41Sopenharmony_ci  }
731cb0ef41Sopenharmony_ci  console.log(buffer.toString('base64'));
741cb0ef41Sopenharmony_ci});
751cb0ef41Sopenharmony_ci
761cb0ef41Sopenharmony_ciconst buffer = Buffer.from('eJzT0yMAAGTvBe8=', 'base64');
771cb0ef41Sopenharmony_ciunzip(buffer, (err, buffer) => {
781cb0ef41Sopenharmony_ci  if (err) {
791cb0ef41Sopenharmony_ci    console.error('An error occurred:', err);
801cb0ef41Sopenharmony_ci    process.exitCode = 1;
811cb0ef41Sopenharmony_ci  }
821cb0ef41Sopenharmony_ci  console.log(buffer.toString());
831cb0ef41Sopenharmony_ci});
841cb0ef41Sopenharmony_ci
851cb0ef41Sopenharmony_ci// Or, Promisified
861cb0ef41Sopenharmony_ci
871cb0ef41Sopenharmony_ciconst { promisify } = require('node:util');
881cb0ef41Sopenharmony_ciconst do_unzip = promisify(unzip);
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_cido_unzip(buffer)
911cb0ef41Sopenharmony_ci  .then((buf) => console.log(buf.toString()))
921cb0ef41Sopenharmony_ci  .catch((err) => {
931cb0ef41Sopenharmony_ci    console.error('An error occurred:', err);
941cb0ef41Sopenharmony_ci    process.exitCode = 1;
951cb0ef41Sopenharmony_ci  });
961cb0ef41Sopenharmony_ci```
971cb0ef41Sopenharmony_ci
981cb0ef41Sopenharmony_ci## Threadpool usage and performance considerations
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ciAll `zlib` APIs, except those that are explicitly synchronous, use the Node.js
1011cb0ef41Sopenharmony_ciinternal threadpool. This can lead to surprising effects and performance
1021cb0ef41Sopenharmony_cilimitations in some applications.
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ciCreating and using a large number of zlib objects simultaneously can cause
1051cb0ef41Sopenharmony_cisignificant memory fragmentation.
1061cb0ef41Sopenharmony_ci
1071cb0ef41Sopenharmony_ci```js
1081cb0ef41Sopenharmony_ciconst zlib = require('node:zlib');
1091cb0ef41Sopenharmony_ci
1101cb0ef41Sopenharmony_ciconst payload = Buffer.from('This is some data');
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ci// WARNING: DO NOT DO THIS!
1131cb0ef41Sopenharmony_cifor (let i = 0; i < 30000; ++i) {
1141cb0ef41Sopenharmony_ci  zlib.deflate(payload, (err, buffer) => {});
1151cb0ef41Sopenharmony_ci}
1161cb0ef41Sopenharmony_ci```
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ciIn the preceding example, 30,000 deflate instances are created concurrently.
1191cb0ef41Sopenharmony_ciBecause of how some operating systems handle memory allocation and
1201cb0ef41Sopenharmony_cideallocation, this may lead to significant memory fragmentation.
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ciIt is strongly recommended that the results of compression
1231cb0ef41Sopenharmony_cioperations be cached to avoid duplication of effort.
1241cb0ef41Sopenharmony_ci
1251cb0ef41Sopenharmony_ci## Compressing HTTP requests and responses
1261cb0ef41Sopenharmony_ci
1271cb0ef41Sopenharmony_ciThe `node:zlib` module can be used to implement support for the `gzip`, `deflate`
1281cb0ef41Sopenharmony_ciand `br` content-encoding mechanisms defined by
1291cb0ef41Sopenharmony_ci[HTTP](https://tools.ietf.org/html/rfc7230#section-4.2).
1301cb0ef41Sopenharmony_ci
1311cb0ef41Sopenharmony_ciThe HTTP [`Accept-Encoding`][] header is used within an HTTP request to identify
1321cb0ef41Sopenharmony_cithe compression encodings accepted by the client. The [`Content-Encoding`][]
1331cb0ef41Sopenharmony_ciheader is used to identify the compression encodings actually applied to a
1341cb0ef41Sopenharmony_cimessage.
1351cb0ef41Sopenharmony_ci
1361cb0ef41Sopenharmony_ciThe examples given below are drastically simplified to show the basic concept.
1371cb0ef41Sopenharmony_ciUsing `zlib` encoding can be expensive, and the results ought to be cached.
1381cb0ef41Sopenharmony_ciSee [Memory usage tuning][] for more information on the speed/memory/compression
1391cb0ef41Sopenharmony_citradeoffs involved in `zlib` usage.
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_ci```js
1421cb0ef41Sopenharmony_ci// Client request example
1431cb0ef41Sopenharmony_ciconst zlib = require('node:zlib');
1441cb0ef41Sopenharmony_ciconst http = require('node:http');
1451cb0ef41Sopenharmony_ciconst fs = require('node:fs');
1461cb0ef41Sopenharmony_ciconst { pipeline } = require('node:stream');
1471cb0ef41Sopenharmony_ci
1481cb0ef41Sopenharmony_ciconst request = http.get({ host: 'example.com',
1491cb0ef41Sopenharmony_ci                           path: '/',
1501cb0ef41Sopenharmony_ci                           port: 80,
1511cb0ef41Sopenharmony_ci                           headers: { 'Accept-Encoding': 'br,gzip,deflate' } });
1521cb0ef41Sopenharmony_cirequest.on('response', (response) => {
1531cb0ef41Sopenharmony_ci  const output = fs.createWriteStream('example.com_index.html');
1541cb0ef41Sopenharmony_ci
1551cb0ef41Sopenharmony_ci  const onError = (err) => {
1561cb0ef41Sopenharmony_ci    if (err) {
1571cb0ef41Sopenharmony_ci      console.error('An error occurred:', err);
1581cb0ef41Sopenharmony_ci      process.exitCode = 1;
1591cb0ef41Sopenharmony_ci    }
1601cb0ef41Sopenharmony_ci  };
1611cb0ef41Sopenharmony_ci
1621cb0ef41Sopenharmony_ci  switch (response.headers['content-encoding']) {
1631cb0ef41Sopenharmony_ci    case 'br':
1641cb0ef41Sopenharmony_ci      pipeline(response, zlib.createBrotliDecompress(), output, onError);
1651cb0ef41Sopenharmony_ci      break;
1661cb0ef41Sopenharmony_ci    // Or, just use zlib.createUnzip() to handle both of the following cases:
1671cb0ef41Sopenharmony_ci    case 'gzip':
1681cb0ef41Sopenharmony_ci      pipeline(response, zlib.createGunzip(), output, onError);
1691cb0ef41Sopenharmony_ci      break;
1701cb0ef41Sopenharmony_ci    case 'deflate':
1711cb0ef41Sopenharmony_ci      pipeline(response, zlib.createInflate(), output, onError);
1721cb0ef41Sopenharmony_ci      break;
1731cb0ef41Sopenharmony_ci    default:
1741cb0ef41Sopenharmony_ci      pipeline(response, output, onError);
1751cb0ef41Sopenharmony_ci      break;
1761cb0ef41Sopenharmony_ci  }
1771cb0ef41Sopenharmony_ci});
1781cb0ef41Sopenharmony_ci```
1791cb0ef41Sopenharmony_ci
1801cb0ef41Sopenharmony_ci```js
1811cb0ef41Sopenharmony_ci// server example
1821cb0ef41Sopenharmony_ci// Running a gzip operation on every request is quite expensive.
1831cb0ef41Sopenharmony_ci// It would be much more efficient to cache the compressed buffer.
1841cb0ef41Sopenharmony_ciconst zlib = require('node:zlib');
1851cb0ef41Sopenharmony_ciconst http = require('node:http');
1861cb0ef41Sopenharmony_ciconst fs = require('node:fs');
1871cb0ef41Sopenharmony_ciconst { pipeline } = require('node:stream');
1881cb0ef41Sopenharmony_ci
1891cb0ef41Sopenharmony_cihttp.createServer((request, response) => {
1901cb0ef41Sopenharmony_ci  const raw = fs.createReadStream('index.html');
1911cb0ef41Sopenharmony_ci  // Store both a compressed and an uncompressed version of the resource.
1921cb0ef41Sopenharmony_ci  response.setHeader('Vary', 'Accept-Encoding');
1931cb0ef41Sopenharmony_ci  let acceptEncoding = request.headers['accept-encoding'];
1941cb0ef41Sopenharmony_ci  if (!acceptEncoding) {
1951cb0ef41Sopenharmony_ci    acceptEncoding = '';
1961cb0ef41Sopenharmony_ci  }
1971cb0ef41Sopenharmony_ci
1981cb0ef41Sopenharmony_ci  const onError = (err) => {
1991cb0ef41Sopenharmony_ci    if (err) {
2001cb0ef41Sopenharmony_ci      // If an error occurs, there's not much we can do because
2011cb0ef41Sopenharmony_ci      // the server has already sent the 200 response code and
2021cb0ef41Sopenharmony_ci      // some amount of data has already been sent to the client.
2031cb0ef41Sopenharmony_ci      // The best we can do is terminate the response immediately
2041cb0ef41Sopenharmony_ci      // and log the error.
2051cb0ef41Sopenharmony_ci      response.end();
2061cb0ef41Sopenharmony_ci      console.error('An error occurred:', err);
2071cb0ef41Sopenharmony_ci    }
2081cb0ef41Sopenharmony_ci  };
2091cb0ef41Sopenharmony_ci
2101cb0ef41Sopenharmony_ci  // Note: This is not a conformant accept-encoding parser.
2111cb0ef41Sopenharmony_ci  // See https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
2121cb0ef41Sopenharmony_ci  if (/\bdeflate\b/.test(acceptEncoding)) {
2131cb0ef41Sopenharmony_ci    response.writeHead(200, { 'Content-Encoding': 'deflate' });
2141cb0ef41Sopenharmony_ci    pipeline(raw, zlib.createDeflate(), response, onError);
2151cb0ef41Sopenharmony_ci  } else if (/\bgzip\b/.test(acceptEncoding)) {
2161cb0ef41Sopenharmony_ci    response.writeHead(200, { 'Content-Encoding': 'gzip' });
2171cb0ef41Sopenharmony_ci    pipeline(raw, zlib.createGzip(), response, onError);
2181cb0ef41Sopenharmony_ci  } else if (/\bbr\b/.test(acceptEncoding)) {
2191cb0ef41Sopenharmony_ci    response.writeHead(200, { 'Content-Encoding': 'br' });
2201cb0ef41Sopenharmony_ci    pipeline(raw, zlib.createBrotliCompress(), response, onError);
2211cb0ef41Sopenharmony_ci  } else {
2221cb0ef41Sopenharmony_ci    response.writeHead(200, {});
2231cb0ef41Sopenharmony_ci    pipeline(raw, response, onError);
2241cb0ef41Sopenharmony_ci  }
2251cb0ef41Sopenharmony_ci}).listen(1337);
2261cb0ef41Sopenharmony_ci```
2271cb0ef41Sopenharmony_ci
2281cb0ef41Sopenharmony_ciBy default, the `zlib` methods will throw an error when decompressing
2291cb0ef41Sopenharmony_citruncated data. However, if it is known that the data is incomplete, or
2301cb0ef41Sopenharmony_cithe desire is to inspect only the beginning of a compressed file, it is
2311cb0ef41Sopenharmony_cipossible to suppress the default error handling by changing the flushing
2321cb0ef41Sopenharmony_cimethod that is used to decompress the last chunk of input data:
2331cb0ef41Sopenharmony_ci
2341cb0ef41Sopenharmony_ci```js
2351cb0ef41Sopenharmony_ci// This is a truncated version of the buffer from the above examples
2361cb0ef41Sopenharmony_ciconst buffer = Buffer.from('eJzT0yMA', 'base64');
2371cb0ef41Sopenharmony_ci
2381cb0ef41Sopenharmony_cizlib.unzip(
2391cb0ef41Sopenharmony_ci  buffer,
2401cb0ef41Sopenharmony_ci  // For Brotli, the equivalent is zlib.constants.BROTLI_OPERATION_FLUSH.
2411cb0ef41Sopenharmony_ci  { finishFlush: zlib.constants.Z_SYNC_FLUSH },
2421cb0ef41Sopenharmony_ci  (err, buffer) => {
2431cb0ef41Sopenharmony_ci    if (err) {
2441cb0ef41Sopenharmony_ci      console.error('An error occurred:', err);
2451cb0ef41Sopenharmony_ci      process.exitCode = 1;
2461cb0ef41Sopenharmony_ci    }
2471cb0ef41Sopenharmony_ci    console.log(buffer.toString());
2481cb0ef41Sopenharmony_ci  });
2491cb0ef41Sopenharmony_ci```
2501cb0ef41Sopenharmony_ci
2511cb0ef41Sopenharmony_ciThis will not change the behavior in other error-throwing situations, e.g.
2521cb0ef41Sopenharmony_ciwhen the input data has an invalid format. Using this method, it will not be
2531cb0ef41Sopenharmony_cipossible to determine whether the input ended prematurely or lacks the
2541cb0ef41Sopenharmony_ciintegrity checks, making it necessary to manually check that the
2551cb0ef41Sopenharmony_cidecompressed result is valid.
2561cb0ef41Sopenharmony_ci
2571cb0ef41Sopenharmony_ci## Memory usage tuning
2581cb0ef41Sopenharmony_ci
2591cb0ef41Sopenharmony_ci<!--type=misc-->
2601cb0ef41Sopenharmony_ci
2611cb0ef41Sopenharmony_ci### For zlib-based streams
2621cb0ef41Sopenharmony_ci
2631cb0ef41Sopenharmony_ciFrom `zlib/zconf.h`, modified for Node.js usage:
2641cb0ef41Sopenharmony_ci
2651cb0ef41Sopenharmony_ciThe memory requirements for deflate are (in bytes):
2661cb0ef41Sopenharmony_ci
2671cb0ef41Sopenharmony_ci<!-- eslint-disable semi -->
2681cb0ef41Sopenharmony_ci
2691cb0ef41Sopenharmony_ci```js
2701cb0ef41Sopenharmony_ci(1 << (windowBits + 2)) + (1 << (memLevel + 9))
2711cb0ef41Sopenharmony_ci```
2721cb0ef41Sopenharmony_ci
2731cb0ef41Sopenharmony_ciThat is: 128K for `windowBits` = 15 + 128K for `memLevel` = 8
2741cb0ef41Sopenharmony_ci(default values) plus a few kilobytes for small objects.
2751cb0ef41Sopenharmony_ci
2761cb0ef41Sopenharmony_ciFor example, to reduce the default memory requirements from 256K to 128K, the
2771cb0ef41Sopenharmony_cioptions should be set to:
2781cb0ef41Sopenharmony_ci
2791cb0ef41Sopenharmony_ci```js
2801cb0ef41Sopenharmony_ciconst options = { windowBits: 14, memLevel: 7 };
2811cb0ef41Sopenharmony_ci```
2821cb0ef41Sopenharmony_ci
2831cb0ef41Sopenharmony_ciThis will, however, generally degrade compression.
2841cb0ef41Sopenharmony_ci
2851cb0ef41Sopenharmony_ciThe memory requirements for inflate are (in bytes) `1 << windowBits`.
2861cb0ef41Sopenharmony_ciThat is, 32K for `windowBits` = 15 (default value) plus a few kilobytes
2871cb0ef41Sopenharmony_cifor small objects.
2881cb0ef41Sopenharmony_ci
2891cb0ef41Sopenharmony_ciThis is in addition to a single internal output slab buffer of size
2901cb0ef41Sopenharmony_ci`chunkSize`, which defaults to 16K.
2911cb0ef41Sopenharmony_ci
2921cb0ef41Sopenharmony_ciThe speed of `zlib` compression is affected most dramatically by the
2931cb0ef41Sopenharmony_ci`level` setting. A higher level will result in better compression, but
2941cb0ef41Sopenharmony_ciwill take longer to complete. A lower level will result in less
2951cb0ef41Sopenharmony_cicompression, but will be much faster.
2961cb0ef41Sopenharmony_ci
2971cb0ef41Sopenharmony_ciIn general, greater memory usage options will mean that Node.js has to make
2981cb0ef41Sopenharmony_cifewer calls to `zlib` because it will be able to process more data on
2991cb0ef41Sopenharmony_cieach `write` operation. So, this is another factor that affects the
3001cb0ef41Sopenharmony_cispeed, at the cost of memory usage.
3011cb0ef41Sopenharmony_ci
3021cb0ef41Sopenharmony_ci### For Brotli-based streams
3031cb0ef41Sopenharmony_ci
3041cb0ef41Sopenharmony_ciThere are equivalents to the zlib options for Brotli-based streams, although
3051cb0ef41Sopenharmony_cithese options have different ranges than the zlib ones:
3061cb0ef41Sopenharmony_ci
3071cb0ef41Sopenharmony_ci* zlib's `level` option matches Brotli's `BROTLI_PARAM_QUALITY` option.
3081cb0ef41Sopenharmony_ci* zlib's `windowBits` option matches Brotli's `BROTLI_PARAM_LGWIN` option.
3091cb0ef41Sopenharmony_ci
3101cb0ef41Sopenharmony_ciSee [below][Brotli parameters] for more details on Brotli-specific options.
3111cb0ef41Sopenharmony_ci
3121cb0ef41Sopenharmony_ci## Flushing
3131cb0ef41Sopenharmony_ci
3141cb0ef41Sopenharmony_ciCalling [`.flush()`][] on a compression stream will make `zlib` return as much
3151cb0ef41Sopenharmony_cioutput as currently possible. This may come at the cost of degraded compression
3161cb0ef41Sopenharmony_ciquality, but can be useful when data needs to be available as soon as possible.
3171cb0ef41Sopenharmony_ci
3181cb0ef41Sopenharmony_ciIn the following example, `flush()` is used to write a compressed partial
3191cb0ef41Sopenharmony_ciHTTP response to the client:
3201cb0ef41Sopenharmony_ci
3211cb0ef41Sopenharmony_ci```js
3221cb0ef41Sopenharmony_ciconst zlib = require('node:zlib');
3231cb0ef41Sopenharmony_ciconst http = require('node:http');
3241cb0ef41Sopenharmony_ciconst { pipeline } = require('node:stream');
3251cb0ef41Sopenharmony_ci
3261cb0ef41Sopenharmony_cihttp.createServer((request, response) => {
3271cb0ef41Sopenharmony_ci  // For the sake of simplicity, the Accept-Encoding checks are omitted.
3281cb0ef41Sopenharmony_ci  response.writeHead(200, { 'content-encoding': 'gzip' });
3291cb0ef41Sopenharmony_ci  const output = zlib.createGzip();
3301cb0ef41Sopenharmony_ci  let i;
3311cb0ef41Sopenharmony_ci
3321cb0ef41Sopenharmony_ci  pipeline(output, response, (err) => {
3331cb0ef41Sopenharmony_ci    if (err) {
3341cb0ef41Sopenharmony_ci      // If an error occurs, there's not much we can do because
3351cb0ef41Sopenharmony_ci      // the server has already sent the 200 response code and
3361cb0ef41Sopenharmony_ci      // some amount of data has already been sent to the client.
3371cb0ef41Sopenharmony_ci      // The best we can do is terminate the response immediately
3381cb0ef41Sopenharmony_ci      // and log the error.
3391cb0ef41Sopenharmony_ci      clearInterval(i);
3401cb0ef41Sopenharmony_ci      response.end();
3411cb0ef41Sopenharmony_ci      console.error('An error occurred:', err);
3421cb0ef41Sopenharmony_ci    }
3431cb0ef41Sopenharmony_ci  });
3441cb0ef41Sopenharmony_ci
3451cb0ef41Sopenharmony_ci  i = setInterval(() => {
3461cb0ef41Sopenharmony_ci    output.write(`The current time is ${Date()}\n`, () => {
3471cb0ef41Sopenharmony_ci      // The data has been passed to zlib, but the compression algorithm may
3481cb0ef41Sopenharmony_ci      // have decided to buffer the data for more efficient compression.
3491cb0ef41Sopenharmony_ci      // Calling .flush() will make the data available as soon as the client
3501cb0ef41Sopenharmony_ci      // is ready to receive it.
3511cb0ef41Sopenharmony_ci      output.flush();
3521cb0ef41Sopenharmony_ci    });
3531cb0ef41Sopenharmony_ci  }, 1000);
3541cb0ef41Sopenharmony_ci}).listen(1337);
3551cb0ef41Sopenharmony_ci```
3561cb0ef41Sopenharmony_ci
3571cb0ef41Sopenharmony_ci## Constants
3581cb0ef41Sopenharmony_ci
3591cb0ef41Sopenharmony_ci<!-- YAML
3601cb0ef41Sopenharmony_ciadded: v0.5.8
3611cb0ef41Sopenharmony_ci-->
3621cb0ef41Sopenharmony_ci
3631cb0ef41Sopenharmony_ci<!--type=misc-->
3641cb0ef41Sopenharmony_ci
3651cb0ef41Sopenharmony_ci### zlib constants
3661cb0ef41Sopenharmony_ci
3671cb0ef41Sopenharmony_ciAll of the constants defined in `zlib.h` are also defined on
3681cb0ef41Sopenharmony_ci`require('node:zlib').constants`. In the normal course of operations, it will
3691cb0ef41Sopenharmony_cinot be necessary to use these constants. They are documented so that their
3701cb0ef41Sopenharmony_cipresence is not surprising. This section is taken almost directly from the
3711cb0ef41Sopenharmony_ci[zlib documentation][].
3721cb0ef41Sopenharmony_ci
3731cb0ef41Sopenharmony_ciPreviously, the constants were available directly from `require('node:zlib')`,
3741cb0ef41Sopenharmony_cifor instance `zlib.Z_NO_FLUSH`. Accessing the constants directly from the module
3751cb0ef41Sopenharmony_ciis currently still possible but is deprecated.
3761cb0ef41Sopenharmony_ci
3771cb0ef41Sopenharmony_ciAllowed flush values.
3781cb0ef41Sopenharmony_ci
3791cb0ef41Sopenharmony_ci* `zlib.constants.Z_NO_FLUSH`
3801cb0ef41Sopenharmony_ci* `zlib.constants.Z_PARTIAL_FLUSH`
3811cb0ef41Sopenharmony_ci* `zlib.constants.Z_SYNC_FLUSH`
3821cb0ef41Sopenharmony_ci* `zlib.constants.Z_FULL_FLUSH`
3831cb0ef41Sopenharmony_ci* `zlib.constants.Z_FINISH`
3841cb0ef41Sopenharmony_ci* `zlib.constants.Z_BLOCK`
3851cb0ef41Sopenharmony_ci* `zlib.constants.Z_TREES`
3861cb0ef41Sopenharmony_ci
3871cb0ef41Sopenharmony_ciReturn codes for the compression/decompression functions. Negative
3881cb0ef41Sopenharmony_civalues are errors, positive values are used for special but normal
3891cb0ef41Sopenharmony_cievents.
3901cb0ef41Sopenharmony_ci
3911cb0ef41Sopenharmony_ci* `zlib.constants.Z_OK`
3921cb0ef41Sopenharmony_ci* `zlib.constants.Z_STREAM_END`
3931cb0ef41Sopenharmony_ci* `zlib.constants.Z_NEED_DICT`
3941cb0ef41Sopenharmony_ci* `zlib.constants.Z_ERRNO`
3951cb0ef41Sopenharmony_ci* `zlib.constants.Z_STREAM_ERROR`
3961cb0ef41Sopenharmony_ci* `zlib.constants.Z_DATA_ERROR`
3971cb0ef41Sopenharmony_ci* `zlib.constants.Z_MEM_ERROR`
3981cb0ef41Sopenharmony_ci* `zlib.constants.Z_BUF_ERROR`
3991cb0ef41Sopenharmony_ci* `zlib.constants.Z_VERSION_ERROR`
4001cb0ef41Sopenharmony_ci
4011cb0ef41Sopenharmony_ciCompression levels.
4021cb0ef41Sopenharmony_ci
4031cb0ef41Sopenharmony_ci* `zlib.constants.Z_NO_COMPRESSION`
4041cb0ef41Sopenharmony_ci* `zlib.constants.Z_BEST_SPEED`
4051cb0ef41Sopenharmony_ci* `zlib.constants.Z_BEST_COMPRESSION`
4061cb0ef41Sopenharmony_ci* `zlib.constants.Z_DEFAULT_COMPRESSION`
4071cb0ef41Sopenharmony_ci
4081cb0ef41Sopenharmony_ciCompression strategy.
4091cb0ef41Sopenharmony_ci
4101cb0ef41Sopenharmony_ci* `zlib.constants.Z_FILTERED`
4111cb0ef41Sopenharmony_ci* `zlib.constants.Z_HUFFMAN_ONLY`
4121cb0ef41Sopenharmony_ci* `zlib.constants.Z_RLE`
4131cb0ef41Sopenharmony_ci* `zlib.constants.Z_FIXED`
4141cb0ef41Sopenharmony_ci* `zlib.constants.Z_DEFAULT_STRATEGY`
4151cb0ef41Sopenharmony_ci
4161cb0ef41Sopenharmony_ci### Brotli constants
4171cb0ef41Sopenharmony_ci
4181cb0ef41Sopenharmony_ci<!-- YAML
4191cb0ef41Sopenharmony_ciadded:
4201cb0ef41Sopenharmony_ci - v11.7.0
4211cb0ef41Sopenharmony_ci - v10.16.0
4221cb0ef41Sopenharmony_ci-->
4231cb0ef41Sopenharmony_ci
4241cb0ef41Sopenharmony_ciThere are several options and other constants available for Brotli-based
4251cb0ef41Sopenharmony_cistreams:
4261cb0ef41Sopenharmony_ci
4271cb0ef41Sopenharmony_ci#### Flush operations
4281cb0ef41Sopenharmony_ci
4291cb0ef41Sopenharmony_ciThe following values are valid flush operations for Brotli-based streams:
4301cb0ef41Sopenharmony_ci
4311cb0ef41Sopenharmony_ci* `zlib.constants.BROTLI_OPERATION_PROCESS` (default for all operations)
4321cb0ef41Sopenharmony_ci* `zlib.constants.BROTLI_OPERATION_FLUSH` (default when calling `.flush()`)
4331cb0ef41Sopenharmony_ci* `zlib.constants.BROTLI_OPERATION_FINISH` (default for the last chunk)
4341cb0ef41Sopenharmony_ci* `zlib.constants.BROTLI_OPERATION_EMIT_METADATA`
4351cb0ef41Sopenharmony_ci  * This particular operation may be hard to use in a Node.js context,
4361cb0ef41Sopenharmony_ci    as the streaming layer makes it hard to know which data will end up
4371cb0ef41Sopenharmony_ci    in this frame. Also, there is currently no way to consume this data through
4381cb0ef41Sopenharmony_ci    the Node.js API.
4391cb0ef41Sopenharmony_ci
4401cb0ef41Sopenharmony_ci#### Compressor options
4411cb0ef41Sopenharmony_ci
4421cb0ef41Sopenharmony_ciThere are several options that can be set on Brotli encoders, affecting
4431cb0ef41Sopenharmony_cicompression efficiency and speed. Both the keys and the values can be accessed
4441cb0ef41Sopenharmony_cias properties of the `zlib.constants` object.
4451cb0ef41Sopenharmony_ci
4461cb0ef41Sopenharmony_ciThe most important options are:
4471cb0ef41Sopenharmony_ci
4481cb0ef41Sopenharmony_ci* `BROTLI_PARAM_MODE`
4491cb0ef41Sopenharmony_ci  * `BROTLI_MODE_GENERIC` (default)
4501cb0ef41Sopenharmony_ci  * `BROTLI_MODE_TEXT`, adjusted for UTF-8 text
4511cb0ef41Sopenharmony_ci  * `BROTLI_MODE_FONT`, adjusted for WOFF 2.0 fonts
4521cb0ef41Sopenharmony_ci* `BROTLI_PARAM_QUALITY`
4531cb0ef41Sopenharmony_ci  * Ranges from `BROTLI_MIN_QUALITY` to `BROTLI_MAX_QUALITY`,
4541cb0ef41Sopenharmony_ci    with a default of `BROTLI_DEFAULT_QUALITY`.
4551cb0ef41Sopenharmony_ci* `BROTLI_PARAM_SIZE_HINT`
4561cb0ef41Sopenharmony_ci  * Integer value representing the expected input size;
4571cb0ef41Sopenharmony_ci    defaults to `0` for an unknown input size.
4581cb0ef41Sopenharmony_ci
4591cb0ef41Sopenharmony_ciThe following flags can be set for advanced control over the compression
4601cb0ef41Sopenharmony_cialgorithm and memory usage tuning:
4611cb0ef41Sopenharmony_ci
4621cb0ef41Sopenharmony_ci* `BROTLI_PARAM_LGWIN`
4631cb0ef41Sopenharmony_ci  * Ranges from `BROTLI_MIN_WINDOW_BITS` to `BROTLI_MAX_WINDOW_BITS`,
4641cb0ef41Sopenharmony_ci    with a default of `BROTLI_DEFAULT_WINDOW`, or up to
4651cb0ef41Sopenharmony_ci    `BROTLI_LARGE_MAX_WINDOW_BITS` if the `BROTLI_PARAM_LARGE_WINDOW` flag
4661cb0ef41Sopenharmony_ci    is set.
4671cb0ef41Sopenharmony_ci* `BROTLI_PARAM_LGBLOCK`
4681cb0ef41Sopenharmony_ci  * Ranges from `BROTLI_MIN_INPUT_BLOCK_BITS` to `BROTLI_MAX_INPUT_BLOCK_BITS`.
4691cb0ef41Sopenharmony_ci* `BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING`
4701cb0ef41Sopenharmony_ci  * Boolean flag that decreases compression ratio in favour of
4711cb0ef41Sopenharmony_ci    decompression speed.
4721cb0ef41Sopenharmony_ci* `BROTLI_PARAM_LARGE_WINDOW`
4731cb0ef41Sopenharmony_ci  * Boolean flag enabling “Large Window Brotli” mode (not compatible with the
4741cb0ef41Sopenharmony_ci    Brotli format as standardized in [RFC 7932][]).
4751cb0ef41Sopenharmony_ci* `BROTLI_PARAM_NPOSTFIX`
4761cb0ef41Sopenharmony_ci  * Ranges from `0` to `BROTLI_MAX_NPOSTFIX`.
4771cb0ef41Sopenharmony_ci* `BROTLI_PARAM_NDIRECT`
4781cb0ef41Sopenharmony_ci  * Ranges from `0` to `15 << NPOSTFIX` in steps of `1 << NPOSTFIX`.
4791cb0ef41Sopenharmony_ci
4801cb0ef41Sopenharmony_ci#### Decompressor options
4811cb0ef41Sopenharmony_ci
4821cb0ef41Sopenharmony_ciThese advanced options are available for controlling decompression:
4831cb0ef41Sopenharmony_ci
4841cb0ef41Sopenharmony_ci* `BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION`
4851cb0ef41Sopenharmony_ci  * Boolean flag that affects internal memory allocation patterns.
4861cb0ef41Sopenharmony_ci* `BROTLI_DECODER_PARAM_LARGE_WINDOW`
4871cb0ef41Sopenharmony_ci  * Boolean flag enabling “Large Window Brotli” mode (not compatible with the
4881cb0ef41Sopenharmony_ci    Brotli format as standardized in [RFC 7932][]).
4891cb0ef41Sopenharmony_ci
4901cb0ef41Sopenharmony_ci## Class: `Options`
4911cb0ef41Sopenharmony_ci
4921cb0ef41Sopenharmony_ci<!-- YAML
4931cb0ef41Sopenharmony_ciadded: v0.11.1
4941cb0ef41Sopenharmony_cichanges:
4951cb0ef41Sopenharmony_ci  - version:
4961cb0ef41Sopenharmony_ci    - v14.5.0
4971cb0ef41Sopenharmony_ci    - v12.19.0
4981cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/33516
4991cb0ef41Sopenharmony_ci    description: The `maxOutputLength` option is supported now.
5001cb0ef41Sopenharmony_ci  - version: v9.4.0
5011cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
5021cb0ef41Sopenharmony_ci    description: The `dictionary` option can be an `ArrayBuffer`.
5031cb0ef41Sopenharmony_ci  - version: v8.0.0
5041cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
5051cb0ef41Sopenharmony_ci    description: The `dictionary` option can be an `Uint8Array` now.
5061cb0ef41Sopenharmony_ci  - version: v5.11.0
5071cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/6069
5081cb0ef41Sopenharmony_ci    description: The `finishFlush` option is supported now.
5091cb0ef41Sopenharmony_ci-->
5101cb0ef41Sopenharmony_ci
5111cb0ef41Sopenharmony_ci<!--type=misc-->
5121cb0ef41Sopenharmony_ci
5131cb0ef41Sopenharmony_ciEach zlib-based class takes an `options` object. No options are required.
5141cb0ef41Sopenharmony_ci
5151cb0ef41Sopenharmony_ciSome options are only relevant when compressing and are
5161cb0ef41Sopenharmony_ciignored by the decompression classes.
5171cb0ef41Sopenharmony_ci
5181cb0ef41Sopenharmony_ci* `flush` {integer} **Default:** `zlib.constants.Z_NO_FLUSH`
5191cb0ef41Sopenharmony_ci* `finishFlush` {integer} **Default:** `zlib.constants.Z_FINISH`
5201cb0ef41Sopenharmony_ci* `chunkSize` {integer} **Default:** `16 * 1024`
5211cb0ef41Sopenharmony_ci* `windowBits` {integer}
5221cb0ef41Sopenharmony_ci* `level` {integer} (compression only)
5231cb0ef41Sopenharmony_ci* `memLevel` {integer} (compression only)
5241cb0ef41Sopenharmony_ci* `strategy` {integer} (compression only)
5251cb0ef41Sopenharmony_ci* `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer} (deflate/inflate only,
5261cb0ef41Sopenharmony_ci  empty dictionary by default)
5271cb0ef41Sopenharmony_ci* `info` {boolean} (If `true`, returns an object with `buffer` and `engine`.)
5281cb0ef41Sopenharmony_ci* `maxOutputLength` {integer} Limits output size when using
5291cb0ef41Sopenharmony_ci  [convenience methods][]. **Default:** [`buffer.kMaxLength`][]
5301cb0ef41Sopenharmony_ci
5311cb0ef41Sopenharmony_ciSee the [`deflateInit2` and `inflateInit2`][] documentation for more
5321cb0ef41Sopenharmony_ciinformation.
5331cb0ef41Sopenharmony_ci
5341cb0ef41Sopenharmony_ci## Class: `BrotliOptions`
5351cb0ef41Sopenharmony_ci
5361cb0ef41Sopenharmony_ci<!-- YAML
5371cb0ef41Sopenharmony_ciadded: v11.7.0
5381cb0ef41Sopenharmony_cichanges:
5391cb0ef41Sopenharmony_ci  - version:
5401cb0ef41Sopenharmony_ci    - v14.5.0
5411cb0ef41Sopenharmony_ci    - v12.19.0
5421cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/33516
5431cb0ef41Sopenharmony_ci    description: The `maxOutputLength` option is supported now.
5441cb0ef41Sopenharmony_ci-->
5451cb0ef41Sopenharmony_ci
5461cb0ef41Sopenharmony_ci<!--type=misc-->
5471cb0ef41Sopenharmony_ci
5481cb0ef41Sopenharmony_ciEach Brotli-based class takes an `options` object. All options are optional.
5491cb0ef41Sopenharmony_ci
5501cb0ef41Sopenharmony_ci* `flush` {integer} **Default:** `zlib.constants.BROTLI_OPERATION_PROCESS`
5511cb0ef41Sopenharmony_ci* `finishFlush` {integer} **Default:** `zlib.constants.BROTLI_OPERATION_FINISH`
5521cb0ef41Sopenharmony_ci* `chunkSize` {integer} **Default:** `16 * 1024`
5531cb0ef41Sopenharmony_ci* `params` {Object} Key-value object containing indexed [Brotli parameters][].
5541cb0ef41Sopenharmony_ci* `maxOutputLength` {integer} Limits output size when using
5551cb0ef41Sopenharmony_ci  [convenience methods][]. **Default:** [`buffer.kMaxLength`][]
5561cb0ef41Sopenharmony_ci
5571cb0ef41Sopenharmony_ciFor example:
5581cb0ef41Sopenharmony_ci
5591cb0ef41Sopenharmony_ci```js
5601cb0ef41Sopenharmony_ciconst stream = zlib.createBrotliCompress({
5611cb0ef41Sopenharmony_ci  chunkSize: 32 * 1024,
5621cb0ef41Sopenharmony_ci  params: {
5631cb0ef41Sopenharmony_ci    [zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT,
5641cb0ef41Sopenharmony_ci    [zlib.constants.BROTLI_PARAM_QUALITY]: 4,
5651cb0ef41Sopenharmony_ci    [zlib.constants.BROTLI_PARAM_SIZE_HINT]: fs.statSync(inputFile).size,
5661cb0ef41Sopenharmony_ci  },
5671cb0ef41Sopenharmony_ci});
5681cb0ef41Sopenharmony_ci```
5691cb0ef41Sopenharmony_ci
5701cb0ef41Sopenharmony_ci## Class: `zlib.BrotliCompress`
5711cb0ef41Sopenharmony_ci
5721cb0ef41Sopenharmony_ci<!-- YAML
5731cb0ef41Sopenharmony_ciadded:
5741cb0ef41Sopenharmony_ci - v11.7.0
5751cb0ef41Sopenharmony_ci - v10.16.0
5761cb0ef41Sopenharmony_ci-->
5771cb0ef41Sopenharmony_ci
5781cb0ef41Sopenharmony_ciCompress data using the Brotli algorithm.
5791cb0ef41Sopenharmony_ci
5801cb0ef41Sopenharmony_ci## Class: `zlib.BrotliDecompress`
5811cb0ef41Sopenharmony_ci
5821cb0ef41Sopenharmony_ci<!-- YAML
5831cb0ef41Sopenharmony_ciadded:
5841cb0ef41Sopenharmony_ci - v11.7.0
5851cb0ef41Sopenharmony_ci - v10.16.0
5861cb0ef41Sopenharmony_ci-->
5871cb0ef41Sopenharmony_ci
5881cb0ef41Sopenharmony_ciDecompress data using the Brotli algorithm.
5891cb0ef41Sopenharmony_ci
5901cb0ef41Sopenharmony_ci## Class: `zlib.Deflate`
5911cb0ef41Sopenharmony_ci
5921cb0ef41Sopenharmony_ci<!-- YAML
5931cb0ef41Sopenharmony_ciadded: v0.5.8
5941cb0ef41Sopenharmony_ci-->
5951cb0ef41Sopenharmony_ci
5961cb0ef41Sopenharmony_ciCompress data using deflate.
5971cb0ef41Sopenharmony_ci
5981cb0ef41Sopenharmony_ci## Class: `zlib.DeflateRaw`
5991cb0ef41Sopenharmony_ci
6001cb0ef41Sopenharmony_ci<!-- YAML
6011cb0ef41Sopenharmony_ciadded: v0.5.8
6021cb0ef41Sopenharmony_ci-->
6031cb0ef41Sopenharmony_ci
6041cb0ef41Sopenharmony_ciCompress data using deflate, and do not append a `zlib` header.
6051cb0ef41Sopenharmony_ci
6061cb0ef41Sopenharmony_ci## Class: `zlib.Gunzip`
6071cb0ef41Sopenharmony_ci
6081cb0ef41Sopenharmony_ci<!-- YAML
6091cb0ef41Sopenharmony_ciadded: v0.5.8
6101cb0ef41Sopenharmony_cichanges:
6111cb0ef41Sopenharmony_ci  - version: v6.0.0
6121cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/5883
6131cb0ef41Sopenharmony_ci    description: Trailing garbage at the end of the input stream will now
6141cb0ef41Sopenharmony_ci                 result in an `'error'` event.
6151cb0ef41Sopenharmony_ci  - version: v5.9.0
6161cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/5120
6171cb0ef41Sopenharmony_ci    description: Multiple concatenated gzip file members are supported now.
6181cb0ef41Sopenharmony_ci  - version: v5.0.0
6191cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/2595
6201cb0ef41Sopenharmony_ci    description: A truncated input stream will now result in an `'error'` event.
6211cb0ef41Sopenharmony_ci-->
6221cb0ef41Sopenharmony_ci
6231cb0ef41Sopenharmony_ciDecompress a gzip stream.
6241cb0ef41Sopenharmony_ci
6251cb0ef41Sopenharmony_ci## Class: `zlib.Gzip`
6261cb0ef41Sopenharmony_ci
6271cb0ef41Sopenharmony_ci<!-- YAML
6281cb0ef41Sopenharmony_ciadded: v0.5.8
6291cb0ef41Sopenharmony_ci-->
6301cb0ef41Sopenharmony_ci
6311cb0ef41Sopenharmony_ciCompress data using gzip.
6321cb0ef41Sopenharmony_ci
6331cb0ef41Sopenharmony_ci## Class: `zlib.Inflate`
6341cb0ef41Sopenharmony_ci
6351cb0ef41Sopenharmony_ci<!-- YAML
6361cb0ef41Sopenharmony_ciadded: v0.5.8
6371cb0ef41Sopenharmony_cichanges:
6381cb0ef41Sopenharmony_ci  - version: v5.0.0
6391cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/2595
6401cb0ef41Sopenharmony_ci    description: A truncated input stream will now result in an `'error'` event.
6411cb0ef41Sopenharmony_ci-->
6421cb0ef41Sopenharmony_ci
6431cb0ef41Sopenharmony_ciDecompress a deflate stream.
6441cb0ef41Sopenharmony_ci
6451cb0ef41Sopenharmony_ci## Class: `zlib.InflateRaw`
6461cb0ef41Sopenharmony_ci
6471cb0ef41Sopenharmony_ci<!-- YAML
6481cb0ef41Sopenharmony_ciadded: v0.5.8
6491cb0ef41Sopenharmony_cichanges:
6501cb0ef41Sopenharmony_ci  - version: v6.8.0
6511cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/8512
6521cb0ef41Sopenharmony_ci    description: Custom dictionaries are now supported by `InflateRaw`.
6531cb0ef41Sopenharmony_ci  - version: v5.0.0
6541cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/2595
6551cb0ef41Sopenharmony_ci    description: A truncated input stream will now result in an `'error'` event.
6561cb0ef41Sopenharmony_ci-->
6571cb0ef41Sopenharmony_ci
6581cb0ef41Sopenharmony_ciDecompress a raw deflate stream.
6591cb0ef41Sopenharmony_ci
6601cb0ef41Sopenharmony_ci## Class: `zlib.Unzip`
6611cb0ef41Sopenharmony_ci
6621cb0ef41Sopenharmony_ci<!-- YAML
6631cb0ef41Sopenharmony_ciadded: v0.5.8
6641cb0ef41Sopenharmony_ci-->
6651cb0ef41Sopenharmony_ci
6661cb0ef41Sopenharmony_ciDecompress either a Gzip- or Deflate-compressed stream by auto-detecting
6671cb0ef41Sopenharmony_cithe header.
6681cb0ef41Sopenharmony_ci
6691cb0ef41Sopenharmony_ci## Class: `zlib.ZlibBase`
6701cb0ef41Sopenharmony_ci
6711cb0ef41Sopenharmony_ci<!-- YAML
6721cb0ef41Sopenharmony_ciadded: v0.5.8
6731cb0ef41Sopenharmony_cichanges:
6741cb0ef41Sopenharmony_ci  - version:
6751cb0ef41Sopenharmony_ci     - v11.7.0
6761cb0ef41Sopenharmony_ci     - v10.16.0
6771cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/24939
6781cb0ef41Sopenharmony_ci    description: This class was renamed from `Zlib` to `ZlibBase`.
6791cb0ef41Sopenharmony_ci-->
6801cb0ef41Sopenharmony_ci
6811cb0ef41Sopenharmony_ciNot exported by the `node:zlib` module. It is documented here because it is the
6821cb0ef41Sopenharmony_cibase class of the compressor/decompressor classes.
6831cb0ef41Sopenharmony_ci
6841cb0ef41Sopenharmony_ciThis class inherits from [`stream.Transform`][], allowing `node:zlib` objects to
6851cb0ef41Sopenharmony_cibe used in pipes and similar stream operations.
6861cb0ef41Sopenharmony_ci
6871cb0ef41Sopenharmony_ci### `zlib.bytesRead`
6881cb0ef41Sopenharmony_ci
6891cb0ef41Sopenharmony_ci<!-- YAML
6901cb0ef41Sopenharmony_ciadded: v8.1.0
6911cb0ef41Sopenharmony_cideprecated: v10.0.0
6921cb0ef41Sopenharmony_ci-->
6931cb0ef41Sopenharmony_ci
6941cb0ef41Sopenharmony_ci> Stability: 0 - Deprecated: Use [`zlib.bytesWritten`][] instead.
6951cb0ef41Sopenharmony_ci
6961cb0ef41Sopenharmony_ci* {number}
6971cb0ef41Sopenharmony_ci
6981cb0ef41Sopenharmony_ciDeprecated alias for [`zlib.bytesWritten`][]. This original name was chosen
6991cb0ef41Sopenharmony_cibecause it also made sense to interpret the value as the number of bytes
7001cb0ef41Sopenharmony_ciread by the engine, but is inconsistent with other streams in Node.js that
7011cb0ef41Sopenharmony_ciexpose values under these names.
7021cb0ef41Sopenharmony_ci
7031cb0ef41Sopenharmony_ci### `zlib.bytesWritten`
7041cb0ef41Sopenharmony_ci
7051cb0ef41Sopenharmony_ci<!-- YAML
7061cb0ef41Sopenharmony_ciadded: v10.0.0
7071cb0ef41Sopenharmony_ci-->
7081cb0ef41Sopenharmony_ci
7091cb0ef41Sopenharmony_ci* {number}
7101cb0ef41Sopenharmony_ci
7111cb0ef41Sopenharmony_ciThe `zlib.bytesWritten` property specifies the number of bytes written to
7121cb0ef41Sopenharmony_cithe engine, before the bytes are processed (compressed or decompressed,
7131cb0ef41Sopenharmony_cias appropriate for the derived class).
7141cb0ef41Sopenharmony_ci
7151cb0ef41Sopenharmony_ci### `zlib.close([callback])`
7161cb0ef41Sopenharmony_ci
7171cb0ef41Sopenharmony_ci<!-- YAML
7181cb0ef41Sopenharmony_ciadded: v0.9.4
7191cb0ef41Sopenharmony_ci-->
7201cb0ef41Sopenharmony_ci
7211cb0ef41Sopenharmony_ci* `callback` {Function}
7221cb0ef41Sopenharmony_ci
7231cb0ef41Sopenharmony_ciClose the underlying handle.
7241cb0ef41Sopenharmony_ci
7251cb0ef41Sopenharmony_ci### `zlib.flush([kind, ]callback)`
7261cb0ef41Sopenharmony_ci
7271cb0ef41Sopenharmony_ci<!-- YAML
7281cb0ef41Sopenharmony_ciadded: v0.5.8
7291cb0ef41Sopenharmony_ci-->
7301cb0ef41Sopenharmony_ci
7311cb0ef41Sopenharmony_ci* `kind` **Default:** `zlib.constants.Z_FULL_FLUSH` for zlib-based streams,
7321cb0ef41Sopenharmony_ci  `zlib.constants.BROTLI_OPERATION_FLUSH` for Brotli-based streams.
7331cb0ef41Sopenharmony_ci* `callback` {Function}
7341cb0ef41Sopenharmony_ci
7351cb0ef41Sopenharmony_ciFlush pending data. Don't call this frivolously, premature flushes negatively
7361cb0ef41Sopenharmony_ciimpact the effectiveness of the compression algorithm.
7371cb0ef41Sopenharmony_ci
7381cb0ef41Sopenharmony_ciCalling this only flushes data from the internal `zlib` state, and does not
7391cb0ef41Sopenharmony_ciperform flushing of any kind on the streams level. Rather, it behaves like a
7401cb0ef41Sopenharmony_cinormal call to `.write()`, i.e. it will be queued up behind other pending
7411cb0ef41Sopenharmony_ciwrites and will only produce output when data is being read from the stream.
7421cb0ef41Sopenharmony_ci
7431cb0ef41Sopenharmony_ci### `zlib.params(level, strategy, callback)`
7441cb0ef41Sopenharmony_ci
7451cb0ef41Sopenharmony_ci<!-- YAML
7461cb0ef41Sopenharmony_ciadded: v0.11.4
7471cb0ef41Sopenharmony_ci-->
7481cb0ef41Sopenharmony_ci
7491cb0ef41Sopenharmony_ci* `level` {integer}
7501cb0ef41Sopenharmony_ci* `strategy` {integer}
7511cb0ef41Sopenharmony_ci* `callback` {Function}
7521cb0ef41Sopenharmony_ci
7531cb0ef41Sopenharmony_ciThis function is only available for zlib-based streams, i.e. not Brotli.
7541cb0ef41Sopenharmony_ci
7551cb0ef41Sopenharmony_ciDynamically update the compression level and compression strategy.
7561cb0ef41Sopenharmony_ciOnly applicable to deflate algorithm.
7571cb0ef41Sopenharmony_ci
7581cb0ef41Sopenharmony_ci### `zlib.reset()`
7591cb0ef41Sopenharmony_ci
7601cb0ef41Sopenharmony_ci<!-- YAML
7611cb0ef41Sopenharmony_ciadded: v0.7.0
7621cb0ef41Sopenharmony_ci-->
7631cb0ef41Sopenharmony_ci
7641cb0ef41Sopenharmony_ciReset the compressor/decompressor to factory defaults. Only applicable to
7651cb0ef41Sopenharmony_cithe inflate and deflate algorithms.
7661cb0ef41Sopenharmony_ci
7671cb0ef41Sopenharmony_ci## `zlib.constants`
7681cb0ef41Sopenharmony_ci
7691cb0ef41Sopenharmony_ci<!-- YAML
7701cb0ef41Sopenharmony_ciadded: v7.0.0
7711cb0ef41Sopenharmony_ci-->
7721cb0ef41Sopenharmony_ci
7731cb0ef41Sopenharmony_ciProvides an object enumerating Zlib-related constants.
7741cb0ef41Sopenharmony_ci
7751cb0ef41Sopenharmony_ci## `zlib.createBrotliCompress([options])`
7761cb0ef41Sopenharmony_ci
7771cb0ef41Sopenharmony_ci<!-- YAML
7781cb0ef41Sopenharmony_ciadded:
7791cb0ef41Sopenharmony_ci - v11.7.0
7801cb0ef41Sopenharmony_ci - v10.16.0
7811cb0ef41Sopenharmony_ci-->
7821cb0ef41Sopenharmony_ci
7831cb0ef41Sopenharmony_ci* `options` {brotli options}
7841cb0ef41Sopenharmony_ci
7851cb0ef41Sopenharmony_ciCreates and returns a new [`BrotliCompress`][] object.
7861cb0ef41Sopenharmony_ci
7871cb0ef41Sopenharmony_ci## `zlib.createBrotliDecompress([options])`
7881cb0ef41Sopenharmony_ci
7891cb0ef41Sopenharmony_ci<!-- YAML
7901cb0ef41Sopenharmony_ciadded:
7911cb0ef41Sopenharmony_ci - v11.7.0
7921cb0ef41Sopenharmony_ci - v10.16.0
7931cb0ef41Sopenharmony_ci-->
7941cb0ef41Sopenharmony_ci
7951cb0ef41Sopenharmony_ci* `options` {brotli options}
7961cb0ef41Sopenharmony_ci
7971cb0ef41Sopenharmony_ciCreates and returns a new [`BrotliDecompress`][] object.
7981cb0ef41Sopenharmony_ci
7991cb0ef41Sopenharmony_ci## `zlib.createDeflate([options])`
8001cb0ef41Sopenharmony_ci
8011cb0ef41Sopenharmony_ci<!-- YAML
8021cb0ef41Sopenharmony_ciadded: v0.5.8
8031cb0ef41Sopenharmony_ci-->
8041cb0ef41Sopenharmony_ci
8051cb0ef41Sopenharmony_ci* `options` {zlib options}
8061cb0ef41Sopenharmony_ci
8071cb0ef41Sopenharmony_ciCreates and returns a new [`Deflate`][] object.
8081cb0ef41Sopenharmony_ci
8091cb0ef41Sopenharmony_ci## `zlib.createDeflateRaw([options])`
8101cb0ef41Sopenharmony_ci
8111cb0ef41Sopenharmony_ci<!-- YAML
8121cb0ef41Sopenharmony_ciadded: v0.5.8
8131cb0ef41Sopenharmony_ci-->
8141cb0ef41Sopenharmony_ci
8151cb0ef41Sopenharmony_ci* `options` {zlib options}
8161cb0ef41Sopenharmony_ci
8171cb0ef41Sopenharmony_ciCreates and returns a new [`DeflateRaw`][] object.
8181cb0ef41Sopenharmony_ci
8191cb0ef41Sopenharmony_ciAn upgrade of zlib from 1.2.8 to 1.2.11 changed behavior when `windowBits`
8201cb0ef41Sopenharmony_ciis set to 8 for raw deflate streams. zlib would automatically set `windowBits`
8211cb0ef41Sopenharmony_cito 9 if was initially set to 8. Newer versions of zlib will throw an exception,
8221cb0ef41Sopenharmony_ciso Node.js restored the original behavior of upgrading a value of 8 to 9,
8231cb0ef41Sopenharmony_cisince passing `windowBits = 9` to zlib actually results in a compressed stream
8241cb0ef41Sopenharmony_cithat effectively uses an 8-bit window only.
8251cb0ef41Sopenharmony_ci
8261cb0ef41Sopenharmony_ci## `zlib.createGunzip([options])`
8271cb0ef41Sopenharmony_ci
8281cb0ef41Sopenharmony_ci<!-- YAML
8291cb0ef41Sopenharmony_ciadded: v0.5.8
8301cb0ef41Sopenharmony_ci-->
8311cb0ef41Sopenharmony_ci
8321cb0ef41Sopenharmony_ci* `options` {zlib options}
8331cb0ef41Sopenharmony_ci
8341cb0ef41Sopenharmony_ciCreates and returns a new [`Gunzip`][] object.
8351cb0ef41Sopenharmony_ci
8361cb0ef41Sopenharmony_ci## `zlib.createGzip([options])`
8371cb0ef41Sopenharmony_ci
8381cb0ef41Sopenharmony_ci<!-- YAML
8391cb0ef41Sopenharmony_ciadded: v0.5.8
8401cb0ef41Sopenharmony_ci-->
8411cb0ef41Sopenharmony_ci
8421cb0ef41Sopenharmony_ci* `options` {zlib options}
8431cb0ef41Sopenharmony_ci
8441cb0ef41Sopenharmony_ciCreates and returns a new [`Gzip`][] object.
8451cb0ef41Sopenharmony_ciSee [example][zlib.createGzip example].
8461cb0ef41Sopenharmony_ci
8471cb0ef41Sopenharmony_ci## `zlib.createInflate([options])`
8481cb0ef41Sopenharmony_ci
8491cb0ef41Sopenharmony_ci<!-- YAML
8501cb0ef41Sopenharmony_ciadded: v0.5.8
8511cb0ef41Sopenharmony_ci-->
8521cb0ef41Sopenharmony_ci
8531cb0ef41Sopenharmony_ci* `options` {zlib options}
8541cb0ef41Sopenharmony_ci
8551cb0ef41Sopenharmony_ciCreates and returns a new [`Inflate`][] object.
8561cb0ef41Sopenharmony_ci
8571cb0ef41Sopenharmony_ci## `zlib.createInflateRaw([options])`
8581cb0ef41Sopenharmony_ci
8591cb0ef41Sopenharmony_ci<!-- YAML
8601cb0ef41Sopenharmony_ciadded: v0.5.8
8611cb0ef41Sopenharmony_ci-->
8621cb0ef41Sopenharmony_ci
8631cb0ef41Sopenharmony_ci* `options` {zlib options}
8641cb0ef41Sopenharmony_ci
8651cb0ef41Sopenharmony_ciCreates and returns a new [`InflateRaw`][] object.
8661cb0ef41Sopenharmony_ci
8671cb0ef41Sopenharmony_ci## `zlib.createUnzip([options])`
8681cb0ef41Sopenharmony_ci
8691cb0ef41Sopenharmony_ci<!-- YAML
8701cb0ef41Sopenharmony_ciadded: v0.5.8
8711cb0ef41Sopenharmony_ci-->
8721cb0ef41Sopenharmony_ci
8731cb0ef41Sopenharmony_ci* `options` {zlib options}
8741cb0ef41Sopenharmony_ci
8751cb0ef41Sopenharmony_ciCreates and returns a new [`Unzip`][] object.
8761cb0ef41Sopenharmony_ci
8771cb0ef41Sopenharmony_ci## Convenience methods
8781cb0ef41Sopenharmony_ci
8791cb0ef41Sopenharmony_ci<!--type=misc-->
8801cb0ef41Sopenharmony_ci
8811cb0ef41Sopenharmony_ciAll of these take a [`Buffer`][], [`TypedArray`][], [`DataView`][],
8821cb0ef41Sopenharmony_ci[`ArrayBuffer`][] or string as the first argument, an optional second argument
8831cb0ef41Sopenharmony_cito supply options to the `zlib` classes and will call the supplied callback
8841cb0ef41Sopenharmony_ciwith `callback(error, result)`.
8851cb0ef41Sopenharmony_ci
8861cb0ef41Sopenharmony_ciEvery method has a `*Sync` counterpart, which accept the same arguments, but
8871cb0ef41Sopenharmony_ciwithout a callback.
8881cb0ef41Sopenharmony_ci
8891cb0ef41Sopenharmony_ci### `zlib.brotliCompress(buffer[, options], callback)`
8901cb0ef41Sopenharmony_ci
8911cb0ef41Sopenharmony_ci<!-- YAML
8921cb0ef41Sopenharmony_ciadded:
8931cb0ef41Sopenharmony_ci - v11.7.0
8941cb0ef41Sopenharmony_ci - v10.16.0
8951cb0ef41Sopenharmony_ci-->
8961cb0ef41Sopenharmony_ci
8971cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
8981cb0ef41Sopenharmony_ci* `options` {brotli options}
8991cb0ef41Sopenharmony_ci* `callback` {Function}
9001cb0ef41Sopenharmony_ci
9011cb0ef41Sopenharmony_ci### `zlib.brotliCompressSync(buffer[, options])`
9021cb0ef41Sopenharmony_ci
9031cb0ef41Sopenharmony_ci<!-- YAML
9041cb0ef41Sopenharmony_ciadded:
9051cb0ef41Sopenharmony_ci - v11.7.0
9061cb0ef41Sopenharmony_ci - v10.16.0
9071cb0ef41Sopenharmony_ci-->
9081cb0ef41Sopenharmony_ci
9091cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
9101cb0ef41Sopenharmony_ci* `options` {brotli options}
9111cb0ef41Sopenharmony_ci
9121cb0ef41Sopenharmony_ciCompress a chunk of data with [`BrotliCompress`][].
9131cb0ef41Sopenharmony_ci
9141cb0ef41Sopenharmony_ci### `zlib.brotliDecompress(buffer[, options], callback)`
9151cb0ef41Sopenharmony_ci
9161cb0ef41Sopenharmony_ci<!-- YAML
9171cb0ef41Sopenharmony_ciadded:
9181cb0ef41Sopenharmony_ci - v11.7.0
9191cb0ef41Sopenharmony_ci - v10.16.0
9201cb0ef41Sopenharmony_ci-->
9211cb0ef41Sopenharmony_ci
9221cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
9231cb0ef41Sopenharmony_ci* `options` {brotli options}
9241cb0ef41Sopenharmony_ci* `callback` {Function}
9251cb0ef41Sopenharmony_ci
9261cb0ef41Sopenharmony_ci### `zlib.brotliDecompressSync(buffer[, options])`
9271cb0ef41Sopenharmony_ci
9281cb0ef41Sopenharmony_ci<!-- YAML
9291cb0ef41Sopenharmony_ciadded:
9301cb0ef41Sopenharmony_ci - v11.7.0
9311cb0ef41Sopenharmony_ci - v10.16.0
9321cb0ef41Sopenharmony_ci-->
9331cb0ef41Sopenharmony_ci
9341cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
9351cb0ef41Sopenharmony_ci* `options` {brotli options}
9361cb0ef41Sopenharmony_ci
9371cb0ef41Sopenharmony_ciDecompress a chunk of data with [`BrotliDecompress`][].
9381cb0ef41Sopenharmony_ci
9391cb0ef41Sopenharmony_ci### `zlib.deflate(buffer[, options], callback)`
9401cb0ef41Sopenharmony_ci
9411cb0ef41Sopenharmony_ci<!-- YAML
9421cb0ef41Sopenharmony_ciadded: v0.6.0
9431cb0ef41Sopenharmony_cichanges:
9441cb0ef41Sopenharmony_ci  - version: v9.4.0
9451cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
9461cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `ArrayBuffer`.
9471cb0ef41Sopenharmony_ci  - version: v8.0.0
9481cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
9491cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
9501cb0ef41Sopenharmony_ci  - version: v8.0.0
9511cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
9521cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
9531cb0ef41Sopenharmony_ci-->
9541cb0ef41Sopenharmony_ci
9551cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
9561cb0ef41Sopenharmony_ci* `options` {zlib options}
9571cb0ef41Sopenharmony_ci* `callback` {Function}
9581cb0ef41Sopenharmony_ci
9591cb0ef41Sopenharmony_ci### `zlib.deflateSync(buffer[, options])`
9601cb0ef41Sopenharmony_ci
9611cb0ef41Sopenharmony_ci<!-- YAML
9621cb0ef41Sopenharmony_ciadded: v0.11.12
9631cb0ef41Sopenharmony_cichanges:
9641cb0ef41Sopenharmony_ci  - version: v9.4.0
9651cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
9661cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `ArrayBuffer`.
9671cb0ef41Sopenharmony_ci  - version: v8.0.0
9681cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
9691cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
9701cb0ef41Sopenharmony_ci  - version: v8.0.0
9711cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
9721cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
9731cb0ef41Sopenharmony_ci-->
9741cb0ef41Sopenharmony_ci
9751cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
9761cb0ef41Sopenharmony_ci* `options` {zlib options}
9771cb0ef41Sopenharmony_ci
9781cb0ef41Sopenharmony_ciCompress a chunk of data with [`Deflate`][].
9791cb0ef41Sopenharmony_ci
9801cb0ef41Sopenharmony_ci### `zlib.deflateRaw(buffer[, options], callback)`
9811cb0ef41Sopenharmony_ci
9821cb0ef41Sopenharmony_ci<!-- YAML
9831cb0ef41Sopenharmony_ciadded: v0.6.0
9841cb0ef41Sopenharmony_cichanges:
9851cb0ef41Sopenharmony_ci  - version: v8.0.0
9861cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
9871cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
9881cb0ef41Sopenharmony_ci  - version: v8.0.0
9891cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
9901cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
9911cb0ef41Sopenharmony_ci-->
9921cb0ef41Sopenharmony_ci
9931cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
9941cb0ef41Sopenharmony_ci* `options` {zlib options}
9951cb0ef41Sopenharmony_ci* `callback` {Function}
9961cb0ef41Sopenharmony_ci
9971cb0ef41Sopenharmony_ci### `zlib.deflateRawSync(buffer[, options])`
9981cb0ef41Sopenharmony_ci
9991cb0ef41Sopenharmony_ci<!-- YAML
10001cb0ef41Sopenharmony_ciadded: v0.11.12
10011cb0ef41Sopenharmony_cichanges:
10021cb0ef41Sopenharmony_ci  - version: v9.4.0
10031cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
10041cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `ArrayBuffer`.
10051cb0ef41Sopenharmony_ci  - version: v8.0.0
10061cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
10071cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
10081cb0ef41Sopenharmony_ci  - version: v8.0.0
10091cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
10101cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
10111cb0ef41Sopenharmony_ci-->
10121cb0ef41Sopenharmony_ci
10131cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
10141cb0ef41Sopenharmony_ci* `options` {zlib options}
10151cb0ef41Sopenharmony_ci
10161cb0ef41Sopenharmony_ciCompress a chunk of data with [`DeflateRaw`][].
10171cb0ef41Sopenharmony_ci
10181cb0ef41Sopenharmony_ci### `zlib.gunzip(buffer[, options], callback)`
10191cb0ef41Sopenharmony_ci
10201cb0ef41Sopenharmony_ci<!-- YAML
10211cb0ef41Sopenharmony_ciadded: v0.6.0
10221cb0ef41Sopenharmony_cichanges:
10231cb0ef41Sopenharmony_ci  - version: v9.4.0
10241cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
10251cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `ArrayBuffer`.
10261cb0ef41Sopenharmony_ci  - version: v8.0.0
10271cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
10281cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
10291cb0ef41Sopenharmony_ci  - version: v8.0.0
10301cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
10311cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
10321cb0ef41Sopenharmony_ci-->
10331cb0ef41Sopenharmony_ci
10341cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
10351cb0ef41Sopenharmony_ci* `options` {zlib options}
10361cb0ef41Sopenharmony_ci* `callback` {Function}
10371cb0ef41Sopenharmony_ci
10381cb0ef41Sopenharmony_ci### `zlib.gunzipSync(buffer[, options])`
10391cb0ef41Sopenharmony_ci
10401cb0ef41Sopenharmony_ci<!-- YAML
10411cb0ef41Sopenharmony_ciadded: v0.11.12
10421cb0ef41Sopenharmony_cichanges:
10431cb0ef41Sopenharmony_ci  - version: v9.4.0
10441cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
10451cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `ArrayBuffer`.
10461cb0ef41Sopenharmony_ci  - version: v8.0.0
10471cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
10481cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
10491cb0ef41Sopenharmony_ci  - version: v8.0.0
10501cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
10511cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
10521cb0ef41Sopenharmony_ci-->
10531cb0ef41Sopenharmony_ci
10541cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
10551cb0ef41Sopenharmony_ci* `options` {zlib options}
10561cb0ef41Sopenharmony_ci
10571cb0ef41Sopenharmony_ciDecompress a chunk of data with [`Gunzip`][].
10581cb0ef41Sopenharmony_ci
10591cb0ef41Sopenharmony_ci### `zlib.gzip(buffer[, options], callback)`
10601cb0ef41Sopenharmony_ci
10611cb0ef41Sopenharmony_ci<!-- YAML
10621cb0ef41Sopenharmony_ciadded: v0.6.0
10631cb0ef41Sopenharmony_cichanges:
10641cb0ef41Sopenharmony_ci  - version: v9.4.0
10651cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
10661cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `ArrayBuffer`.
10671cb0ef41Sopenharmony_ci  - version: v8.0.0
10681cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
10691cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
10701cb0ef41Sopenharmony_ci  - version: v8.0.0
10711cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
10721cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
10731cb0ef41Sopenharmony_ci-->
10741cb0ef41Sopenharmony_ci
10751cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
10761cb0ef41Sopenharmony_ci* `options` {zlib options}
10771cb0ef41Sopenharmony_ci* `callback` {Function}
10781cb0ef41Sopenharmony_ci
10791cb0ef41Sopenharmony_ci### `zlib.gzipSync(buffer[, options])`
10801cb0ef41Sopenharmony_ci
10811cb0ef41Sopenharmony_ci<!-- YAML
10821cb0ef41Sopenharmony_ciadded: v0.11.12
10831cb0ef41Sopenharmony_cichanges:
10841cb0ef41Sopenharmony_ci  - version: v9.4.0
10851cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
10861cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `ArrayBuffer`.
10871cb0ef41Sopenharmony_ci  - version: v8.0.0
10881cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
10891cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
10901cb0ef41Sopenharmony_ci  - version: v8.0.0
10911cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
10921cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
10931cb0ef41Sopenharmony_ci-->
10941cb0ef41Sopenharmony_ci
10951cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
10961cb0ef41Sopenharmony_ci* `options` {zlib options}
10971cb0ef41Sopenharmony_ci
10981cb0ef41Sopenharmony_ciCompress a chunk of data with [`Gzip`][].
10991cb0ef41Sopenharmony_ci
11001cb0ef41Sopenharmony_ci### `zlib.inflate(buffer[, options], callback)`
11011cb0ef41Sopenharmony_ci
11021cb0ef41Sopenharmony_ci<!-- YAML
11031cb0ef41Sopenharmony_ciadded: v0.6.0
11041cb0ef41Sopenharmony_cichanges:
11051cb0ef41Sopenharmony_ci  - version: v9.4.0
11061cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
11071cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `ArrayBuffer`.
11081cb0ef41Sopenharmony_ci  - version: v8.0.0
11091cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
11101cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
11111cb0ef41Sopenharmony_ci  - version: v8.0.0
11121cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
11131cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
11141cb0ef41Sopenharmony_ci-->
11151cb0ef41Sopenharmony_ci
11161cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
11171cb0ef41Sopenharmony_ci* `options` {zlib options}
11181cb0ef41Sopenharmony_ci* `callback` {Function}
11191cb0ef41Sopenharmony_ci
11201cb0ef41Sopenharmony_ci### `zlib.inflateSync(buffer[, options])`
11211cb0ef41Sopenharmony_ci
11221cb0ef41Sopenharmony_ci<!-- YAML
11231cb0ef41Sopenharmony_ciadded: v0.11.12
11241cb0ef41Sopenharmony_cichanges:
11251cb0ef41Sopenharmony_ci  - version: v9.4.0
11261cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
11271cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `ArrayBuffer`.
11281cb0ef41Sopenharmony_ci  - version: v8.0.0
11291cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
11301cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
11311cb0ef41Sopenharmony_ci  - version: v8.0.0
11321cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
11331cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
11341cb0ef41Sopenharmony_ci-->
11351cb0ef41Sopenharmony_ci
11361cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
11371cb0ef41Sopenharmony_ci* `options` {zlib options}
11381cb0ef41Sopenharmony_ci
11391cb0ef41Sopenharmony_ciDecompress a chunk of data with [`Inflate`][].
11401cb0ef41Sopenharmony_ci
11411cb0ef41Sopenharmony_ci### `zlib.inflateRaw(buffer[, options], callback)`
11421cb0ef41Sopenharmony_ci
11431cb0ef41Sopenharmony_ci<!-- YAML
11441cb0ef41Sopenharmony_ciadded: v0.6.0
11451cb0ef41Sopenharmony_cichanges:
11461cb0ef41Sopenharmony_ci  - version: v9.4.0
11471cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
11481cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `ArrayBuffer`.
11491cb0ef41Sopenharmony_ci  - version: v8.0.0
11501cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
11511cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
11521cb0ef41Sopenharmony_ci  - version: v8.0.0
11531cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
11541cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
11551cb0ef41Sopenharmony_ci-->
11561cb0ef41Sopenharmony_ci
11571cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
11581cb0ef41Sopenharmony_ci* `options` {zlib options}
11591cb0ef41Sopenharmony_ci* `callback` {Function}
11601cb0ef41Sopenharmony_ci
11611cb0ef41Sopenharmony_ci### `zlib.inflateRawSync(buffer[, options])`
11621cb0ef41Sopenharmony_ci
11631cb0ef41Sopenharmony_ci<!-- YAML
11641cb0ef41Sopenharmony_ciadded: v0.11.12
11651cb0ef41Sopenharmony_cichanges:
11661cb0ef41Sopenharmony_ci  - version: v9.4.0
11671cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
11681cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `ArrayBuffer`.
11691cb0ef41Sopenharmony_ci  - version: v8.0.0
11701cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
11711cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
11721cb0ef41Sopenharmony_ci  - version: v8.0.0
11731cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
11741cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
11751cb0ef41Sopenharmony_ci-->
11761cb0ef41Sopenharmony_ci
11771cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
11781cb0ef41Sopenharmony_ci* `options` {zlib options}
11791cb0ef41Sopenharmony_ci
11801cb0ef41Sopenharmony_ciDecompress a chunk of data with [`InflateRaw`][].
11811cb0ef41Sopenharmony_ci
11821cb0ef41Sopenharmony_ci### `zlib.unzip(buffer[, options], callback)`
11831cb0ef41Sopenharmony_ci
11841cb0ef41Sopenharmony_ci<!-- YAML
11851cb0ef41Sopenharmony_ciadded: v0.6.0
11861cb0ef41Sopenharmony_cichanges:
11871cb0ef41Sopenharmony_ci  - version: v9.4.0
11881cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
11891cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `ArrayBuffer`.
11901cb0ef41Sopenharmony_ci  - version: v8.0.0
11911cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
11921cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
11931cb0ef41Sopenharmony_ci  - version: v8.0.0
11941cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
11951cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
11961cb0ef41Sopenharmony_ci-->
11971cb0ef41Sopenharmony_ci
11981cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
11991cb0ef41Sopenharmony_ci* `options` {zlib options}
12001cb0ef41Sopenharmony_ci* `callback` {Function}
12011cb0ef41Sopenharmony_ci
12021cb0ef41Sopenharmony_ci### `zlib.unzipSync(buffer[, options])`
12031cb0ef41Sopenharmony_ci
12041cb0ef41Sopenharmony_ci<!-- YAML
12051cb0ef41Sopenharmony_ciadded: v0.11.12
12061cb0ef41Sopenharmony_cichanges:
12071cb0ef41Sopenharmony_ci  - version: v9.4.0
12081cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/16042
12091cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `ArrayBuffer`.
12101cb0ef41Sopenharmony_ci  - version: v8.0.0
12111cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12223
12121cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be any `TypedArray` or `DataView`.
12131cb0ef41Sopenharmony_ci  - version: v8.0.0
12141cb0ef41Sopenharmony_ci    pr-url: https://github.com/nodejs/node/pull/12001
12151cb0ef41Sopenharmony_ci    description: The `buffer` parameter can be an `Uint8Array` now.
12161cb0ef41Sopenharmony_ci-->
12171cb0ef41Sopenharmony_ci
12181cb0ef41Sopenharmony_ci* `buffer` {Buffer|TypedArray|DataView|ArrayBuffer|string}
12191cb0ef41Sopenharmony_ci* `options` {zlib options}
12201cb0ef41Sopenharmony_ci
12211cb0ef41Sopenharmony_ciDecompress a chunk of data with [`Unzip`][].
12221cb0ef41Sopenharmony_ci
12231cb0ef41Sopenharmony_ci[Brotli parameters]: #brotli-constants
12241cb0ef41Sopenharmony_ci[Memory usage tuning]: #memory-usage-tuning
12251cb0ef41Sopenharmony_ci[RFC 7932]: https://www.rfc-editor.org/rfc/rfc7932.txt
12261cb0ef41Sopenharmony_ci[Streams API]: stream.md
12271cb0ef41Sopenharmony_ci[`.flush()`]: #zlibflushkind-callback
12281cb0ef41Sopenharmony_ci[`Accept-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3
12291cb0ef41Sopenharmony_ci[`ArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer
12301cb0ef41Sopenharmony_ci[`BrotliCompress`]: #class-zlibbrotlicompress
12311cb0ef41Sopenharmony_ci[`BrotliDecompress`]: #class-zlibbrotlidecompress
12321cb0ef41Sopenharmony_ci[`Buffer`]: buffer.md#class-buffer
12331cb0ef41Sopenharmony_ci[`Content-Encoding`]: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11
12341cb0ef41Sopenharmony_ci[`DataView`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView
12351cb0ef41Sopenharmony_ci[`DeflateRaw`]: #class-zlibdeflateraw
12361cb0ef41Sopenharmony_ci[`Deflate`]: #class-zlibdeflate
12371cb0ef41Sopenharmony_ci[`Gunzip`]: #class-zlibgunzip
12381cb0ef41Sopenharmony_ci[`Gzip`]: #class-zlibgzip
12391cb0ef41Sopenharmony_ci[`InflateRaw`]: #class-zlibinflateraw
12401cb0ef41Sopenharmony_ci[`Inflate`]: #class-zlibinflate
12411cb0ef41Sopenharmony_ci[`TypedArray`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
12421cb0ef41Sopenharmony_ci[`Unzip`]: #class-zlibunzip
12431cb0ef41Sopenharmony_ci[`buffer.kMaxLength`]: buffer.md#bufferkmaxlength
12441cb0ef41Sopenharmony_ci[`deflateInit2` and `inflateInit2`]: https://zlib.net/manual.html#Advanced
12451cb0ef41Sopenharmony_ci[`stream.Transform`]: stream.md#class-streamtransform
12461cb0ef41Sopenharmony_ci[`zlib.bytesWritten`]: #zlibbyteswritten
12471cb0ef41Sopenharmony_ci[convenience methods]: #convenience-methods
12481cb0ef41Sopenharmony_ci[zlib documentation]: https://zlib.net/manual.html#Constants
12491cb0ef41Sopenharmony_ci[zlib.createGzip example]: #zlib
1250