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