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