• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!DOCTYPE html>
2<html lang="en">
3<head>
4  <meta charset="utf-8">
5  <meta name="viewport" content="width=device-width">
6  <meta name="nodejs.org:node-version" content="v14.20.1">
7  <title>Zlib | Node.js v14.20.1 Documentation</title>
8  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback">
9  <link rel="stylesheet" href="assets/style.css">
10  <link rel="stylesheet" href="assets/hljs.css">
11  <link rel="canonical" href="https://nodejs.org/api/zlib.html">
12</head>
13<body class="alt apidoc" id="api-section-zlib">
14  <div id="content" class="clearfix">
15    <div id="column2" class="interior">
16      <div id="intro" class="interior">
17        <a href="/" title="Go back to the home page">
18          Node.js
19        </a>
20      </div>
21      <ul>
22<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
23<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
24</ul>
25<hr class="line">
26<ul>
27<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
28<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
29<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
30<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
31<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
32<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
33<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
34<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
35<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
36<li><a href="console.html" class="nav-console">Console</a></li>
37<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
38<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
39<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
40<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
41<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
42<li><a href="dns.html" class="nav-dns">DNS</a></li>
43<li><a href="domain.html" class="nav-domain">Domain</a></li>
44<li><a href="errors.html" class="nav-errors">Errors</a></li>
45<li><a href="events.html" class="nav-events">Events</a></li>
46<li><a href="fs.html" class="nav-fs">File system</a></li>
47<li><a href="globals.html" class="nav-globals">Globals</a></li>
48<li><a href="http.html" class="nav-http">HTTP</a></li>
49<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
50<li><a href="https.html" class="nav-https">HTTPS</a></li>
51<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
52<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
53<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
54<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
55<li><a href="module.html" class="nav-module">Modules: <code>module</code> API</a></li>
56<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
57<li><a href="net.html" class="nav-net">Net</a></li>
58<li><a href="os.html" class="nav-os">OS</a></li>
59<li><a href="path.html" class="nav-path">Path</a></li>
60<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
61<li><a href="policy.html" class="nav-policy">Policies</a></li>
62<li><a href="process.html" class="nav-process">Process</a></li>
63<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
64<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
65<li><a href="readline.html" class="nav-readline">Readline</a></li>
66<li><a href="repl.html" class="nav-repl">REPL</a></li>
67<li><a href="report.html" class="nav-report">Report</a></li>
68<li><a href="stream.html" class="nav-stream">Stream</a></li>
69<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
70<li><a href="timers.html" class="nav-timers">Timers</a></li>
71<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
72<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
73<li><a href="tty.html" class="nav-tty">TTY</a></li>
74<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
75<li><a href="url.html" class="nav-url">URL</a></li>
76<li><a href="util.html" class="nav-util">Utilities</a></li>
77<li><a href="v8.html" class="nav-v8">V8</a></li>
78<li><a href="vm.html" class="nav-vm">VM</a></li>
79<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
80<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
81<li><a href="zlib.html" class="nav-zlib active">Zlib</a></li>
82</ul>
83<hr class="line">
84<ul>
85<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
86</ul>
87    </div>
88
89    <div id="column1" data-id="zlib" class="interior">
90      <header>
91        <div class="header-container">
92          <h1>Node.js v14.20.1 documentation</h1>
93          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
94            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
95              <path fill="none" d="M0 0h24v24H0z" />
96              <path d="M11.1 12.08c-2.33-4.51-.5-8.48.53-10.07C6.27 2.2 1.98 6.59 1.98 12c0 .14.02.28.02.42.62-.27 1.29-.42 2-.42 1.66 0 3.18.83 4.1 2.15A4.01 4.01 0 0111 18c0 1.52-.87 2.83-2.12 3.51.98.32 2.03.5 3.11.5 3.5 0 6.58-1.8 8.37-4.52-2.36.23-6.98-.97-9.26-5.41z"/>
97              <path d="M7 16h-.18C6.4 14.84 5.3 14 4 14c-1.66 0-3 1.34-3 3s1.34 3 3 3h3c1.1 0 2-.9 2-2s-.9-2-2-2z"/>
98            </svg>
99            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
100              <path d="M0 0h24v24H0z" fill="none" />
101              <path d="M6.76 4.84l-1.8-1.79-1.41 1.41 1.79 1.79 1.42-1.41zM4 10.5H1v2h3v-2zm9-9.95h-2V3.5h2V.55zm7.45 3.91l-1.41-1.41-1.79 1.79 1.41 1.41 1.79-1.79zm-3.21 13.7l1.79 1.8 1.41-1.41-1.8-1.79-1.4 1.4zM20 10.5v2h3v-2h-3zm-8-5c-3.31 0-6 2.69-6 6s2.69 6 6 6 6-2.69 6-6-2.69-6-6-6zm-1 16.95h2V19.5h-2v2.95zm-7.45-3.91l1.41 1.41 1.79-1.8-1.41-1.41-1.79 1.8z"/>
102            </svg>
103          </button>
104        </div>
105        <div id="gtoc">
106          <ul>
107            <li>
108              <a href="index.html">Index</a>
109            </li>
110            <li>
111              <a href="all.html">View on single page</a>
112            </li>
113            <li>
114              <a href="zlib.json">View as JSON</a>
115            </li>
116
117    <li class="version-picker">
118      <a href="#">View another version <span>&#x25bc;</span></a>
119      <ol class="version-picker"><li><a href="https://nodejs.org/docs/latest-v18.x/api/zlib.html">18.x</a></li>
120<li><a href="https://nodejs.org/docs/latest-v17.x/api/zlib.html">17.x</a></li>
121<li><a href="https://nodejs.org/docs/latest-v16.x/api/zlib.html">16.x <b>LTS</b></a></li>
122<li><a href="https://nodejs.org/docs/latest-v15.x/api/zlib.html">15.x</a></li>
123<li><a href="https://nodejs.org/docs/latest-v14.x/api/zlib.html">14.x <b>LTS</b></a></li>
124<li><a href="https://nodejs.org/docs/latest-v13.x/api/zlib.html">13.x</a></li>
125<li><a href="https://nodejs.org/docs/latest-v12.x/api/zlib.html">12.x <b>LTS</b></a></li>
126<li><a href="https://nodejs.org/docs/latest-v11.x/api/zlib.html">11.x</a></li>
127<li><a href="https://nodejs.org/docs/latest-v10.x/api/zlib.html">10.x</a></li>
128<li><a href="https://nodejs.org/docs/latest-v9.x/api/zlib.html">9.x</a></li>
129<li><a href="https://nodejs.org/docs/latest-v8.x/api/zlib.html">8.x</a></li>
130<li><a href="https://nodejs.org/docs/latest-v7.x/api/zlib.html">7.x</a></li>
131<li><a href="https://nodejs.org/docs/latest-v6.x/api/zlib.html">6.x</a></li>
132<li><a href="https://nodejs.org/docs/latest-v5.x/api/zlib.html">5.x</a></li>
133<li><a href="https://nodejs.org/docs/latest-v4.x/api/zlib.html">4.x</a></li>
134<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/zlib.html">0.12.x</a></li>
135<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/zlib.html">0.10.x</a></li></ol>
136    </li>
137
138            <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/master/doc/api/zlib.md">Edit on GitHub</a></li>
139          </ul>
140        </div>
141        <hr>
142      </header>
143
144      <details id="toc" open><summary>Table of contents</summary><ul>
145<li><span class="stability_2"><a href="#zlib_zlib">Zlib</a></span>
146<ul>
147<li><a href="#zlib_threadpool_usage_and_performance_considerations">Threadpool usage and performance considerations</a></li>
148<li><a href="#zlib_compressing_http_requests_and_responses">Compressing HTTP requests and responses</a></li>
149<li><a href="#zlib_memory_usage_tuning">Memory usage tuning</a>
150<ul>
151<li><a href="#zlib_for_zlib_based_streams">For zlib-based streams</a></li>
152<li><a href="#zlib_for_brotli_based_streams">For Brotli-based streams</a></li>
153</ul>
154</li>
155<li><a href="#zlib_flushing">Flushing</a></li>
156<li><a href="#zlib_constants">Constants</a>
157<ul>
158<li><a href="#zlib_zlib_constants">zlib constants</a></li>
159<li><a href="#zlib_brotli_constants">Brotli constants</a>
160<ul>
161<li><a href="#zlib_flush_operations">Flush operations</a></li>
162<li><a href="#zlib_compressor_options">Compressor options</a></li>
163<li><a href="#zlib_decompressor_options">Decompressor options</a></li>
164</ul>
165</li>
166</ul>
167</li>
168<li><a href="#zlib_class_options">Class: <code>Options</code></a></li>
169<li><a href="#zlib_class_brotlioptions">Class: <code>BrotliOptions</code></a></li>
170<li><a href="#zlib_class_zlib_brotlicompress">Class: <code>zlib.BrotliCompress</code></a></li>
171<li><a href="#zlib_class_zlib_brotlidecompress">Class: <code>zlib.BrotliDecompress</code></a></li>
172<li><a href="#zlib_class_zlib_deflate">Class: <code>zlib.Deflate</code></a></li>
173<li><a href="#zlib_class_zlib_deflateraw">Class: <code>zlib.DeflateRaw</code></a></li>
174<li><a href="#zlib_class_zlib_gunzip">Class: <code>zlib.Gunzip</code></a></li>
175<li><a href="#zlib_class_zlib_gzip">Class: <code>zlib.Gzip</code></a></li>
176<li><a href="#zlib_class_zlib_inflate">Class: <code>zlib.Inflate</code></a></li>
177<li><a href="#zlib_class_zlib_inflateraw">Class: <code>zlib.InflateRaw</code></a></li>
178<li><a href="#zlib_class_zlib_unzip">Class: <code>zlib.Unzip</code></a></li>
179<li><a href="#zlib_class_zlib_zlibbase">Class: <code>zlib.ZlibBase</code></a>
180<ul>
181<li><span class="stability_0"><a href="#zlib_zlib_bytesread"><code>zlib.bytesRead</code></a></span></li>
182<li><a href="#zlib_zlib_byteswritten"><code>zlib.bytesWritten</code></a></li>
183<li><a href="#zlib_zlib_close_callback"><code>zlib.close([callback])</code></a></li>
184<li><a href="#zlib_zlib_flush_kind_callback"><code>zlib.flush([kind, ]callback)</code></a></li>
185<li><a href="#zlib_zlib_params_level_strategy_callback"><code>zlib.params(level, strategy, callback)</code></a></li>
186<li><a href="#zlib_zlib_reset"><code>zlib.reset()</code></a></li>
187</ul>
188</li>
189<li><a href="#zlib_zlib_constants_1"><code>zlib.constants</code></a></li>
190<li><a href="#zlib_zlib_createbrotlicompress_options"><code>zlib.createBrotliCompress([options])</code></a></li>
191<li><a href="#zlib_zlib_createbrotlidecompress_options"><code>zlib.createBrotliDecompress([options])</code></a></li>
192<li><a href="#zlib_zlib_createdeflate_options"><code>zlib.createDeflate([options])</code></a></li>
193<li><a href="#zlib_zlib_createdeflateraw_options"><code>zlib.createDeflateRaw([options])</code></a></li>
194<li><a href="#zlib_zlib_creategunzip_options"><code>zlib.createGunzip([options])</code></a></li>
195<li><a href="#zlib_zlib_creategzip_options"><code>zlib.createGzip([options])</code></a></li>
196<li><a href="#zlib_zlib_createinflate_options"><code>zlib.createInflate([options])</code></a></li>
197<li><a href="#zlib_zlib_createinflateraw_options"><code>zlib.createInflateRaw([options])</code></a></li>
198<li><a href="#zlib_zlib_createunzip_options"><code>zlib.createUnzip([options])</code></a></li>
199<li><a href="#zlib_convenience_methods">Convenience methods</a>
200<ul>
201<li><a href="#zlib_zlib_brotlicompress_buffer_options_callback"><code>zlib.brotliCompress(buffer[, options], callback)</code></a></li>
202<li><a href="#zlib_zlib_brotlicompresssync_buffer_options"><code>zlib.brotliCompressSync(buffer[, options])</code></a></li>
203<li><a href="#zlib_zlib_brotlidecompress_buffer_options_callback"><code>zlib.brotliDecompress(buffer[, options], callback)</code></a></li>
204<li><a href="#zlib_zlib_brotlidecompresssync_buffer_options"><code>zlib.brotliDecompressSync(buffer[, options])</code></a></li>
205<li><a href="#zlib_zlib_deflate_buffer_options_callback"><code>zlib.deflate(buffer[, options], callback)</code></a></li>
206<li><a href="#zlib_zlib_deflatesync_buffer_options"><code>zlib.deflateSync(buffer[, options])</code></a></li>
207<li><a href="#zlib_zlib_deflateraw_buffer_options_callback"><code>zlib.deflateRaw(buffer[, options], callback)</code></a></li>
208<li><a href="#zlib_zlib_deflaterawsync_buffer_options"><code>zlib.deflateRawSync(buffer[, options])</code></a></li>
209<li><a href="#zlib_zlib_gunzip_buffer_options_callback"><code>zlib.gunzip(buffer[, options], callback)</code></a></li>
210<li><a href="#zlib_zlib_gunzipsync_buffer_options"><code>zlib.gunzipSync(buffer[, options])</code></a></li>
211<li><a href="#zlib_zlib_gzip_buffer_options_callback"><code>zlib.gzip(buffer[, options], callback)</code></a></li>
212<li><a href="#zlib_zlib_gzipsync_buffer_options"><code>zlib.gzipSync(buffer[, options])</code></a></li>
213<li><a href="#zlib_zlib_inflate_buffer_options_callback"><code>zlib.inflate(buffer[, options], callback)</code></a></li>
214<li><a href="#zlib_zlib_inflatesync_buffer_options"><code>zlib.inflateSync(buffer[, options])</code></a></li>
215<li><a href="#zlib_zlib_inflateraw_buffer_options_callback"><code>zlib.inflateRaw(buffer[, options], callback)</code></a></li>
216<li><a href="#zlib_zlib_inflaterawsync_buffer_options"><code>zlib.inflateRawSync(buffer[, options])</code></a></li>
217<li><a href="#zlib_zlib_unzip_buffer_options_callback"><code>zlib.unzip(buffer[, options], callback)</code></a></li>
218<li><a href="#zlib_zlib_unzipsync_buffer_options"><code>zlib.unzipSync(buffer[, options])</code></a></li>
219</ul>
220</li>
221</ul>
222</li>
223</ul></details>
224
225      <div id="apicontent">
226        <h2>Zlib<span><a class="mark" href="#zlib_zlib" id="zlib_zlib">#</a></span></h2>
227
228<p></p><div class="api_stability api_stability_2"><a href="documentation.html#documentation_stability_index">Stability: 2</a> - Stable</div><p></p>
229<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v14.20.1/lib/zlib.js">lib/zlib.js</a></p>
230<p>The <code>zlib</code> module provides compression functionality implemented using Gzip,
231Deflate/Inflate, and Brotli.</p>
232<p>To access it:</p>
233<pre><code class="language-js"><span class="hljs-keyword">const</span> zlib = <span class="hljs-built_in">require</span>(<span class="hljs-string">'zlib'</span>);</code></pre>
234<p>Compression and decompression are built around the Node.js <a href="stream.html">Streams API</a>.</p>
235<p>Compressing or decompressing a stream (such as a file) can be accomplished by
236piping the source stream through a <code>zlib</code> <code>Transform</code> stream into a destination
237stream:</p>
238<pre><code class="language-js"><span class="hljs-keyword">const</span> { createGzip } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'zlib'</span>);
239<span class="hljs-keyword">const</span> { pipeline } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'stream'</span>);
240<span class="hljs-keyword">const</span> {
241  createReadStream,
242  createWriteStream
243} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
244
245<span class="hljs-keyword">const</span> gzip = <span class="hljs-title function_">createGzip</span>();
246<span class="hljs-keyword">const</span> source = <span class="hljs-title function_">createReadStream</span>(<span class="hljs-string">'input.txt'</span>);
247<span class="hljs-keyword">const</span> destination = <span class="hljs-title function_">createWriteStream</span>(<span class="hljs-string">'input.txt.gz'</span>);
248
249<span class="hljs-title function_">pipeline</span>(source, gzip, destination, <span class="hljs-function">(<span class="hljs-params">err</span>) =></span> {
250  <span class="hljs-keyword">if</span> (err) {
251    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
252    process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
253  }
254});
255
256<span class="hljs-comment">// Or, Promisified</span>
257
258<span class="hljs-keyword">const</span> { promisify } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'util'</span>);
259<span class="hljs-keyword">const</span> pipe = <span class="hljs-title function_">promisify</span>(pipeline);
260
261<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">do_gzip</span>(<span class="hljs-params">input, output</span>) {
262  <span class="hljs-keyword">const</span> gzip = <span class="hljs-title function_">createGzip</span>();
263  <span class="hljs-keyword">const</span> source = <span class="hljs-title function_">createReadStream</span>(input);
264  <span class="hljs-keyword">const</span> destination = <span class="hljs-title function_">createWriteStream</span>(output);
265  <span class="hljs-keyword">await</span> <span class="hljs-title function_">pipe</span>(source, gzip, destination);
266}
267
268<span class="hljs-title function_">do_gzip</span>(<span class="hljs-string">'input.txt'</span>, <span class="hljs-string">'input.txt.gz'</span>)
269  .<span class="hljs-title function_">catch</span>(<span class="hljs-function">(<span class="hljs-params">err</span>) =></span> {
270    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
271    process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
272  });</code></pre>
273<p>It is also possible to compress or decompress data in a single step:</p>
274<pre><code class="language-js"><span class="hljs-keyword">const</span> { deflate, unzip } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'zlib'</span>);
275
276<span class="hljs-keyword">const</span> input = <span class="hljs-string">'.................................'</span>;
277<span class="hljs-title function_">deflate</span>(input, <span class="hljs-function">(<span class="hljs-params">err, buffer</span>) =></span> {
278  <span class="hljs-keyword">if</span> (err) {
279    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
280    process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
281  }
282  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(buffer.<span class="hljs-title function_">toString</span>(<span class="hljs-string">'base64'</span>));
283});
284
285<span class="hljs-keyword">const</span> buffer = <span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">from</span>(<span class="hljs-string">'eJzT0yMAAGTvBe8='</span>, <span class="hljs-string">'base64'</span>);
286<span class="hljs-title function_">unzip</span>(buffer, <span class="hljs-function">(<span class="hljs-params">err, buffer</span>) =></span> {
287  <span class="hljs-keyword">if</span> (err) {
288    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
289    process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
290  }
291  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(buffer.<span class="hljs-title function_">toString</span>());
292});
293
294<span class="hljs-comment">// Or, Promisified</span>
295
296<span class="hljs-keyword">const</span> { promisify } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'util'</span>);
297<span class="hljs-keyword">const</span> do_unzip = <span class="hljs-title function_">promisify</span>(unzip);
298
299<span class="hljs-title function_">do_unzip</span>(buffer)
300  .<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">buf</span>) =></span> <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(buf.<span class="hljs-title function_">toString</span>()))
301  .<span class="hljs-title function_">catch</span>(<span class="hljs-function">(<span class="hljs-params">err</span>) =></span> {
302    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
303    process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
304  });</code></pre>
305<section><h3>Threadpool usage and performance considerations<span><a class="mark" href="#zlib_threadpool_usage_and_performance_considerations" id="zlib_threadpool_usage_and_performance_considerations">#</a></span></h3>
306<p>All <code>zlib</code> APIs, except those that are explicitly synchronous, use the Node.js
307internal threadpool. This can lead to surprising effects and performance
308limitations in some applications.</p>
309<p>Creating and using a large number of zlib objects simultaneously can cause
310significant memory fragmentation.</p>
311<pre><code class="language-js"><span class="hljs-keyword">const</span> zlib = <span class="hljs-built_in">require</span>(<span class="hljs-string">'zlib'</span>);
312
313<span class="hljs-keyword">const</span> payload = <span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">from</span>(<span class="hljs-string">'This is some data'</span>);
314
315<span class="hljs-comment">// WARNING: DO NOT DO THIS!</span>
316<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &#x3C; <span class="hljs-number">30000</span>; ++i) {
317  zlib.<span class="hljs-title function_">deflate</span>(payload, <span class="hljs-function">(<span class="hljs-params">err, buffer</span>) =></span> {});
318}</code></pre>
319<p>In the preceding example, 30,000 deflate instances are created concurrently.
320Because of how some operating systems handle memory allocation and
321deallocation, this may lead to to significant memory fragmentation.</p>
322<p>It is strongly recommended that the results of compression
323operations be cached to avoid duplication of effort.</p>
324</section><section><h3>Compressing HTTP requests and responses<span><a class="mark" href="#zlib_compressing_http_requests_and_responses" id="zlib_compressing_http_requests_and_responses">#</a></span></h3>
325<p>The <code>zlib</code> module can be used to implement support for the <code>gzip</code>, <code>deflate</code>
326and <code>br</code> content-encoding mechanisms defined by
327<a href="https://tools.ietf.org/html/rfc7230#section-4.2">HTTP</a>.</p>
328<p>The HTTP <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3"><code>Accept-Encoding</code></a> header is used within an http request to identify
329the compression encodings accepted by the client. The <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.11"><code>Content-Encoding</code></a>
330header is used to identify the compression encodings actually applied to a
331message.</p>
332<p>The examples given below are drastically simplified to show the basic concept.
333Using <code>zlib</code> encoding can be expensive, and the results ought to be cached.
334See <a href="#zlib_memory_usage_tuning">Memory usage tuning</a> for more information on the speed/memory/compression
335tradeoffs involved in <code>zlib</code> usage.</p>
336<pre><code class="language-js"><span class="hljs-comment">// Client request example</span>
337<span class="hljs-keyword">const</span> zlib = <span class="hljs-built_in">require</span>(<span class="hljs-string">'zlib'</span>);
338<span class="hljs-keyword">const</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">'http'</span>);
339<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
340<span class="hljs-keyword">const</span> { pipeline } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'stream'</span>);
341
342<span class="hljs-keyword">const</span> request = http.<span class="hljs-title function_">get</span>({ <span class="hljs-attr">host</span>: <span class="hljs-string">'example.com'</span>,
343                           <span class="hljs-attr">path</span>: <span class="hljs-string">'/'</span>,
344                           <span class="hljs-attr">port</span>: <span class="hljs-number">80</span>,
345                           <span class="hljs-attr">headers</span>: { <span class="hljs-string">'Accept-Encoding'</span>: <span class="hljs-string">'br,gzip,deflate'</span> } });
346request.<span class="hljs-title function_">on</span>(<span class="hljs-string">'response'</span>, <span class="hljs-function">(<span class="hljs-params">response</span>) =></span> {
347  <span class="hljs-keyword">const</span> output = fs.<span class="hljs-title function_">createWriteStream</span>(<span class="hljs-string">'example.com_index.html'</span>);
348
349  <span class="hljs-keyword">const</span> <span class="hljs-title function_">onError</span> = (<span class="hljs-params">err</span>) => {
350    <span class="hljs-keyword">if</span> (err) {
351      <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
352      process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
353    }
354  };
355
356  <span class="hljs-keyword">switch</span> (response.<span class="hljs-property">headers</span>[<span class="hljs-string">'content-encoding'</span>]) {
357    <span class="hljs-keyword">case</span> <span class="hljs-string">'br'</span>:
358      <span class="hljs-title function_">pipeline</span>(response, zlib.<span class="hljs-title function_">createBrotliDecompress</span>(), output, onError);
359      <span class="hljs-keyword">break</span>;
360    <span class="hljs-comment">// Or, just use zlib.createUnzip() to handle both of the following cases:</span>
361    <span class="hljs-keyword">case</span> <span class="hljs-string">'gzip'</span>:
362      <span class="hljs-title function_">pipeline</span>(response, zlib.<span class="hljs-title function_">createGunzip</span>(), output, onError);
363      <span class="hljs-keyword">break</span>;
364    <span class="hljs-keyword">case</span> <span class="hljs-string">'deflate'</span>:
365      <span class="hljs-title function_">pipeline</span>(response, zlib.<span class="hljs-title function_">createInflate</span>(), output, onError);
366      <span class="hljs-keyword">break</span>;
367    <span class="hljs-attr">default</span>:
368      <span class="hljs-title function_">pipeline</span>(response, output, onError);
369      <span class="hljs-keyword">break</span>;
370  }
371});</code></pre>
372<pre><code class="language-js"><span class="hljs-comment">// server example</span>
373<span class="hljs-comment">// Running a gzip operation on every request is quite expensive.</span>
374<span class="hljs-comment">// It would be much more efficient to cache the compressed buffer.</span>
375<span class="hljs-keyword">const</span> zlib = <span class="hljs-built_in">require</span>(<span class="hljs-string">'zlib'</span>);
376<span class="hljs-keyword">const</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">'http'</span>);
377<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'fs'</span>);
378<span class="hljs-keyword">const</span> { pipeline } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'stream'</span>);
379
380http.<span class="hljs-title function_">createServer</span>(<span class="hljs-function">(<span class="hljs-params">request, response</span>) =></span> {
381  <span class="hljs-keyword">const</span> raw = fs.<span class="hljs-title function_">createReadStream</span>(<span class="hljs-string">'index.html'</span>);
382  <span class="hljs-comment">// Store both a compressed and an uncompressed version of the resource.</span>
383  response.<span class="hljs-title function_">setHeader</span>(<span class="hljs-string">'Vary'</span>, <span class="hljs-string">'Accept-Encoding'</span>);
384  <span class="hljs-keyword">let</span> acceptEncoding = request.<span class="hljs-property">headers</span>[<span class="hljs-string">'accept-encoding'</span>];
385  <span class="hljs-keyword">if</span> (!acceptEncoding) {
386    acceptEncoding = <span class="hljs-string">''</span>;
387  }
388
389  <span class="hljs-keyword">const</span> <span class="hljs-title function_">onError</span> = (<span class="hljs-params">err</span>) => {
390    <span class="hljs-keyword">if</span> (err) {
391      <span class="hljs-comment">// If an error occurs, there's not much we can do because</span>
392      <span class="hljs-comment">// the server has already sent the 200 response code and</span>
393      <span class="hljs-comment">// some amount of data has already been sent to the client.</span>
394      <span class="hljs-comment">// The best we can do is terminate the response immediately</span>
395      <span class="hljs-comment">// and log the error.</span>
396      response.<span class="hljs-title function_">end</span>();
397      <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
398    }
399  };
400
401  <span class="hljs-comment">// Note: This is not a conformant accept-encoding parser.</span>
402  <span class="hljs-comment">// See https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3</span>
403  <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/\bdeflate\b/</span>.<span class="hljs-title function_">test</span>(acceptEncoding)) {
404    response.<span class="hljs-title function_">writeHead</span>(<span class="hljs-number">200</span>, { <span class="hljs-string">'Content-Encoding'</span>: <span class="hljs-string">'deflate'</span> });
405    <span class="hljs-title function_">pipeline</span>(raw, zlib.<span class="hljs-title function_">createDeflate</span>(), response, onError);
406  } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/\bgzip\b/</span>.<span class="hljs-title function_">test</span>(acceptEncoding)) {
407    response.<span class="hljs-title function_">writeHead</span>(<span class="hljs-number">200</span>, { <span class="hljs-string">'Content-Encoding'</span>: <span class="hljs-string">'gzip'</span> });
408    <span class="hljs-title function_">pipeline</span>(raw, zlib.<span class="hljs-title function_">createGzip</span>(), response, onError);
409  } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/\bbr\b/</span>.<span class="hljs-title function_">test</span>(acceptEncoding)) {
410    response.<span class="hljs-title function_">writeHead</span>(<span class="hljs-number">200</span>, { <span class="hljs-string">'Content-Encoding'</span>: <span class="hljs-string">'br'</span> });
411    <span class="hljs-title function_">pipeline</span>(raw, zlib.<span class="hljs-title function_">createBrotliCompress</span>(), response, onError);
412  } <span class="hljs-keyword">else</span> {
413    response.<span class="hljs-title function_">writeHead</span>(<span class="hljs-number">200</span>, {});
414    <span class="hljs-title function_">pipeline</span>(raw, response, onError);
415  }
416}).<span class="hljs-title function_">listen</span>(<span class="hljs-number">1337</span>);</code></pre>
417<p>By default, the <code>zlib</code> methods will throw an error when decompressing
418truncated data. However, if it is known that the data is incomplete, or
419the desire is to inspect only the beginning of a compressed file, it is
420possible to suppress the default error handling by changing the flushing
421method that is used to decompress the last chunk of input data:</p>
422<pre><code class="language-js"><span class="hljs-comment">// This is a truncated version of the buffer from the above examples</span>
423<span class="hljs-keyword">const</span> buffer = <span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">from</span>(<span class="hljs-string">'eJzT0yMA'</span>, <span class="hljs-string">'base64'</span>);
424
425zlib.<span class="hljs-title function_">unzip</span>(
426  buffer,
427  <span class="hljs-comment">// For Brotli, the equivalent is zlib.constants.BROTLI_OPERATION_FLUSH.</span>
428  { <span class="hljs-attr">finishFlush</span>: zlib.<span class="hljs-property">constants</span>.<span class="hljs-property">Z_SYNC_FLUSH</span> },
429  <span class="hljs-function">(<span class="hljs-params">err, buffer</span>) =></span> {
430    <span class="hljs-keyword">if</span> (err) {
431      <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
432      process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
433    }
434    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(buffer.<span class="hljs-title function_">toString</span>());
435  });</code></pre>
436<p>This will not change the behavior in other error-throwing situations, e.g.
437when the input data has an invalid format. Using this method, it will not be
438possible to determine whether the input ended prematurely or lacks the
439integrity checks, making it necessary to manually check that the
440decompressed result is valid.</p>
441</section><section><h3>Memory usage tuning<span><a class="mark" href="#zlib_memory_usage_tuning" id="zlib_memory_usage_tuning">#</a></span></h3>
442
443<h4>For zlib-based streams<span><a class="mark" href="#zlib_for_zlib_based_streams" id="zlib_for_zlib_based_streams">#</a></span></h4>
444<p>From <code>zlib/zconf.h</code>, modified for Node.js usage:</p>
445<p>The memory requirements for deflate are (in bytes):</p>
446<!-- eslint-disable semi -->
447<pre><code class="language-js">(<span class="hljs-number">1</span> &#x3C;&#x3C; (windowBits + <span class="hljs-number">2</span>)) + (<span class="hljs-number">1</span> &#x3C;&#x3C; (memLevel + <span class="hljs-number">9</span>))</code></pre>
448<p>That is: 128K for <code>windowBits</code> = 15 + 128K for <code>memLevel</code> = 8
449(default values) plus a few kilobytes for small objects.</p>
450<p>For example, to reduce the default memory requirements from 256K to 128K, the
451options should be set to:</p>
452<pre><code class="language-js"><span class="hljs-keyword">const</span> options = { <span class="hljs-attr">windowBits</span>: <span class="hljs-number">14</span>, <span class="hljs-attr">memLevel</span>: <span class="hljs-number">7</span> };</code></pre>
453<p>This will, however, generally degrade compression.</p>
454<p>The memory requirements for inflate are (in bytes) <code>1 &#x3C;&#x3C; windowBits</code>.
455That is, 32K for <code>windowBits</code> = 15 (default value) plus a few kilobytes
456for small objects.</p>
457<p>This is in addition to a single internal output slab buffer of size
458<code>chunkSize</code>, which defaults to 16K.</p>
459<p>The speed of <code>zlib</code> compression is affected most dramatically by the
460<code>level</code> setting. A higher level will result in better compression, but
461will take longer to complete. A lower level will result in less
462compression, but will be much faster.</p>
463<p>In general, greater memory usage options will mean that Node.js has to make
464fewer calls to <code>zlib</code> because it will be able to process more data on
465each <code>write</code> operation. So, this is another factor that affects the
466speed, at the cost of memory usage.</p>
467<h4>For Brotli-based streams<span><a class="mark" href="#zlib_for_brotli_based_streams" id="zlib_for_brotli_based_streams">#</a></span></h4>
468<p>There are equivalents to the zlib options for Brotli-based streams, although
469these options have different ranges than the zlib ones:</p>
470<ul>
471<li>zlib’s <code>level</code> option matches Brotli’s <code>BROTLI_PARAM_QUALITY</code> option.</li>
472<li>zlib’s <code>windowBits</code> option matches Brotli’s <code>BROTLI_PARAM_LGWIN</code> option.</li>
473</ul>
474<p>See <a href="#zlib_brotli_constants">below</a> for more details on Brotli-specific options.</p>
475</section><section><h3>Flushing<span><a class="mark" href="#zlib_flushing" id="zlib_flushing">#</a></span></h3>
476<p>Calling <a href="#zlib_zlib_flush_kind_callback"><code>.flush()</code></a> on a compression stream will make <code>zlib</code> return as much
477output as currently possible. This may come at the cost of degraded compression
478quality, but can be useful when data needs to be available as soon as possible.</p>
479<p>In the following example, <code>flush()</code> is used to write a compressed partial
480HTTP response to the client:</p>
481<pre><code class="language-js"><span class="hljs-keyword">const</span> zlib = <span class="hljs-built_in">require</span>(<span class="hljs-string">'zlib'</span>);
482<span class="hljs-keyword">const</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">'http'</span>);
483<span class="hljs-keyword">const</span> { pipeline } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'stream'</span>);
484
485http.<span class="hljs-title function_">createServer</span>(<span class="hljs-function">(<span class="hljs-params">request, response</span>) =></span> {
486  <span class="hljs-comment">// For the sake of simplicity, the Accept-Encoding checks are omitted.</span>
487  response.<span class="hljs-title function_">writeHead</span>(<span class="hljs-number">200</span>, { <span class="hljs-string">'content-encoding'</span>: <span class="hljs-string">'gzip'</span> });
488  <span class="hljs-keyword">const</span> output = zlib.<span class="hljs-title function_">createGzip</span>();
489  <span class="hljs-keyword">let</span> i;
490
491  <span class="hljs-title function_">pipeline</span>(output, response, <span class="hljs-function">(<span class="hljs-params">err</span>) =></span> {
492    <span class="hljs-keyword">if</span> (err) {
493      <span class="hljs-comment">// If an error occurs, there's not much we can do because</span>
494      <span class="hljs-comment">// the server has already sent the 200 response code and</span>
495      <span class="hljs-comment">// some amount of data has already been sent to the client.</span>
496      <span class="hljs-comment">// The best we can do is terminate the response immediately</span>
497      <span class="hljs-comment">// and log the error.</span>
498      <span class="hljs-built_in">clearInterval</span>(i);
499      response.<span class="hljs-title function_">end</span>();
500      <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
501    }
502  });
503
504  i = <span class="hljs-built_in">setInterval</span>(<span class="hljs-function">() =></span> {
505    output.<span class="hljs-title function_">write</span>(<span class="hljs-string">`The current time is <span class="hljs-subst">${<span class="hljs-built_in">Date</span>()}</span>\n`</span>, <span class="hljs-function">() =></span> {
506      <span class="hljs-comment">// The data has been passed to zlib, but the compression algorithm may</span>
507      <span class="hljs-comment">// have decided to buffer the data for more efficient compression.</span>
508      <span class="hljs-comment">// Calling .flush() will make the data available as soon as the client</span>
509      <span class="hljs-comment">// is ready to receive it.</span>
510      output.<span class="hljs-title function_">flush</span>();
511    });
512  }, <span class="hljs-number">1000</span>);
513}).<span class="hljs-title function_">listen</span>(<span class="hljs-number">1337</span>);</code></pre>
514</section><section><h3>Constants<span><a class="mark" href="#zlib_constants" id="zlib_constants">#</a></span></h3>
515<div class="api_metadata">
516<span>Added in: v0.5.8</span>
517</div>
518
519<h4>zlib constants<span><a class="mark" href="#zlib_zlib_constants" id="zlib_zlib_constants">#</a></span></h4>
520<p>All of the constants defined in <code>zlib.h</code> are also defined on
521<code>require('zlib').constants</code>. In the normal course of operations, it will not be
522necessary to use these constants. They are documented so that their presence is
523not surprising. This section is taken almost directly from the
524<a href="https://zlib.net/manual.html#Constants">zlib documentation</a>.</p>
525<p>Previously, the constants were available directly from <code>require('zlib')</code>, for
526instance <code>zlib.Z_NO_FLUSH</code>. Accessing the constants directly from the module is
527currently still possible but is deprecated.</p>
528<p>Allowed flush values.</p>
529<ul>
530<li><code>zlib.constants.Z_NO_FLUSH</code></li>
531<li><code>zlib.constants.Z_PARTIAL_FLUSH</code></li>
532<li><code>zlib.constants.Z_SYNC_FLUSH</code></li>
533<li><code>zlib.constants.Z_FULL_FLUSH</code></li>
534<li><code>zlib.constants.Z_FINISH</code></li>
535<li><code>zlib.constants.Z_BLOCK</code></li>
536<li><code>zlib.constants.Z_TREES</code></li>
537</ul>
538<p>Return codes for the compression/decompression functions. Negative
539values are errors, positive values are used for special but normal
540events.</p>
541<ul>
542<li><code>zlib.constants.Z_OK</code></li>
543<li><code>zlib.constants.Z_STREAM_END</code></li>
544<li><code>zlib.constants.Z_NEED_DICT</code></li>
545<li><code>zlib.constants.Z_ERRNO</code></li>
546<li><code>zlib.constants.Z_STREAM_ERROR</code></li>
547<li><code>zlib.constants.Z_DATA_ERROR</code></li>
548<li><code>zlib.constants.Z_MEM_ERROR</code></li>
549<li><code>zlib.constants.Z_BUF_ERROR</code></li>
550<li><code>zlib.constants.Z_VERSION_ERROR</code></li>
551</ul>
552<p>Compression levels.</p>
553<ul>
554<li><code>zlib.constants.Z_NO_COMPRESSION</code></li>
555<li><code>zlib.constants.Z_BEST_SPEED</code></li>
556<li><code>zlib.constants.Z_BEST_COMPRESSION</code></li>
557<li><code>zlib.constants.Z_DEFAULT_COMPRESSION</code></li>
558</ul>
559<p>Compression strategy.</p>
560<ul>
561<li><code>zlib.constants.Z_FILTERED</code></li>
562<li><code>zlib.constants.Z_HUFFMAN_ONLY</code></li>
563<li><code>zlib.constants.Z_RLE</code></li>
564<li><code>zlib.constants.Z_FIXED</code></li>
565<li><code>zlib.constants.Z_DEFAULT_STRATEGY</code></li>
566</ul>
567<h4>Brotli constants<span><a class="mark" href="#zlib_brotli_constants" id="zlib_brotli_constants">#</a></span></h4>
568<div class="api_metadata">
569<span>Added in: v11.7.0, v10.16.0</span>
570</div>
571<p>There are several options and other constants available for Brotli-based
572streams:</p>
573<h5>Flush operations<span><a class="mark" href="#zlib_flush_operations" id="zlib_flush_operations">#</a></span></h5>
574<p>The following values are valid flush operations for Brotli-based streams:</p>
575<ul>
576<li><code>zlib.constants.BROTLI_OPERATION_PROCESS</code> (default for all operations)</li>
577<li><code>zlib.constants.BROTLI_OPERATION_FLUSH</code> (default when calling <code>.flush()</code>)</li>
578<li><code>zlib.constants.BROTLI_OPERATION_FINISH</code> (default for the last chunk)</li>
579<li><code>zlib.constants.BROTLI_OPERATION_EMIT_METADATA</code>
580<ul>
581<li>This particular operation may be hard to use in a Node.js context,
582as the streaming layer makes it hard to know which data will end up
583in this frame. Also, there is currently no way to consume this data through
584the Node.js API.</li>
585</ul>
586</li>
587</ul>
588<h5>Compressor options<span><a class="mark" href="#zlib_compressor_options" id="zlib_compressor_options">#</a></span></h5>
589<p>There are several options that can be set on Brotli encoders, affecting
590compression efficiency and speed. Both the keys and the values can be accessed
591as properties of the <code>zlib.constants</code> object.</p>
592<p>The most important options are:</p>
593<ul>
594<li><code>BROTLI_PARAM_MODE</code>
595<ul>
596<li><code>BROTLI_MODE_GENERIC</code> (default)</li>
597<li><code>BROTLI_MODE_TEXT</code>, adjusted for UTF-8 text</li>
598<li><code>BROTLI_MODE_FONT</code>, adjusted for WOFF 2.0 fonts</li>
599</ul>
600</li>
601<li><code>BROTLI_PARAM_QUALITY</code>
602<ul>
603<li>Ranges from <code>BROTLI_MIN_QUALITY</code> to <code>BROTLI_MAX_QUALITY</code>,
604with a default of <code>BROTLI_DEFAULT_QUALITY</code>.</li>
605</ul>
606</li>
607<li><code>BROTLI_PARAM_SIZE_HINT</code>
608<ul>
609<li>Integer value representing the expected input size;
610defaults to <code>0</code> for an unknown input size.</li>
611</ul>
612</li>
613</ul>
614<p>The following flags can be set for advanced control over the compression
615algorithm and memory usage tuning:</p>
616<ul>
617<li><code>BROTLI_PARAM_LGWIN</code>
618<ul>
619<li>Ranges from <code>BROTLI_MIN_WINDOW_BITS</code> to <code>BROTLI_MAX_WINDOW_BITS</code>,
620with a default of <code>BROTLI_DEFAULT_WINDOW</code>, or up to
621<code>BROTLI_LARGE_MAX_WINDOW_BITS</code> if the <code>BROTLI_PARAM_LARGE_WINDOW</code> flag
622is set.</li>
623</ul>
624</li>
625<li><code>BROTLI_PARAM_LGBLOCK</code>
626<ul>
627<li>Ranges from <code>BROTLI_MIN_INPUT_BLOCK_BITS</code> to <code>BROTLI_MAX_INPUT_BLOCK_BITS</code>.</li>
628</ul>
629</li>
630<li><code>BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING</code>
631<ul>
632<li>Boolean flag that decreases compression ratio in favour of
633decompression speed.</li>
634</ul>
635</li>
636<li><code>BROTLI_PARAM_LARGE_WINDOW</code>
637<ul>
638<li>Boolean flag enabling “Large Window Brotli” mode (not compatible with the
639Brotli format as standardized in <a href="https://www.rfc-editor.org/rfc/rfc7932.txt">RFC 7932</a>).</li>
640</ul>
641</li>
642<li><code>BROTLI_PARAM_NPOSTFIX</code>
643<ul>
644<li>Ranges from <code>0</code> to <code>BROTLI_MAX_NPOSTFIX</code>.</li>
645</ul>
646</li>
647<li><code>BROTLI_PARAM_NDIRECT</code>
648<ul>
649<li>Ranges from <code>0</code> to <code>15 &#x3C;&#x3C; NPOSTFIX</code> in steps of <code>1 &#x3C;&#x3C; NPOSTFIX</code>.</li>
650</ul>
651</li>
652</ul>
653<h5>Decompressor options<span><a class="mark" href="#zlib_decompressor_options" id="zlib_decompressor_options">#</a></span></h5>
654<p>These advanced options are available for controlling decompression:</p>
655<ul>
656<li><code>BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION</code>
657<ul>
658<li>Boolean flag that affects internal memory allocation patterns.</li>
659</ul>
660</li>
661<li><code>BROTLI_DECODER_PARAM_LARGE_WINDOW</code>
662<ul>
663<li>Boolean flag enabling “Large Window Brotli” mode (not compatible with the
664Brotli format as standardized in <a href="https://www.rfc-editor.org/rfc/rfc7932.txt">RFC 7932</a>).</li>
665</ul>
666</li>
667</ul>
668</section><section><h3>Class: <code>Options</code><span><a class="mark" href="#zlib_class_options" id="zlib_class_options">#</a></span></h3>
669<div class="api_metadata">
670<details class="changelog"><summary>History</summary>
671<table>
672<tbody><tr><th>Version</th><th>Changes</th></tr>
673<tr><td>v14.5.0, v12.19.0</td>
674<td><p>The <code>maxOutputLength</code> option is supported now.</p></td></tr>
675<tr><td>v9.4.0</td>
676<td><p>The <code>dictionary</code> option can be an <code>ArrayBuffer</code>.</p></td></tr>
677<tr><td>v8.0.0</td>
678<td><p>The <code>dictionary</code> option can be an <code>Uint8Array</code> now.</p></td></tr>
679<tr><td>v5.11.0</td>
680<td><p>The <code>finishFlush</code> option is supported now.</p></td></tr>
681<tr><td>v0.11.1</td>
682<td><p><span>Added in: v0.11.1</span></p></td></tr>
683</tbody></table>
684</details>
685</div>
686
687<p>Each zlib-based class takes an <code>options</code> object. No options are required.</p>
688<p>Some options are only relevant when compressing and are
689ignored by the decompression classes.</p>
690<ul>
691<li><code>flush</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <strong>Default:</strong> <code>zlib.constants.Z_NO_FLUSH</code></li>
692<li><code>finishFlush</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <strong>Default:</strong> <code>zlib.constants.Z_FINISH</code></li>
693<li><code>chunkSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <strong>Default:</strong> <code>16 * 1024</code></li>
694<li><code>windowBits</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
695<li><code>level</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> (compression only)</li>
696<li><code>memLevel</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> (compression only)</li>
697<li><code>strategy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> (compression only)</li>
698<li><code>dictionary</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> (deflate/inflate only,
699empty dictionary by default)</li>
700<li><code>info</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> (If <code>true</code>, returns an object with <code>buffer</code> and <code>engine</code>.)</li>
701<li><code>maxOutputLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> Limits output size when using
702<a href="#zlib_convenience_methods">convenience methods</a>. <strong>Default:</strong> <a href="buffer.html#buffer_buffer_kmaxlength"><code>buffer.kMaxLength</code></a></li>
703</ul>
704<p>See the <a href="https://zlib.net/manual.html#Advanced"><code>deflateInit2</code> and <code>inflateInit2</code></a> documentation for more
705information.</p>
706</section><section><h3>Class: <code>BrotliOptions</code><span><a class="mark" href="#zlib_class_brotlioptions" id="zlib_class_brotlioptions">#</a></span></h3>
707<div class="api_metadata">
708<details class="changelog"><summary>History</summary>
709<table>
710<tbody><tr><th>Version</th><th>Changes</th></tr>
711<tr><td>v14.5.0</td>
712<td><p>The <code>maxOutputLength</code> option is supported now.</p></td></tr>
713<tr><td>v11.7.0</td>
714<td><p><span>Added in: v11.7.0</span></p></td></tr>
715</tbody></table>
716</details>
717</div>
718
719<p>Each Brotli-based class takes an <code>options</code> object. All options are optional.</p>
720<ul>
721<li><code>flush</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <strong>Default:</strong> <code>zlib.constants.BROTLI_OPERATION_PROCESS</code></li>
722<li><code>finishFlush</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <strong>Default:</strong> <code>zlib.constants.BROTLI_OPERATION_FINISH</code></li>
723<li><code>chunkSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <strong>Default:</strong> <code>16 * 1024</code></li>
724<li><code>params</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> Key-value object containing indexed <a href="#zlib_brotli_constants">Brotli parameters</a>.</li>
725<li><code>maxOutputLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> Limits output size when using
726<a href="#zlib_convenience_methods">convenience methods</a>. <strong>Default:</strong> <a href="buffer.html#buffer_buffer_kmaxlength"><code>buffer.kMaxLength</code></a></li>
727</ul>
728<p>For example:</p>
729<pre><code class="language-js"><span class="hljs-keyword">const</span> stream = zlib.<span class="hljs-title function_">createBrotliCompress</span>({
730  <span class="hljs-attr">chunkSize</span>: <span class="hljs-number">32</span> * <span class="hljs-number">1024</span>,
731  <span class="hljs-attr">params</span>: {
732    [zlib.<span class="hljs-property">constants</span>.<span class="hljs-property">BROTLI_PARAM_MODE</span>]: zlib.<span class="hljs-property">constants</span>.<span class="hljs-property">BROTLI_MODE_TEXT</span>,
733    [zlib.<span class="hljs-property">constants</span>.<span class="hljs-property">BROTLI_PARAM_QUALITY</span>]: <span class="hljs-number">4</span>,
734    [zlib.<span class="hljs-property">constants</span>.<span class="hljs-property">BROTLI_PARAM_SIZE_HINT</span>]: fs.<span class="hljs-title function_">statSync</span>(inputFile).<span class="hljs-property">size</span>
735  }
736});</code></pre>
737</section><section><h3>Class: <code>zlib.BrotliCompress</code><span><a class="mark" href="#zlib_class_zlib_brotlicompress" id="zlib_class_zlib_brotlicompress">#</a></span></h3>
738<div class="api_metadata">
739<span>Added in: v11.7.0, v10.16.0</span>
740</div>
741<p>Compress data using the Brotli algorithm.</p>
742</section><section><h3>Class: <code>zlib.BrotliDecompress</code><span><a class="mark" href="#zlib_class_zlib_brotlidecompress" id="zlib_class_zlib_brotlidecompress">#</a></span></h3>
743<div class="api_metadata">
744<span>Added in: v11.7.0, v10.16.0</span>
745</div>
746<p>Decompress data using the Brotli algorithm.</p>
747</section><section><h3>Class: <code>zlib.Deflate</code><span><a class="mark" href="#zlib_class_zlib_deflate" id="zlib_class_zlib_deflate">#</a></span></h3>
748<div class="api_metadata">
749<span>Added in: v0.5.8</span>
750</div>
751<p>Compress data using deflate.</p>
752</section><section><h3>Class: <code>zlib.DeflateRaw</code><span><a class="mark" href="#zlib_class_zlib_deflateraw" id="zlib_class_zlib_deflateraw">#</a></span></h3>
753<div class="api_metadata">
754<span>Added in: v0.5.8</span>
755</div>
756<p>Compress data using deflate, and do not append a <code>zlib</code> header.</p>
757</section><section><h3>Class: <code>zlib.Gunzip</code><span><a class="mark" href="#zlib_class_zlib_gunzip" id="zlib_class_zlib_gunzip">#</a></span></h3>
758<div class="api_metadata">
759<details class="changelog"><summary>History</summary>
760<table>
761<tbody><tr><th>Version</th><th>Changes</th></tr>
762<tr><td>v6.0.0</td>
763<td><p>Trailing garbage at the end of the input stream will now result in an <code>'error'</code> event.</p></td></tr>
764<tr><td>v5.9.0</td>
765<td><p>Multiple concatenated gzip file members are supported now.</p></td></tr>
766<tr><td>v5.0.0</td>
767<td><p>A truncated input stream will now result in an <code>'error'</code> event.</p></td></tr>
768<tr><td>v0.5.8</td>
769<td><p><span>Added in: v0.5.8</span></p></td></tr>
770</tbody></table>
771</details>
772</div>
773<p>Decompress a gzip stream.</p>
774</section><section><h3>Class: <code>zlib.Gzip</code><span><a class="mark" href="#zlib_class_zlib_gzip" id="zlib_class_zlib_gzip">#</a></span></h3>
775<div class="api_metadata">
776<span>Added in: v0.5.8</span>
777</div>
778<p>Compress data using gzip.</p>
779</section><section><h3>Class: <code>zlib.Inflate</code><span><a class="mark" href="#zlib_class_zlib_inflate" id="zlib_class_zlib_inflate">#</a></span></h3>
780<div class="api_metadata">
781<details class="changelog"><summary>History</summary>
782<table>
783<tbody><tr><th>Version</th><th>Changes</th></tr>
784<tr><td>v5.0.0</td>
785<td><p>A truncated input stream will now result in an <code>'error'</code> event.</p></td></tr>
786<tr><td>v0.5.8</td>
787<td><p><span>Added in: v0.5.8</span></p></td></tr>
788</tbody></table>
789</details>
790</div>
791<p>Decompress a deflate stream.</p>
792</section><section><h3>Class: <code>zlib.InflateRaw</code><span><a class="mark" href="#zlib_class_zlib_inflateraw" id="zlib_class_zlib_inflateraw">#</a></span></h3>
793<div class="api_metadata">
794<details class="changelog"><summary>History</summary>
795<table>
796<tbody><tr><th>Version</th><th>Changes</th></tr>
797<tr><td>v6.8.0</td>
798<td><p>Custom dictionaries are now supported by <code>InflateRaw</code>.</p></td></tr>
799<tr><td>v5.0.0</td>
800<td><p>A truncated input stream will now result in an <code>'error'</code> event.</p></td></tr>
801<tr><td>v0.5.8</td>
802<td><p><span>Added in: v0.5.8</span></p></td></tr>
803</tbody></table>
804</details>
805</div>
806<p>Decompress a raw deflate stream.</p>
807</section><section><h3>Class: <code>zlib.Unzip</code><span><a class="mark" href="#zlib_class_zlib_unzip" id="zlib_class_zlib_unzip">#</a></span></h3>
808<div class="api_metadata">
809<span>Added in: v0.5.8</span>
810</div>
811<p>Decompress either a Gzip- or Deflate-compressed stream by auto-detecting
812the header.</p>
813</section><section><h3>Class: <code>zlib.ZlibBase</code><span><a class="mark" href="#zlib_class_zlib_zlibbase" id="zlib_class_zlib_zlibbase">#</a></span></h3>
814<div class="api_metadata">
815<details class="changelog"><summary>History</summary>
816<table>
817<tbody><tr><th>Version</th><th>Changes</th></tr>
818<tr><td>v11.7.0, v10.16.0</td>
819<td><p>This class was renamed from <code>Zlib</code> to <code>ZlibBase</code>.</p></td></tr>
820<tr><td>v0.5.8</td>
821<td><p><span>Added in: v0.5.8</span></p></td></tr>
822</tbody></table>
823</details>
824</div>
825<p>Not exported by the <code>zlib</code> module. It is documented here because it is the base
826class of the compressor/decompressor classes.</p>
827<p>This class inherits from <a href="stream.html#stream_class_stream_transform"><code>stream.Transform</code></a>, allowing <code>zlib</code> objects to be
828used in pipes and similar stream operations.</p>
829<h4><code>zlib.bytesRead</code><span><a class="mark" href="#zlib_zlib_bytesread" id="zlib_zlib_bytesread">#</a></span></h4>
830<div class="api_metadata">
831<span>Added in: v8.1.0</span><span>Deprecated since: v10.0.0</span>
832</div>
833<p></p><div class="api_stability api_stability_0"><a href="documentation.html#documentation_stability_index">Stability: 0</a> - Deprecated: Use <a href="#zlib_zlib_byteswritten"><code>zlib.bytesWritten</code></a> instead.</div><p></p>
834<ul>
835<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
836</ul>
837<p>Deprecated alias for <a href="#zlib_zlib_byteswritten"><code>zlib.bytesWritten</code></a>. This original name was chosen
838because it also made sense to interpret the value as the number of bytes
839read by the engine, but is inconsistent with other streams in Node.js that
840expose values under these names.</p>
841<h4><code>zlib.bytesWritten</code><span><a class="mark" href="#zlib_zlib_byteswritten" id="zlib_zlib_byteswritten">#</a></span></h4>
842<div class="api_metadata">
843<span>Added in: v10.0.0</span>
844</div>
845<ul>
846<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
847</ul>
848<p>The <code>zlib.bytesWritten</code> property specifies the number of bytes written to
849the engine, before the bytes are processed (compressed or decompressed,
850as appropriate for the derived class).</p>
851<h4><code>zlib.close([callback])</code><span><a class="mark" href="#zlib_zlib_close_callback" id="zlib_zlib_close_callback">#</a></span></h4>
852<div class="api_metadata">
853<span>Added in: v0.9.4</span>
854</div>
855<ul>
856<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
857</ul>
858<p>Close the underlying handle.</p>
859<h4><code>zlib.flush([kind, ]callback)</code><span><a class="mark" href="#zlib_zlib_flush_kind_callback" id="zlib_zlib_flush_kind_callback">#</a></span></h4>
860<div class="api_metadata">
861<span>Added in: v0.5.8</span>
862</div>
863<ul>
864<li><code>kind</code> <strong>Default:</strong> <code>zlib.constants.Z_FULL_FLUSH</code> for zlib-based streams,
865<code>zlib.constants.BROTLI_OPERATION_FLUSH</code> for Brotli-based streams.</li>
866<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
867</ul>
868<p>Flush pending data. Don't call this frivolously, premature flushes negatively
869impact the effectiveness of the compression algorithm.</p>
870<p>Calling this only flushes data from the internal <code>zlib</code> state, and does not
871perform flushing of any kind on the streams level. Rather, it behaves like a
872normal call to <code>.write()</code>, i.e. it will be queued up behind other pending
873writes and will only produce output when data is being read from the stream.</p>
874<h4><code>zlib.params(level, strategy, callback)</code><span><a class="mark" href="#zlib_zlib_params_level_strategy_callback" id="zlib_zlib_params_level_strategy_callback">#</a></span></h4>
875<div class="api_metadata">
876<span>Added in: v0.11.4</span>
877</div>
878<ul>
879<li><code>level</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
880<li><code>strategy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
881<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
882</ul>
883<p>This function is only available for zlib-based streams, i.e. not Brotli.</p>
884<p>Dynamically update the compression level and compression strategy.
885Only applicable to deflate algorithm.</p>
886<h4><code>zlib.reset()</code><span><a class="mark" href="#zlib_zlib_reset" id="zlib_zlib_reset">#</a></span></h4>
887<div class="api_metadata">
888<span>Added in: v0.7.0</span>
889</div>
890<p>Reset the compressor/decompressor to factory defaults. Only applicable to
891the inflate and deflate algorithms.</p>
892</section><section><h3><code>zlib.constants</code><span><a class="mark" href="#zlib_zlib_constants_1" id="zlib_zlib_constants_1">#</a></span></h3>
893<div class="api_metadata">
894<span>Added in: v7.0.0</span>
895</div>
896<p>Provides an object enumerating Zlib-related constants.</p>
897</section><section><h3><code>zlib.createBrotliCompress([options])</code><span><a class="mark" href="#zlib_zlib_createbrotlicompress_options" id="zlib_zlib_createbrotlicompress_options">#</a></span></h3>
898<div class="api_metadata">
899<span>Added in: v11.7.0, v10.16.0</span>
900</div>
901<ul>
902<li><code>options</code> <a href="zlib.html#zlib_class_brotlioptions" class="type">&#x3C;brotli options></a></li>
903</ul>
904<p>Creates and returns a new <a href="#zlib_class_zlib_brotlicompress"><code>BrotliCompress</code></a> object.</p>
905</section><section><h3><code>zlib.createBrotliDecompress([options])</code><span><a class="mark" href="#zlib_zlib_createbrotlidecompress_options" id="zlib_zlib_createbrotlidecompress_options">#</a></span></h3>
906<div class="api_metadata">
907<span>Added in: v11.7.0, v10.16.0</span>
908</div>
909<ul>
910<li><code>options</code> <a href="zlib.html#zlib_class_brotlioptions" class="type">&#x3C;brotli options></a></li>
911</ul>
912<p>Creates and returns a new <a href="#zlib_class_zlib_brotlidecompress"><code>BrotliDecompress</code></a> object.</p>
913</section><section><h3><code>zlib.createDeflate([options])</code><span><a class="mark" href="#zlib_zlib_createdeflate_options" id="zlib_zlib_createdeflate_options">#</a></span></h3>
914<div class="api_metadata">
915<span>Added in: v0.5.8</span>
916</div>
917<ul>
918<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
919</ul>
920<p>Creates and returns a new <a href="#zlib_class_zlib_deflate"><code>Deflate</code></a> object.</p>
921</section><section><h3><code>zlib.createDeflateRaw([options])</code><span><a class="mark" href="#zlib_zlib_createdeflateraw_options" id="zlib_zlib_createdeflateraw_options">#</a></span></h3>
922<div class="api_metadata">
923<span>Added in: v0.5.8</span>
924</div>
925<ul>
926<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
927</ul>
928<p>Creates and returns a new <a href="#zlib_class_zlib_deflateraw"><code>DeflateRaw</code></a> object.</p>
929<p>An upgrade of zlib from 1.2.8 to 1.2.11 changed behavior when <code>windowBits</code>
930is set to 8 for raw deflate streams. zlib would automatically set <code>windowBits</code>
931to 9 if was initially set to 8. Newer versions of zlib will throw an exception,
932so Node.js restored the original behavior of upgrading a value of 8 to 9,
933since passing <code>windowBits = 9</code> to zlib actually results in a compressed stream
934that effectively uses an 8-bit window only.</p>
935</section><section><h3><code>zlib.createGunzip([options])</code><span><a class="mark" href="#zlib_zlib_creategunzip_options" id="zlib_zlib_creategunzip_options">#</a></span></h3>
936<div class="api_metadata">
937<span>Added in: v0.5.8</span>
938</div>
939<ul>
940<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
941</ul>
942<p>Creates and returns a new <a href="#zlib_class_zlib_gunzip"><code>Gunzip</code></a> object.</p>
943</section><section><h3><code>zlib.createGzip([options])</code><span><a class="mark" href="#zlib_zlib_creategzip_options" id="zlib_zlib_creategzip_options">#</a></span></h3>
944<div class="api_metadata">
945<span>Added in: v0.5.8</span>
946</div>
947<ul>
948<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
949</ul>
950<p>Creates and returns a new <a href="#zlib_class_zlib_gzip"><code>Gzip</code></a> object.
951See <a href="#zlib_zlib">example</a>.</p>
952</section><section><h3><code>zlib.createInflate([options])</code><span><a class="mark" href="#zlib_zlib_createinflate_options" id="zlib_zlib_createinflate_options">#</a></span></h3>
953<div class="api_metadata">
954<span>Added in: v0.5.8</span>
955</div>
956<ul>
957<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
958</ul>
959<p>Creates and returns a new <a href="#zlib_class_zlib_inflate"><code>Inflate</code></a> object.</p>
960</section><section><h3><code>zlib.createInflateRaw([options])</code><span><a class="mark" href="#zlib_zlib_createinflateraw_options" id="zlib_zlib_createinflateraw_options">#</a></span></h3>
961<div class="api_metadata">
962<span>Added in: v0.5.8</span>
963</div>
964<ul>
965<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
966</ul>
967<p>Creates and returns a new <a href="#zlib_class_zlib_inflateraw"><code>InflateRaw</code></a> object.</p>
968</section><section><h3><code>zlib.createUnzip([options])</code><span><a class="mark" href="#zlib_zlib_createunzip_options" id="zlib_zlib_createunzip_options">#</a></span></h3>
969<div class="api_metadata">
970<span>Added in: v0.5.8</span>
971</div>
972<ul>
973<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
974</ul>
975<p>Creates and returns a new <a href="#zlib_class_zlib_unzip"><code>Unzip</code></a> object.</p>
976</section><section><h3>Convenience methods<span><a class="mark" href="#zlib_convenience_methods" id="zlib_convenience_methods">#</a></span></h3>
977
978<p>All of these take a <a href="buffer.html#buffer_class_buffer"><code>Buffer</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray"><code>TypedArray</code></a>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView"><code>DataView</code></a>,
979<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer"><code>ArrayBuffer</code></a> or string as the first argument, an optional second argument
980to supply options to the <code>zlib</code> classes and will call the supplied callback
981with <code>callback(error, result)</code>.</p>
982<p>Every method has a <code>*Sync</code> counterpart, which accept the same arguments, but
983without a callback.</p>
984<h4><code>zlib.brotliCompress(buffer[, options], callback)</code><span><a class="mark" href="#zlib_zlib_brotlicompress_buffer_options_callback" id="zlib_zlib_brotlicompress_buffer_options_callback">#</a></span></h4>
985<div class="api_metadata">
986<span>Added in: v11.7.0, v10.16.0</span>
987</div>
988<ul>
989<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
990<li><code>options</code> <a href="zlib.html#zlib_class_brotlioptions" class="type">&#x3C;brotli options></a></li>
991<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
992</ul>
993<h4><code>zlib.brotliCompressSync(buffer[, options])</code><span><a class="mark" href="#zlib_zlib_brotlicompresssync_buffer_options" id="zlib_zlib_brotlicompresssync_buffer_options">#</a></span></h4>
994<div class="api_metadata">
995<span>Added in: v11.7.0, v10.16.0</span>
996</div>
997<ul>
998<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
999<li><code>options</code> <a href="zlib.html#zlib_class_brotlioptions" class="type">&#x3C;brotli options></a></li>
1000</ul>
1001<p>Compress a chunk of data with <a href="#zlib_class_zlib_brotlicompress"><code>BrotliCompress</code></a>.</p>
1002<h4><code>zlib.brotliDecompress(buffer[, options], callback)</code><span><a class="mark" href="#zlib_zlib_brotlidecompress_buffer_options_callback" id="zlib_zlib_brotlidecompress_buffer_options_callback">#</a></span></h4>
1003<div class="api_metadata">
1004<span>Added in: v11.7.0, v10.16.0</span>
1005</div>
1006<ul>
1007<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1008<li><code>options</code> <a href="zlib.html#zlib_class_brotlioptions" class="type">&#x3C;brotli options></a></li>
1009<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
1010</ul>
1011<h4><code>zlib.brotliDecompressSync(buffer[, options])</code><span><a class="mark" href="#zlib_zlib_brotlidecompresssync_buffer_options" id="zlib_zlib_brotlidecompresssync_buffer_options">#</a></span></h4>
1012<div class="api_metadata">
1013<span>Added in: v11.7.0, v10.16.0</span>
1014</div>
1015<ul>
1016<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1017<li><code>options</code> <a href="zlib.html#zlib_class_brotlioptions" class="type">&#x3C;brotli options></a></li>
1018</ul>
1019<p>Decompress a chunk of data with <a href="#zlib_class_zlib_brotlidecompress"><code>BrotliDecompress</code></a>.</p>
1020<h4><code>zlib.deflate(buffer[, options], callback)</code><span><a class="mark" href="#zlib_zlib_deflate_buffer_options_callback" id="zlib_zlib_deflate_buffer_options_callback">#</a></span></h4>
1021<div class="api_metadata">
1022<details class="changelog"><summary>History</summary>
1023<table>
1024<tbody><tr><th>Version</th><th>Changes</th></tr>
1025<tr><td>v9.4.0</td>
1026<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
1027<tr><td>v8.0.0</td>
1028<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1029<tr><td>v8.0.0</td>
1030<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1031<tr><td>v0.6.0</td>
1032<td><p><span>Added in: v0.6.0</span></p></td></tr>
1033</tbody></table>
1034</details>
1035</div>
1036<ul>
1037<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1038<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1039<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
1040</ul>
1041<h4><code>zlib.deflateSync(buffer[, options])</code><span><a class="mark" href="#zlib_zlib_deflatesync_buffer_options" id="zlib_zlib_deflatesync_buffer_options">#</a></span></h4>
1042<div class="api_metadata">
1043<details class="changelog"><summary>History</summary>
1044<table>
1045<tbody><tr><th>Version</th><th>Changes</th></tr>
1046<tr><td>v9.4.0</td>
1047<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
1048<tr><td>v8.0.0</td>
1049<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1050<tr><td>v8.0.0</td>
1051<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1052<tr><td>v0.11.12</td>
1053<td><p><span>Added in: v0.11.12</span></p></td></tr>
1054</tbody></table>
1055</details>
1056</div>
1057<ul>
1058<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1059<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1060</ul>
1061<p>Compress a chunk of data with <a href="#zlib_class_zlib_deflate"><code>Deflate</code></a>.</p>
1062<h4><code>zlib.deflateRaw(buffer[, options], callback)</code><span><a class="mark" href="#zlib_zlib_deflateraw_buffer_options_callback" id="zlib_zlib_deflateraw_buffer_options_callback">#</a></span></h4>
1063<div class="api_metadata">
1064<details class="changelog"><summary>History</summary>
1065<table>
1066<tbody><tr><th>Version</th><th>Changes</th></tr>
1067<tr><td>v8.0.0</td>
1068<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1069<tr><td>v8.0.0</td>
1070<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1071<tr><td>v0.6.0</td>
1072<td><p><span>Added in: v0.6.0</span></p></td></tr>
1073</tbody></table>
1074</details>
1075</div>
1076<ul>
1077<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1078<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1079<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
1080</ul>
1081<h4><code>zlib.deflateRawSync(buffer[, options])</code><span><a class="mark" href="#zlib_zlib_deflaterawsync_buffer_options" id="zlib_zlib_deflaterawsync_buffer_options">#</a></span></h4>
1082<div class="api_metadata">
1083<details class="changelog"><summary>History</summary>
1084<table>
1085<tbody><tr><th>Version</th><th>Changes</th></tr>
1086<tr><td>v9.4.0</td>
1087<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
1088<tr><td>v8.0.0</td>
1089<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1090<tr><td>v8.0.0</td>
1091<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1092<tr><td>v0.11.12</td>
1093<td><p><span>Added in: v0.11.12</span></p></td></tr>
1094</tbody></table>
1095</details>
1096</div>
1097<ul>
1098<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1099<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1100</ul>
1101<p>Compress a chunk of data with <a href="#zlib_class_zlib_deflateraw"><code>DeflateRaw</code></a>.</p>
1102<h4><code>zlib.gunzip(buffer[, options], callback)</code><span><a class="mark" href="#zlib_zlib_gunzip_buffer_options_callback" id="zlib_zlib_gunzip_buffer_options_callback">#</a></span></h4>
1103<div class="api_metadata">
1104<details class="changelog"><summary>History</summary>
1105<table>
1106<tbody><tr><th>Version</th><th>Changes</th></tr>
1107<tr><td>v9.4.0</td>
1108<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
1109<tr><td>v8.0.0</td>
1110<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1111<tr><td>v8.0.0</td>
1112<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1113<tr><td>v0.6.0</td>
1114<td><p><span>Added in: v0.6.0</span></p></td></tr>
1115</tbody></table>
1116</details>
1117</div>
1118<ul>
1119<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1120<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1121<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
1122</ul>
1123<h4><code>zlib.gunzipSync(buffer[, options])</code><span><a class="mark" href="#zlib_zlib_gunzipsync_buffer_options" id="zlib_zlib_gunzipsync_buffer_options">#</a></span></h4>
1124<div class="api_metadata">
1125<details class="changelog"><summary>History</summary>
1126<table>
1127<tbody><tr><th>Version</th><th>Changes</th></tr>
1128<tr><td>v9.4.0</td>
1129<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
1130<tr><td>v8.0.0</td>
1131<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1132<tr><td>v8.0.0</td>
1133<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1134<tr><td>v0.11.12</td>
1135<td><p><span>Added in: v0.11.12</span></p></td></tr>
1136</tbody></table>
1137</details>
1138</div>
1139<ul>
1140<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1141<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1142</ul>
1143<p>Decompress a chunk of data with <a href="#zlib_class_zlib_gunzip"><code>Gunzip</code></a>.</p>
1144<h4><code>zlib.gzip(buffer[, options], callback)</code><span><a class="mark" href="#zlib_zlib_gzip_buffer_options_callback" id="zlib_zlib_gzip_buffer_options_callback">#</a></span></h4>
1145<div class="api_metadata">
1146<details class="changelog"><summary>History</summary>
1147<table>
1148<tbody><tr><th>Version</th><th>Changes</th></tr>
1149<tr><td>v9.4.0</td>
1150<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
1151<tr><td>v8.0.0</td>
1152<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1153<tr><td>v8.0.0</td>
1154<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1155<tr><td>v0.6.0</td>
1156<td><p><span>Added in: v0.6.0</span></p></td></tr>
1157</tbody></table>
1158</details>
1159</div>
1160<ul>
1161<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1162<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1163<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
1164</ul>
1165<h4><code>zlib.gzipSync(buffer[, options])</code><span><a class="mark" href="#zlib_zlib_gzipsync_buffer_options" id="zlib_zlib_gzipsync_buffer_options">#</a></span></h4>
1166<div class="api_metadata">
1167<details class="changelog"><summary>History</summary>
1168<table>
1169<tbody><tr><th>Version</th><th>Changes</th></tr>
1170<tr><td>v9.4.0</td>
1171<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
1172<tr><td>v8.0.0</td>
1173<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1174<tr><td>v8.0.0</td>
1175<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1176<tr><td>v0.11.12</td>
1177<td><p><span>Added in: v0.11.12</span></p></td></tr>
1178</tbody></table>
1179</details>
1180</div>
1181<ul>
1182<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1183<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1184</ul>
1185<p>Compress a chunk of data with <a href="#zlib_class_zlib_gzip"><code>Gzip</code></a>.</p>
1186<h4><code>zlib.inflate(buffer[, options], callback)</code><span><a class="mark" href="#zlib_zlib_inflate_buffer_options_callback" id="zlib_zlib_inflate_buffer_options_callback">#</a></span></h4>
1187<div class="api_metadata">
1188<details class="changelog"><summary>History</summary>
1189<table>
1190<tbody><tr><th>Version</th><th>Changes</th></tr>
1191<tr><td>v9.4.0</td>
1192<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
1193<tr><td>v8.0.0</td>
1194<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1195<tr><td>v8.0.0</td>
1196<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1197<tr><td>v0.6.0</td>
1198<td><p><span>Added in: v0.6.0</span></p></td></tr>
1199</tbody></table>
1200</details>
1201</div>
1202<ul>
1203<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1204<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1205<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
1206</ul>
1207<h4><code>zlib.inflateSync(buffer[, options])</code><span><a class="mark" href="#zlib_zlib_inflatesync_buffer_options" id="zlib_zlib_inflatesync_buffer_options">#</a></span></h4>
1208<div class="api_metadata">
1209<details class="changelog"><summary>History</summary>
1210<table>
1211<tbody><tr><th>Version</th><th>Changes</th></tr>
1212<tr><td>v9.4.0</td>
1213<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
1214<tr><td>v8.0.0</td>
1215<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1216<tr><td>v8.0.0</td>
1217<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1218<tr><td>v0.11.12</td>
1219<td><p><span>Added in: v0.11.12</span></p></td></tr>
1220</tbody></table>
1221</details>
1222</div>
1223<ul>
1224<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1225<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1226</ul>
1227<p>Decompress a chunk of data with <a href="#zlib_class_zlib_inflate"><code>Inflate</code></a>.</p>
1228<h4><code>zlib.inflateRaw(buffer[, options], callback)</code><span><a class="mark" href="#zlib_zlib_inflateraw_buffer_options_callback" id="zlib_zlib_inflateraw_buffer_options_callback">#</a></span></h4>
1229<div class="api_metadata">
1230<details class="changelog"><summary>History</summary>
1231<table>
1232<tbody><tr><th>Version</th><th>Changes</th></tr>
1233<tr><td>v9.4.0</td>
1234<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
1235<tr><td>v8.0.0</td>
1236<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1237<tr><td>v8.0.0</td>
1238<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1239<tr><td>v0.6.0</td>
1240<td><p><span>Added in: v0.6.0</span></p></td></tr>
1241</tbody></table>
1242</details>
1243</div>
1244<ul>
1245<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1246<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1247<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
1248</ul>
1249<h4><code>zlib.inflateRawSync(buffer[, options])</code><span><a class="mark" href="#zlib_zlib_inflaterawsync_buffer_options" id="zlib_zlib_inflaterawsync_buffer_options">#</a></span></h4>
1250<div class="api_metadata">
1251<details class="changelog"><summary>History</summary>
1252<table>
1253<tbody><tr><th>Version</th><th>Changes</th></tr>
1254<tr><td>v9.4.0</td>
1255<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
1256<tr><td>v8.0.0</td>
1257<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1258<tr><td>v8.0.0</td>
1259<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1260<tr><td>v0.11.12</td>
1261<td><p><span>Added in: v0.11.12</span></p></td></tr>
1262</tbody></table>
1263</details>
1264</div>
1265<ul>
1266<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1267<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1268</ul>
1269<p>Decompress a chunk of data with <a href="#zlib_class_zlib_inflateraw"><code>InflateRaw</code></a>.</p>
1270<h4><code>zlib.unzip(buffer[, options], callback)</code><span><a class="mark" href="#zlib_zlib_unzip_buffer_options_callback" id="zlib_zlib_unzip_buffer_options_callback">#</a></span></h4>
1271<div class="api_metadata">
1272<details class="changelog"><summary>History</summary>
1273<table>
1274<tbody><tr><th>Version</th><th>Changes</th></tr>
1275<tr><td>v9.4.0</td>
1276<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
1277<tr><td>v8.0.0</td>
1278<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1279<tr><td>v8.0.0</td>
1280<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1281<tr><td>v0.6.0</td>
1282<td><p><span>Added in: v0.6.0</span></p></td></tr>
1283</tbody></table>
1284</details>
1285</div>
1286<ul>
1287<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1288<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1289<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
1290</ul>
1291<h4><code>zlib.unzipSync(buffer[, options])</code><span><a class="mark" href="#zlib_zlib_unzipsync_buffer_options" id="zlib_zlib_unzipsync_buffer_options">#</a></span></h4>
1292<div class="api_metadata">
1293<details class="changelog"><summary>History</summary>
1294<table>
1295<tbody><tr><th>Version</th><th>Changes</th></tr>
1296<tr><td>v9.4.0</td>
1297<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
1298<tr><td>v8.0.0</td>
1299<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
1300<tr><td>v8.0.0</td>
1301<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
1302<tr><td>v0.11.12</td>
1303<td><p><span>Added in: v0.11.12</span></p></td></tr>
1304</tbody></table>
1305</details>
1306</div>
1307<ul>
1308<li><code>buffer</code> <a href="buffer.html#buffer_class_buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
1309<li><code>options</code> <a href="zlib.html#zlib_class_options" class="type">&#x3C;zlib options></a></li>
1310</ul>
1311<p>Decompress a chunk of data with <a href="#zlib_class_zlib_unzip"><code>Unzip</code></a>.</p></section>
1312        <!-- API END -->
1313      </div>
1314    </div>
1315  </div>
1316  <script>
1317    'use strict';
1318    {
1319      const kCustomPreference = 'customDarkTheme';
1320      const userSettings = sessionStorage.getItem(kCustomPreference);
1321      const themeToggleButton = document.getElementById('theme-toggle-btn');
1322      if (userSettings === null && window.matchMedia) {
1323        const mq = window.matchMedia('(prefers-color-scheme: dark)');
1324        if ('onchange' in mq) {
1325          function mqChangeListener(e) {
1326            document.body.classList.toggle('dark-mode', e.matches);
1327          }
1328          mq.addEventListener('change', mqChangeListener);
1329          if (themeToggleButton) {
1330            themeToggleButton.addEventListener('click', function() {
1331              mq.removeEventListener('change', mqChangeListener);
1332            }, { once: true });
1333          }
1334        }
1335        if (mq.matches) {
1336          document.body.classList.add('dark-mode');
1337        }
1338      } else if (userSettings === 'true') {
1339        document.body.classList.add('dark-mode');
1340      }
1341      if (themeToggleButton) {
1342        themeToggleButton.hidden = false;
1343        themeToggleButton.addEventListener('click', function() {
1344          sessionStorage.setItem(
1345            kCustomPreference,
1346            document.body.classList.toggle('dark-mode')
1347          );
1348        });
1349      }
1350    }
1351  </script>
1352</body>
1353</html>
1354