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