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