11cb0ef41Sopenharmony_ci<!DOCTYPE html>
21cb0ef41Sopenharmony_ci<html lang="en">
31cb0ef41Sopenharmony_ci<head>
41cb0ef41Sopenharmony_ci  <meta charset="utf-8">
51cb0ef41Sopenharmony_ci  <meta name="viewport" content="width=device-width">
61cb0ef41Sopenharmony_ci  <meta name="nodejs.org:node-version" content="v18.20.1">
71cb0ef41Sopenharmony_ci  <title>Zlib | Node.js v18.20.1 Documentation</title>
81cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:400,700,400italic&display=fallback">
91cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="assets/style.css">
101cb0ef41Sopenharmony_ci  <link rel="stylesheet" href="assets/hljs.css">
111cb0ef41Sopenharmony_ci  <link rel="canonical" href="https://nodejs.org/api/zlib.html">
121cb0ef41Sopenharmony_ci  <script async defer src="assets/api.js" type="text/javascript"></script>
131cb0ef41Sopenharmony_ci  
141cb0ef41Sopenharmony_ci</head>
151cb0ef41Sopenharmony_ci<body class="alt apidoc" id="api-section-zlib">
161cb0ef41Sopenharmony_ci  <div id="content" class="clearfix">
171cb0ef41Sopenharmony_ci    <div id="column2" class="interior">
181cb0ef41Sopenharmony_ci      <div id="intro" class="interior">
191cb0ef41Sopenharmony_ci        <a href="/" title="Go back to the home page">
201cb0ef41Sopenharmony_ci          Node.js
211cb0ef41Sopenharmony_ci        </a>
221cb0ef41Sopenharmony_ci      </div>
231cb0ef41Sopenharmony_ci      <ul>
241cb0ef41Sopenharmony_ci<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
251cb0ef41Sopenharmony_ci<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
261cb0ef41Sopenharmony_ci</ul>
271cb0ef41Sopenharmony_ci<hr class="line">
281cb0ef41Sopenharmony_ci<ul>
291cb0ef41Sopenharmony_ci<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
301cb0ef41Sopenharmony_ci<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
311cb0ef41Sopenharmony_ci<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
321cb0ef41Sopenharmony_ci<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
331cb0ef41Sopenharmony_ci<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
341cb0ef41Sopenharmony_ci<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
351cb0ef41Sopenharmony_ci<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
361cb0ef41Sopenharmony_ci<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
371cb0ef41Sopenharmony_ci<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
381cb0ef41Sopenharmony_ci<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
391cb0ef41Sopenharmony_ci<li><a href="console.html" class="nav-console">Console</a></li>
401cb0ef41Sopenharmony_ci<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
411cb0ef41Sopenharmony_ci<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
421cb0ef41Sopenharmony_ci<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
431cb0ef41Sopenharmony_ci<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
441cb0ef41Sopenharmony_ci<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
451cb0ef41Sopenharmony_ci<li><a href="dns.html" class="nav-dns">DNS</a></li>
461cb0ef41Sopenharmony_ci<li><a href="domain.html" class="nav-domain">Domain</a></li>
471cb0ef41Sopenharmony_ci<li><a href="errors.html" class="nav-errors">Errors</a></li>
481cb0ef41Sopenharmony_ci<li><a href="events.html" class="nav-events">Events</a></li>
491cb0ef41Sopenharmony_ci<li><a href="fs.html" class="nav-fs">File system</a></li>
501cb0ef41Sopenharmony_ci<li><a href="globals.html" class="nav-globals">Globals</a></li>
511cb0ef41Sopenharmony_ci<li><a href="http.html" class="nav-http">HTTP</a></li>
521cb0ef41Sopenharmony_ci<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
531cb0ef41Sopenharmony_ci<li><a href="https.html" class="nav-https">HTTPS</a></li>
541cb0ef41Sopenharmony_ci<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
551cb0ef41Sopenharmony_ci<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
561cb0ef41Sopenharmony_ci<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
571cb0ef41Sopenharmony_ci<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
581cb0ef41Sopenharmony_ci<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
591cb0ef41Sopenharmony_ci<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
601cb0ef41Sopenharmony_ci<li><a href="net.html" class="nav-net">Net</a></li>
611cb0ef41Sopenharmony_ci<li><a href="os.html" class="nav-os">OS</a></li>
621cb0ef41Sopenharmony_ci<li><a href="path.html" class="nav-path">Path</a></li>
631cb0ef41Sopenharmony_ci<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
641cb0ef41Sopenharmony_ci<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
651cb0ef41Sopenharmony_ci<li><a href="process.html" class="nav-process">Process</a></li>
661cb0ef41Sopenharmony_ci<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
671cb0ef41Sopenharmony_ci<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
681cb0ef41Sopenharmony_ci<li><a href="readline.html" class="nav-readline">Readline</a></li>
691cb0ef41Sopenharmony_ci<li><a href="repl.html" class="nav-repl">REPL</a></li>
701cb0ef41Sopenharmony_ci<li><a href="report.html" class="nav-report">Report</a></li>
711cb0ef41Sopenharmony_ci<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
721cb0ef41Sopenharmony_ci<li><a href="stream.html" class="nav-stream">Stream</a></li>
731cb0ef41Sopenharmony_ci<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
741cb0ef41Sopenharmony_ci<li><a href="test.html" class="nav-test">Test runner</a></li>
751cb0ef41Sopenharmony_ci<li><a href="timers.html" class="nav-timers">Timers</a></li>
761cb0ef41Sopenharmony_ci<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
771cb0ef41Sopenharmony_ci<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
781cb0ef41Sopenharmony_ci<li><a href="tty.html" class="nav-tty">TTY</a></li>
791cb0ef41Sopenharmony_ci<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
801cb0ef41Sopenharmony_ci<li><a href="url.html" class="nav-url">URL</a></li>
811cb0ef41Sopenharmony_ci<li><a href="util.html" class="nav-util">Utilities</a></li>
821cb0ef41Sopenharmony_ci<li><a href="v8.html" class="nav-v8">V8</a></li>
831cb0ef41Sopenharmony_ci<li><a href="vm.html" class="nav-vm">VM</a></li>
841cb0ef41Sopenharmony_ci<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
851cb0ef41Sopenharmony_ci<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
861cb0ef41Sopenharmony_ci<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
871cb0ef41Sopenharmony_ci<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
881cb0ef41Sopenharmony_ci<li><a href="zlib.html" class="nav-zlib active">Zlib</a></li>
891cb0ef41Sopenharmony_ci</ul>
901cb0ef41Sopenharmony_ci<hr class="line">
911cb0ef41Sopenharmony_ci<ul>
921cb0ef41Sopenharmony_ci<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
931cb0ef41Sopenharmony_ci</ul>
941cb0ef41Sopenharmony_ci    </div>
951cb0ef41Sopenharmony_ci
961cb0ef41Sopenharmony_ci    <div id="column1" data-id="zlib" class="interior">
971cb0ef41Sopenharmony_ci      <header class="header">
981cb0ef41Sopenharmony_ci        <div class="header-container">
991cb0ef41Sopenharmony_ci          <h1>Node.js v18.20.1 documentation</h1>
1001cb0ef41Sopenharmony_ci          <button class="theme-toggle-btn" id="theme-toggle-btn" title="Toggle dark mode/light mode" aria-label="Toggle dark mode/light mode" hidden>
1011cb0ef41Sopenharmony_ci            <svg xmlns="http://www.w3.org/2000/svg" class="icon dark-icon" height="24" width="24">
1021cb0ef41Sopenharmony_ci              <path fill="none" d="M0 0h24v24H0z" />
1031cb0ef41Sopenharmony_ci              <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"/>
1041cb0ef41Sopenharmony_ci              <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"/>
1051cb0ef41Sopenharmony_ci            </svg>
1061cb0ef41Sopenharmony_ci            <svg xmlns="http://www.w3.org/2000/svg" class="icon light-icon" height="24" width="24">
1071cb0ef41Sopenharmony_ci              <path d="M0 0h24v24H0z" fill="none" />
1081cb0ef41Sopenharmony_ci              <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"/>
1091cb0ef41Sopenharmony_ci            </svg>
1101cb0ef41Sopenharmony_ci          </button>
1111cb0ef41Sopenharmony_ci        </div>
1121cb0ef41Sopenharmony_ci        <div id="gtoc">
1131cb0ef41Sopenharmony_ci          <ul>
1141cb0ef41Sopenharmony_ci            <li class="pinned-header">Node.js v18.20.1</li>
1151cb0ef41Sopenharmony_ci            
1161cb0ef41Sopenharmony_ci    <li class="picker-header">
1171cb0ef41Sopenharmony_ci      <a href="#">
1181cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
1191cb0ef41Sopenharmony_ci        Table of contents
1201cb0ef41Sopenharmony_ci      </a>
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ci      <div class="picker"><div class="toc"><ul>
1231cb0ef41Sopenharmony_ci<li><span class="stability_2"><a href="#zlib">Zlib</a></span>
1241cb0ef41Sopenharmony_ci<ul>
1251cb0ef41Sopenharmony_ci<li><a href="#threadpool-usage-and-performance-considerations">Threadpool usage and performance considerations</a></li>
1261cb0ef41Sopenharmony_ci<li><a href="#compressing-http-requests-and-responses">Compressing HTTP requests and responses</a></li>
1271cb0ef41Sopenharmony_ci<li><a href="#memory-usage-tuning">Memory usage tuning</a>
1281cb0ef41Sopenharmony_ci<ul>
1291cb0ef41Sopenharmony_ci<li><a href="#for-zlib-based-streams">For zlib-based streams</a></li>
1301cb0ef41Sopenharmony_ci<li><a href="#for-brotli-based-streams">For Brotli-based streams</a></li>
1311cb0ef41Sopenharmony_ci</ul>
1321cb0ef41Sopenharmony_ci</li>
1331cb0ef41Sopenharmony_ci<li><a href="#flushing">Flushing</a></li>
1341cb0ef41Sopenharmony_ci<li><a href="#constants">Constants</a>
1351cb0ef41Sopenharmony_ci<ul>
1361cb0ef41Sopenharmony_ci<li><a href="#zlib-constants">zlib constants</a></li>
1371cb0ef41Sopenharmony_ci<li><a href="#brotli-constants">Brotli constants</a>
1381cb0ef41Sopenharmony_ci<ul>
1391cb0ef41Sopenharmony_ci<li><a href="#flush-operations">Flush operations</a></li>
1401cb0ef41Sopenharmony_ci<li><a href="#compressor-options">Compressor options</a></li>
1411cb0ef41Sopenharmony_ci<li><a href="#decompressor-options">Decompressor options</a></li>
1421cb0ef41Sopenharmony_ci</ul>
1431cb0ef41Sopenharmony_ci</li>
1441cb0ef41Sopenharmony_ci</ul>
1451cb0ef41Sopenharmony_ci</li>
1461cb0ef41Sopenharmony_ci<li><a href="#class-options">Class: <code>Options</code></a></li>
1471cb0ef41Sopenharmony_ci<li><a href="#class-brotlioptions">Class: <code>BrotliOptions</code></a></li>
1481cb0ef41Sopenharmony_ci<li><a href="#class-zlibbrotlicompress">Class: <code>zlib.BrotliCompress</code></a></li>
1491cb0ef41Sopenharmony_ci<li><a href="#class-zlibbrotlidecompress">Class: <code>zlib.BrotliDecompress</code></a></li>
1501cb0ef41Sopenharmony_ci<li><a href="#class-zlibdeflate">Class: <code>zlib.Deflate</code></a></li>
1511cb0ef41Sopenharmony_ci<li><a href="#class-zlibdeflateraw">Class: <code>zlib.DeflateRaw</code></a></li>
1521cb0ef41Sopenharmony_ci<li><a href="#class-zlibgunzip">Class: <code>zlib.Gunzip</code></a></li>
1531cb0ef41Sopenharmony_ci<li><a href="#class-zlibgzip">Class: <code>zlib.Gzip</code></a></li>
1541cb0ef41Sopenharmony_ci<li><a href="#class-zlibinflate">Class: <code>zlib.Inflate</code></a></li>
1551cb0ef41Sopenharmony_ci<li><a href="#class-zlibinflateraw">Class: <code>zlib.InflateRaw</code></a></li>
1561cb0ef41Sopenharmony_ci<li><a href="#class-zlibunzip">Class: <code>zlib.Unzip</code></a></li>
1571cb0ef41Sopenharmony_ci<li><a href="#class-zlibzlibbase">Class: <code>zlib.ZlibBase</code></a>
1581cb0ef41Sopenharmony_ci<ul>
1591cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#zlibbytesread"><code>zlib.bytesRead</code></a></span></li>
1601cb0ef41Sopenharmony_ci<li><a href="#zlibbyteswritten"><code>zlib.bytesWritten</code></a></li>
1611cb0ef41Sopenharmony_ci<li><a href="#zlibclosecallback"><code>zlib.close([callback])</code></a></li>
1621cb0ef41Sopenharmony_ci<li><a href="#zlibflushkind-callback"><code>zlib.flush([kind, ]callback)</code></a></li>
1631cb0ef41Sopenharmony_ci<li><a href="#zlibparamslevel-strategy-callback"><code>zlib.params(level, strategy, callback)</code></a></li>
1641cb0ef41Sopenharmony_ci<li><a href="#zlibreset"><code>zlib.reset()</code></a></li>
1651cb0ef41Sopenharmony_ci</ul>
1661cb0ef41Sopenharmony_ci</li>
1671cb0ef41Sopenharmony_ci<li><a href="#zlibconstants"><code>zlib.constants</code></a></li>
1681cb0ef41Sopenharmony_ci<li><a href="#zlibcreatebrotlicompressoptions"><code>zlib.createBrotliCompress([options])</code></a></li>
1691cb0ef41Sopenharmony_ci<li><a href="#zlibcreatebrotlidecompressoptions"><code>zlib.createBrotliDecompress([options])</code></a></li>
1701cb0ef41Sopenharmony_ci<li><a href="#zlibcreatedeflateoptions"><code>zlib.createDeflate([options])</code></a></li>
1711cb0ef41Sopenharmony_ci<li><a href="#zlibcreatedeflaterawoptions"><code>zlib.createDeflateRaw([options])</code></a></li>
1721cb0ef41Sopenharmony_ci<li><a href="#zlibcreategunzipoptions"><code>zlib.createGunzip([options])</code></a></li>
1731cb0ef41Sopenharmony_ci<li><a href="#zlibcreategzipoptions"><code>zlib.createGzip([options])</code></a></li>
1741cb0ef41Sopenharmony_ci<li><a href="#zlibcreateinflateoptions"><code>zlib.createInflate([options])</code></a></li>
1751cb0ef41Sopenharmony_ci<li><a href="#zlibcreateinflaterawoptions"><code>zlib.createInflateRaw([options])</code></a></li>
1761cb0ef41Sopenharmony_ci<li><a href="#zlibcreateunzipoptions"><code>zlib.createUnzip([options])</code></a></li>
1771cb0ef41Sopenharmony_ci<li><a href="#convenience-methods">Convenience methods</a>
1781cb0ef41Sopenharmony_ci<ul>
1791cb0ef41Sopenharmony_ci<li><a href="#zlibbrotlicompressbuffer-options-callback"><code>zlib.brotliCompress(buffer[, options], callback)</code></a></li>
1801cb0ef41Sopenharmony_ci<li><a href="#zlibbrotlicompresssyncbuffer-options"><code>zlib.brotliCompressSync(buffer[, options])</code></a></li>
1811cb0ef41Sopenharmony_ci<li><a href="#zlibbrotlidecompressbuffer-options-callback"><code>zlib.brotliDecompress(buffer[, options], callback)</code></a></li>
1821cb0ef41Sopenharmony_ci<li><a href="#zlibbrotlidecompresssyncbuffer-options"><code>zlib.brotliDecompressSync(buffer[, options])</code></a></li>
1831cb0ef41Sopenharmony_ci<li><a href="#zlibdeflatebuffer-options-callback"><code>zlib.deflate(buffer[, options], callback)</code></a></li>
1841cb0ef41Sopenharmony_ci<li><a href="#zlibdeflatesyncbuffer-options"><code>zlib.deflateSync(buffer[, options])</code></a></li>
1851cb0ef41Sopenharmony_ci<li><a href="#zlibdeflaterawbuffer-options-callback"><code>zlib.deflateRaw(buffer[, options], callback)</code></a></li>
1861cb0ef41Sopenharmony_ci<li><a href="#zlibdeflaterawsyncbuffer-options"><code>zlib.deflateRawSync(buffer[, options])</code></a></li>
1871cb0ef41Sopenharmony_ci<li><a href="#zlibgunzipbuffer-options-callback"><code>zlib.gunzip(buffer[, options], callback)</code></a></li>
1881cb0ef41Sopenharmony_ci<li><a href="#zlibgunzipsyncbuffer-options"><code>zlib.gunzipSync(buffer[, options])</code></a></li>
1891cb0ef41Sopenharmony_ci<li><a href="#zlibgzipbuffer-options-callback"><code>zlib.gzip(buffer[, options], callback)</code></a></li>
1901cb0ef41Sopenharmony_ci<li><a href="#zlibgzipsyncbuffer-options"><code>zlib.gzipSync(buffer[, options])</code></a></li>
1911cb0ef41Sopenharmony_ci<li><a href="#zlibinflatebuffer-options-callback"><code>zlib.inflate(buffer[, options], callback)</code></a></li>
1921cb0ef41Sopenharmony_ci<li><a href="#zlibinflatesyncbuffer-options"><code>zlib.inflateSync(buffer[, options])</code></a></li>
1931cb0ef41Sopenharmony_ci<li><a href="#zlibinflaterawbuffer-options-callback"><code>zlib.inflateRaw(buffer[, options], callback)</code></a></li>
1941cb0ef41Sopenharmony_ci<li><a href="#zlibinflaterawsyncbuffer-options"><code>zlib.inflateRawSync(buffer[, options])</code></a></li>
1951cb0ef41Sopenharmony_ci<li><a href="#zlibunzipbuffer-options-callback"><code>zlib.unzip(buffer[, options], callback)</code></a></li>
1961cb0ef41Sopenharmony_ci<li><a href="#zlibunzipsyncbuffer-options"><code>zlib.unzipSync(buffer[, options])</code></a></li>
1971cb0ef41Sopenharmony_ci</ul>
1981cb0ef41Sopenharmony_ci</li>
1991cb0ef41Sopenharmony_ci</ul>
2001cb0ef41Sopenharmony_ci</li>
2011cb0ef41Sopenharmony_ci</ul></div></div>
2021cb0ef41Sopenharmony_ci    </li>
2031cb0ef41Sopenharmony_ci  
2041cb0ef41Sopenharmony_ci            
2051cb0ef41Sopenharmony_ci    <li class="picker-header">
2061cb0ef41Sopenharmony_ci      <a href="#">
2071cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
2081cb0ef41Sopenharmony_ci        Index
2091cb0ef41Sopenharmony_ci      </a>
2101cb0ef41Sopenharmony_ci
2111cb0ef41Sopenharmony_ci      <div class="picker"><ul>
2121cb0ef41Sopenharmony_ci<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
2131cb0ef41Sopenharmony_ci<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
2141cb0ef41Sopenharmony_ci
2151cb0ef41Sopenharmony_ci      <li>
2161cb0ef41Sopenharmony_ci        <a href="index.html">Index</a>
2171cb0ef41Sopenharmony_ci      </li>
2181cb0ef41Sopenharmony_ci    </ul>
2191cb0ef41Sopenharmony_ci  
2201cb0ef41Sopenharmony_ci<hr class="line">
2211cb0ef41Sopenharmony_ci<ul>
2221cb0ef41Sopenharmony_ci<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
2231cb0ef41Sopenharmony_ci<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
2241cb0ef41Sopenharmony_ci<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
2251cb0ef41Sopenharmony_ci<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
2261cb0ef41Sopenharmony_ci<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
2271cb0ef41Sopenharmony_ci<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
2281cb0ef41Sopenharmony_ci<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
2291cb0ef41Sopenharmony_ci<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
2301cb0ef41Sopenharmony_ci<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
2311cb0ef41Sopenharmony_ci<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
2321cb0ef41Sopenharmony_ci<li><a href="console.html" class="nav-console">Console</a></li>
2331cb0ef41Sopenharmony_ci<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
2341cb0ef41Sopenharmony_ci<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
2351cb0ef41Sopenharmony_ci<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
2361cb0ef41Sopenharmony_ci<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
2371cb0ef41Sopenharmony_ci<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
2381cb0ef41Sopenharmony_ci<li><a href="dns.html" class="nav-dns">DNS</a></li>
2391cb0ef41Sopenharmony_ci<li><a href="domain.html" class="nav-domain">Domain</a></li>
2401cb0ef41Sopenharmony_ci<li><a href="errors.html" class="nav-errors">Errors</a></li>
2411cb0ef41Sopenharmony_ci<li><a href="events.html" class="nav-events">Events</a></li>
2421cb0ef41Sopenharmony_ci<li><a href="fs.html" class="nav-fs">File system</a></li>
2431cb0ef41Sopenharmony_ci<li><a href="globals.html" class="nav-globals">Globals</a></li>
2441cb0ef41Sopenharmony_ci<li><a href="http.html" class="nav-http">HTTP</a></li>
2451cb0ef41Sopenharmony_ci<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
2461cb0ef41Sopenharmony_ci<li><a href="https.html" class="nav-https">HTTPS</a></li>
2471cb0ef41Sopenharmony_ci<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
2481cb0ef41Sopenharmony_ci<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
2491cb0ef41Sopenharmony_ci<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
2501cb0ef41Sopenharmony_ci<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
2511cb0ef41Sopenharmony_ci<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
2521cb0ef41Sopenharmony_ci<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
2531cb0ef41Sopenharmony_ci<li><a href="net.html" class="nav-net">Net</a></li>
2541cb0ef41Sopenharmony_ci<li><a href="os.html" class="nav-os">OS</a></li>
2551cb0ef41Sopenharmony_ci<li><a href="path.html" class="nav-path">Path</a></li>
2561cb0ef41Sopenharmony_ci<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
2571cb0ef41Sopenharmony_ci<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
2581cb0ef41Sopenharmony_ci<li><a href="process.html" class="nav-process">Process</a></li>
2591cb0ef41Sopenharmony_ci<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
2601cb0ef41Sopenharmony_ci<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
2611cb0ef41Sopenharmony_ci<li><a href="readline.html" class="nav-readline">Readline</a></li>
2621cb0ef41Sopenharmony_ci<li><a href="repl.html" class="nav-repl">REPL</a></li>
2631cb0ef41Sopenharmony_ci<li><a href="report.html" class="nav-report">Report</a></li>
2641cb0ef41Sopenharmony_ci<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
2651cb0ef41Sopenharmony_ci<li><a href="stream.html" class="nav-stream">Stream</a></li>
2661cb0ef41Sopenharmony_ci<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
2671cb0ef41Sopenharmony_ci<li><a href="test.html" class="nav-test">Test runner</a></li>
2681cb0ef41Sopenharmony_ci<li><a href="timers.html" class="nav-timers">Timers</a></li>
2691cb0ef41Sopenharmony_ci<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
2701cb0ef41Sopenharmony_ci<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
2711cb0ef41Sopenharmony_ci<li><a href="tty.html" class="nav-tty">TTY</a></li>
2721cb0ef41Sopenharmony_ci<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
2731cb0ef41Sopenharmony_ci<li><a href="url.html" class="nav-url">URL</a></li>
2741cb0ef41Sopenharmony_ci<li><a href="util.html" class="nav-util">Utilities</a></li>
2751cb0ef41Sopenharmony_ci<li><a href="v8.html" class="nav-v8">V8</a></li>
2761cb0ef41Sopenharmony_ci<li><a href="vm.html" class="nav-vm">VM</a></li>
2771cb0ef41Sopenharmony_ci<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
2781cb0ef41Sopenharmony_ci<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
2791cb0ef41Sopenharmony_ci<li><a href="webstreams.html" class="nav-webstreams">Web Streams API</a></li>
2801cb0ef41Sopenharmony_ci<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
2811cb0ef41Sopenharmony_ci<li><a href="zlib.html" class="nav-zlib active">Zlib</a></li>
2821cb0ef41Sopenharmony_ci</ul>
2831cb0ef41Sopenharmony_ci<hr class="line">
2841cb0ef41Sopenharmony_ci<ul>
2851cb0ef41Sopenharmony_ci<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
2861cb0ef41Sopenharmony_ci</ul></div>
2871cb0ef41Sopenharmony_ci    </li>
2881cb0ef41Sopenharmony_ci  
2891cb0ef41Sopenharmony_ci            
2901cb0ef41Sopenharmony_ci    <li class="picker-header">
2911cb0ef41Sopenharmony_ci      <a href="#">
2921cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
2931cb0ef41Sopenharmony_ci        Other versions
2941cb0ef41Sopenharmony_ci      </a>
2951cb0ef41Sopenharmony_ci      <div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v21.x/api/zlib.html">21.x</a></li>
2961cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v20.x/api/zlib.html">20.x <b>LTS</b></a></li>
2971cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v19.x/api/zlib.html">19.x</a></li>
2981cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v18.x/api/zlib.html">18.x <b>LTS</b></a></li>
2991cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v17.x/api/zlib.html">17.x</a></li>
3001cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v16.x/api/zlib.html">16.x</a></li>
3011cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v15.x/api/zlib.html">15.x</a></li>
3021cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v14.x/api/zlib.html">14.x</a></li>
3031cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v13.x/api/zlib.html">13.x</a></li>
3041cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v12.x/api/zlib.html">12.x</a></li>
3051cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v11.x/api/zlib.html">11.x</a></li>
3061cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v10.x/api/zlib.html">10.x</a></li>
3071cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v9.x/api/zlib.html">9.x</a></li>
3081cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v8.x/api/zlib.html">8.x</a></li>
3091cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v7.x/api/zlib.html">7.x</a></li>
3101cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v6.x/api/zlib.html">6.x</a></li>
3111cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v5.x/api/zlib.html">5.x</a></li>
3121cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v4.x/api/zlib.html">4.x</a></li>
3131cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v0.12.x/api/zlib.html">0.12.x</a></li>
3141cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v0.10.x/api/zlib.html">0.10.x</a></li></ol></div>
3151cb0ef41Sopenharmony_ci    </li>
3161cb0ef41Sopenharmony_ci  
3171cb0ef41Sopenharmony_ci            <li class="picker-header">
3181cb0ef41Sopenharmony_ci              <a href="#">
3191cb0ef41Sopenharmony_ci                <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
3201cb0ef41Sopenharmony_ci                Options
3211cb0ef41Sopenharmony_ci              </a>
3221cb0ef41Sopenharmony_ci        
3231cb0ef41Sopenharmony_ci              <div class="picker">
3241cb0ef41Sopenharmony_ci                <ul>
3251cb0ef41Sopenharmony_ci                  <li>
3261cb0ef41Sopenharmony_ci                    <a href="all.html">View on single page</a>
3271cb0ef41Sopenharmony_ci                  </li>
3281cb0ef41Sopenharmony_ci                  <li>
3291cb0ef41Sopenharmony_ci                    <a href="zlib.json">View as JSON</a>
3301cb0ef41Sopenharmony_ci                  </li>
3311cb0ef41Sopenharmony_ci                  <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/main/doc/api/zlib.md">Edit on GitHub</a></li>    
3321cb0ef41Sopenharmony_ci                </ul>
3331cb0ef41Sopenharmony_ci              </div>
3341cb0ef41Sopenharmony_ci            </li>
3351cb0ef41Sopenharmony_ci          </ul>
3361cb0ef41Sopenharmony_ci        </div>
3371cb0ef41Sopenharmony_ci        <hr>
3381cb0ef41Sopenharmony_ci      </header>
3391cb0ef41Sopenharmony_ci
3401cb0ef41Sopenharmony_ci      <details id="toc" open><summary>Table of contents</summary><ul>
3411cb0ef41Sopenharmony_ci<li><span class="stability_2"><a href="#zlib">Zlib</a></span>
3421cb0ef41Sopenharmony_ci<ul>
3431cb0ef41Sopenharmony_ci<li><a href="#threadpool-usage-and-performance-considerations">Threadpool usage and performance considerations</a></li>
3441cb0ef41Sopenharmony_ci<li><a href="#compressing-http-requests-and-responses">Compressing HTTP requests and responses</a></li>
3451cb0ef41Sopenharmony_ci<li><a href="#memory-usage-tuning">Memory usage tuning</a>
3461cb0ef41Sopenharmony_ci<ul>
3471cb0ef41Sopenharmony_ci<li><a href="#for-zlib-based-streams">For zlib-based streams</a></li>
3481cb0ef41Sopenharmony_ci<li><a href="#for-brotli-based-streams">For Brotli-based streams</a></li>
3491cb0ef41Sopenharmony_ci</ul>
3501cb0ef41Sopenharmony_ci</li>
3511cb0ef41Sopenharmony_ci<li><a href="#flushing">Flushing</a></li>
3521cb0ef41Sopenharmony_ci<li><a href="#constants">Constants</a>
3531cb0ef41Sopenharmony_ci<ul>
3541cb0ef41Sopenharmony_ci<li><a href="#zlib-constants">zlib constants</a></li>
3551cb0ef41Sopenharmony_ci<li><a href="#brotli-constants">Brotli constants</a>
3561cb0ef41Sopenharmony_ci<ul>
3571cb0ef41Sopenharmony_ci<li><a href="#flush-operations">Flush operations</a></li>
3581cb0ef41Sopenharmony_ci<li><a href="#compressor-options">Compressor options</a></li>
3591cb0ef41Sopenharmony_ci<li><a href="#decompressor-options">Decompressor options</a></li>
3601cb0ef41Sopenharmony_ci</ul>
3611cb0ef41Sopenharmony_ci</li>
3621cb0ef41Sopenharmony_ci</ul>
3631cb0ef41Sopenharmony_ci</li>
3641cb0ef41Sopenharmony_ci<li><a href="#class-options">Class: <code>Options</code></a></li>
3651cb0ef41Sopenharmony_ci<li><a href="#class-brotlioptions">Class: <code>BrotliOptions</code></a></li>
3661cb0ef41Sopenharmony_ci<li><a href="#class-zlibbrotlicompress">Class: <code>zlib.BrotliCompress</code></a></li>
3671cb0ef41Sopenharmony_ci<li><a href="#class-zlibbrotlidecompress">Class: <code>zlib.BrotliDecompress</code></a></li>
3681cb0ef41Sopenharmony_ci<li><a href="#class-zlibdeflate">Class: <code>zlib.Deflate</code></a></li>
3691cb0ef41Sopenharmony_ci<li><a href="#class-zlibdeflateraw">Class: <code>zlib.DeflateRaw</code></a></li>
3701cb0ef41Sopenharmony_ci<li><a href="#class-zlibgunzip">Class: <code>zlib.Gunzip</code></a></li>
3711cb0ef41Sopenharmony_ci<li><a href="#class-zlibgzip">Class: <code>zlib.Gzip</code></a></li>
3721cb0ef41Sopenharmony_ci<li><a href="#class-zlibinflate">Class: <code>zlib.Inflate</code></a></li>
3731cb0ef41Sopenharmony_ci<li><a href="#class-zlibinflateraw">Class: <code>zlib.InflateRaw</code></a></li>
3741cb0ef41Sopenharmony_ci<li><a href="#class-zlibunzip">Class: <code>zlib.Unzip</code></a></li>
3751cb0ef41Sopenharmony_ci<li><a href="#class-zlibzlibbase">Class: <code>zlib.ZlibBase</code></a>
3761cb0ef41Sopenharmony_ci<ul>
3771cb0ef41Sopenharmony_ci<li><span class="stability_0"><a href="#zlibbytesread"><code>zlib.bytesRead</code></a></span></li>
3781cb0ef41Sopenharmony_ci<li><a href="#zlibbyteswritten"><code>zlib.bytesWritten</code></a></li>
3791cb0ef41Sopenharmony_ci<li><a href="#zlibclosecallback"><code>zlib.close([callback])</code></a></li>
3801cb0ef41Sopenharmony_ci<li><a href="#zlibflushkind-callback"><code>zlib.flush([kind, ]callback)</code></a></li>
3811cb0ef41Sopenharmony_ci<li><a href="#zlibparamslevel-strategy-callback"><code>zlib.params(level, strategy, callback)</code></a></li>
3821cb0ef41Sopenharmony_ci<li><a href="#zlibreset"><code>zlib.reset()</code></a></li>
3831cb0ef41Sopenharmony_ci</ul>
3841cb0ef41Sopenharmony_ci</li>
3851cb0ef41Sopenharmony_ci<li><a href="#zlibconstants"><code>zlib.constants</code></a></li>
3861cb0ef41Sopenharmony_ci<li><a href="#zlibcreatebrotlicompressoptions"><code>zlib.createBrotliCompress([options])</code></a></li>
3871cb0ef41Sopenharmony_ci<li><a href="#zlibcreatebrotlidecompressoptions"><code>zlib.createBrotliDecompress([options])</code></a></li>
3881cb0ef41Sopenharmony_ci<li><a href="#zlibcreatedeflateoptions"><code>zlib.createDeflate([options])</code></a></li>
3891cb0ef41Sopenharmony_ci<li><a href="#zlibcreatedeflaterawoptions"><code>zlib.createDeflateRaw([options])</code></a></li>
3901cb0ef41Sopenharmony_ci<li><a href="#zlibcreategunzipoptions"><code>zlib.createGunzip([options])</code></a></li>
3911cb0ef41Sopenharmony_ci<li><a href="#zlibcreategzipoptions"><code>zlib.createGzip([options])</code></a></li>
3921cb0ef41Sopenharmony_ci<li><a href="#zlibcreateinflateoptions"><code>zlib.createInflate([options])</code></a></li>
3931cb0ef41Sopenharmony_ci<li><a href="#zlibcreateinflaterawoptions"><code>zlib.createInflateRaw([options])</code></a></li>
3941cb0ef41Sopenharmony_ci<li><a href="#zlibcreateunzipoptions"><code>zlib.createUnzip([options])</code></a></li>
3951cb0ef41Sopenharmony_ci<li><a href="#convenience-methods">Convenience methods</a>
3961cb0ef41Sopenharmony_ci<ul>
3971cb0ef41Sopenharmony_ci<li><a href="#zlibbrotlicompressbuffer-options-callback"><code>zlib.brotliCompress(buffer[, options], callback)</code></a></li>
3981cb0ef41Sopenharmony_ci<li><a href="#zlibbrotlicompresssyncbuffer-options"><code>zlib.brotliCompressSync(buffer[, options])</code></a></li>
3991cb0ef41Sopenharmony_ci<li><a href="#zlibbrotlidecompressbuffer-options-callback"><code>zlib.brotliDecompress(buffer[, options], callback)</code></a></li>
4001cb0ef41Sopenharmony_ci<li><a href="#zlibbrotlidecompresssyncbuffer-options"><code>zlib.brotliDecompressSync(buffer[, options])</code></a></li>
4011cb0ef41Sopenharmony_ci<li><a href="#zlibdeflatebuffer-options-callback"><code>zlib.deflate(buffer[, options], callback)</code></a></li>
4021cb0ef41Sopenharmony_ci<li><a href="#zlibdeflatesyncbuffer-options"><code>zlib.deflateSync(buffer[, options])</code></a></li>
4031cb0ef41Sopenharmony_ci<li><a href="#zlibdeflaterawbuffer-options-callback"><code>zlib.deflateRaw(buffer[, options], callback)</code></a></li>
4041cb0ef41Sopenharmony_ci<li><a href="#zlibdeflaterawsyncbuffer-options"><code>zlib.deflateRawSync(buffer[, options])</code></a></li>
4051cb0ef41Sopenharmony_ci<li><a href="#zlibgunzipbuffer-options-callback"><code>zlib.gunzip(buffer[, options], callback)</code></a></li>
4061cb0ef41Sopenharmony_ci<li><a href="#zlibgunzipsyncbuffer-options"><code>zlib.gunzipSync(buffer[, options])</code></a></li>
4071cb0ef41Sopenharmony_ci<li><a href="#zlibgzipbuffer-options-callback"><code>zlib.gzip(buffer[, options], callback)</code></a></li>
4081cb0ef41Sopenharmony_ci<li><a href="#zlibgzipsyncbuffer-options"><code>zlib.gzipSync(buffer[, options])</code></a></li>
4091cb0ef41Sopenharmony_ci<li><a href="#zlibinflatebuffer-options-callback"><code>zlib.inflate(buffer[, options], callback)</code></a></li>
4101cb0ef41Sopenharmony_ci<li><a href="#zlibinflatesyncbuffer-options"><code>zlib.inflateSync(buffer[, options])</code></a></li>
4111cb0ef41Sopenharmony_ci<li><a href="#zlibinflaterawbuffer-options-callback"><code>zlib.inflateRaw(buffer[, options], callback)</code></a></li>
4121cb0ef41Sopenharmony_ci<li><a href="#zlibinflaterawsyncbuffer-options"><code>zlib.inflateRawSync(buffer[, options])</code></a></li>
4131cb0ef41Sopenharmony_ci<li><a href="#zlibunzipbuffer-options-callback"><code>zlib.unzip(buffer[, options], callback)</code></a></li>
4141cb0ef41Sopenharmony_ci<li><a href="#zlibunzipsyncbuffer-options"><code>zlib.unzipSync(buffer[, options])</code></a></li>
4151cb0ef41Sopenharmony_ci</ul>
4161cb0ef41Sopenharmony_ci</li>
4171cb0ef41Sopenharmony_ci</ul>
4181cb0ef41Sopenharmony_ci</li>
4191cb0ef41Sopenharmony_ci</ul></details>
4201cb0ef41Sopenharmony_ci
4211cb0ef41Sopenharmony_ci      <div id="apicontent">
4221cb0ef41Sopenharmony_ci        <h2>Zlib<span><a class="mark" href="#zlib" id="zlib">#</a></span><a aria-hidden="true" class="legacy" id="zlib_zlib"></a></h2>
4231cb0ef41Sopenharmony_ci
4241cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_2"><a href="documentation.html#stability-index">Stability: 2</a> - Stable</div><p></p>
4251cb0ef41Sopenharmony_ci<p><strong>Source Code:</strong> <a href="https://github.com/nodejs/node/blob/v18.20.1/lib/zlib.js">lib/zlib.js</a></p>
4261cb0ef41Sopenharmony_ci<p>The <code>node:zlib</code> module provides compression functionality implemented using
4271cb0ef41Sopenharmony_ciGzip, Deflate/Inflate, and Brotli.</p>
4281cb0ef41Sopenharmony_ci<p>To access it:</p>
4291cb0ef41Sopenharmony_ci<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>
4301cb0ef41Sopenharmony_ci<p>Compression and decompression are built around the Node.js <a href="stream.html">Streams API</a>.</p>
4311cb0ef41Sopenharmony_ci<p>Compressing or decompressing a stream (such as a file) can be accomplished by
4321cb0ef41Sopenharmony_cipiping the source stream through a <code>zlib</code> <code>Transform</code> stream into a destination
4331cb0ef41Sopenharmony_cistream:</p>
4341cb0ef41Sopenharmony_ci<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>);
4351cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { pipeline } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream'</span>);
4361cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> {
4371cb0ef41Sopenharmony_ci  createReadStream,
4381cb0ef41Sopenharmony_ci  createWriteStream,
4391cb0ef41Sopenharmony_ci} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:fs'</span>);
4401cb0ef41Sopenharmony_ci
4411cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> gzip = <span class="hljs-title function_">createGzip</span>();
4421cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> source = <span class="hljs-title function_">createReadStream</span>(<span class="hljs-string">'input.txt'</span>);
4431cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> destination = <span class="hljs-title function_">createWriteStream</span>(<span class="hljs-string">'input.txt.gz'</span>);
4441cb0ef41Sopenharmony_ci
4451cb0ef41Sopenharmony_ci<span class="hljs-title function_">pipeline</span>(source, gzip, destination, <span class="hljs-function">(<span class="hljs-params">err</span>) =></span> {
4461cb0ef41Sopenharmony_ci  <span class="hljs-keyword">if</span> (err) {
4471cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
4481cb0ef41Sopenharmony_ci    process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
4491cb0ef41Sopenharmony_ci  }
4501cb0ef41Sopenharmony_ci});
4511cb0ef41Sopenharmony_ci
4521cb0ef41Sopenharmony_ci<span class="hljs-comment">// Or, Promisified</span>
4531cb0ef41Sopenharmony_ci
4541cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { promisify } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
4551cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> pipe = <span class="hljs-title function_">promisify</span>(pipeline);
4561cb0ef41Sopenharmony_ci
4571cb0ef41Sopenharmony_ci<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>) {
4581cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> gzip = <span class="hljs-title function_">createGzip</span>();
4591cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> source = <span class="hljs-title function_">createReadStream</span>(input);
4601cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> destination = <span class="hljs-title function_">createWriteStream</span>(output);
4611cb0ef41Sopenharmony_ci  <span class="hljs-keyword">await</span> <span class="hljs-title function_">pipe</span>(source, gzip, destination);
4621cb0ef41Sopenharmony_ci}
4631cb0ef41Sopenharmony_ci
4641cb0ef41Sopenharmony_ci<span class="hljs-title function_">do_gzip</span>(<span class="hljs-string">'input.txt'</span>, <span class="hljs-string">'input.txt.gz'</span>)
4651cb0ef41Sopenharmony_ci  .<span class="hljs-title function_">catch</span>(<span class="hljs-function">(<span class="hljs-params">err</span>) =></span> {
4661cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
4671cb0ef41Sopenharmony_ci    process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
4681cb0ef41Sopenharmony_ci  });</code> <button class="copy-button">copy</button></pre>
4691cb0ef41Sopenharmony_ci<p>It is also possible to compress or decompress data in a single step:</p>
4701cb0ef41Sopenharmony_ci<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>);
4711cb0ef41Sopenharmony_ci
4721cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> input = <span class="hljs-string">'.................................'</span>;
4731cb0ef41Sopenharmony_ci<span class="hljs-title function_">deflate</span>(input, <span class="hljs-function">(<span class="hljs-params">err, buffer</span>) =></span> {
4741cb0ef41Sopenharmony_ci  <span class="hljs-keyword">if</span> (err) {
4751cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
4761cb0ef41Sopenharmony_ci    process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
4771cb0ef41Sopenharmony_ci  }
4781cb0ef41Sopenharmony_ci  <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>));
4791cb0ef41Sopenharmony_ci});
4801cb0ef41Sopenharmony_ci
4811cb0ef41Sopenharmony_ci<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>);
4821cb0ef41Sopenharmony_ci<span class="hljs-title function_">unzip</span>(buffer, <span class="hljs-function">(<span class="hljs-params">err, buffer</span>) =></span> {
4831cb0ef41Sopenharmony_ci  <span class="hljs-keyword">if</span> (err) {
4841cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
4851cb0ef41Sopenharmony_ci    process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
4861cb0ef41Sopenharmony_ci  }
4871cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(buffer.<span class="hljs-title function_">toString</span>());
4881cb0ef41Sopenharmony_ci});
4891cb0ef41Sopenharmony_ci
4901cb0ef41Sopenharmony_ci<span class="hljs-comment">// Or, Promisified</span>
4911cb0ef41Sopenharmony_ci
4921cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { promisify } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
4931cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> do_unzip = <span class="hljs-title function_">promisify</span>(unzip);
4941cb0ef41Sopenharmony_ci
4951cb0ef41Sopenharmony_ci<span class="hljs-title function_">do_unzip</span>(buffer)
4961cb0ef41Sopenharmony_ci  .<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>()))
4971cb0ef41Sopenharmony_ci  .<span class="hljs-title function_">catch</span>(<span class="hljs-function">(<span class="hljs-params">err</span>) =></span> {
4981cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
4991cb0ef41Sopenharmony_ci    process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
5001cb0ef41Sopenharmony_ci  });</code> <button class="copy-button">copy</button></pre>
5011cb0ef41Sopenharmony_ci<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>
5021cb0ef41Sopenharmony_ci<p>All <code>zlib</code> APIs, except those that are explicitly synchronous, use the Node.js
5031cb0ef41Sopenharmony_ciinternal threadpool. This can lead to surprising effects and performance
5041cb0ef41Sopenharmony_cilimitations in some applications.</p>
5051cb0ef41Sopenharmony_ci<p>Creating and using a large number of zlib objects simultaneously can cause
5061cb0ef41Sopenharmony_cisignificant memory fragmentation.</p>
5071cb0ef41Sopenharmony_ci<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>);
5081cb0ef41Sopenharmony_ci
5091cb0ef41Sopenharmony_ci<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>);
5101cb0ef41Sopenharmony_ci
5111cb0ef41Sopenharmony_ci<span class="hljs-comment">// WARNING: DO NOT DO THIS!</span>
5121cb0ef41Sopenharmony_ci<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i &#x3C; <span class="hljs-number">30000</span>; ++i) {
5131cb0ef41Sopenharmony_ci  zlib.<span class="hljs-title function_">deflate</span>(payload, <span class="hljs-function">(<span class="hljs-params">err, buffer</span>) =></span> {});
5141cb0ef41Sopenharmony_ci}</code> <button class="copy-button">copy</button></pre>
5151cb0ef41Sopenharmony_ci<p>In the preceding example, 30,000 deflate instances are created concurrently.
5161cb0ef41Sopenharmony_ciBecause of how some operating systems handle memory allocation and
5171cb0ef41Sopenharmony_cideallocation, this may lead to significant memory fragmentation.</p>
5181cb0ef41Sopenharmony_ci<p>It is strongly recommended that the results of compression
5191cb0ef41Sopenharmony_cioperations be cached to avoid duplication of effort.</p>
5201cb0ef41Sopenharmony_ci</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>
5211cb0ef41Sopenharmony_ci<p>The <code>node:zlib</code> module can be used to implement support for the <code>gzip</code>, <code>deflate</code>
5221cb0ef41Sopenharmony_ciand <code>br</code> content-encoding mechanisms defined by
5231cb0ef41Sopenharmony_ci<a href="https://tools.ietf.org/html/rfc7230#section-4.2">HTTP</a>.</p>
5241cb0ef41Sopenharmony_ci<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
5251cb0ef41Sopenharmony_cithe 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>
5261cb0ef41Sopenharmony_ciheader is used to identify the compression encodings actually applied to a
5271cb0ef41Sopenharmony_cimessage.</p>
5281cb0ef41Sopenharmony_ci<p>The examples given below are drastically simplified to show the basic concept.
5291cb0ef41Sopenharmony_ciUsing <code>zlib</code> encoding can be expensive, and the results ought to be cached.
5301cb0ef41Sopenharmony_ciSee <a href="#memory-usage-tuning">Memory usage tuning</a> for more information on the speed/memory/compression
5311cb0ef41Sopenharmony_citradeoffs involved in <code>zlib</code> usage.</p>
5321cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-comment">// Client request example</span>
5331cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> zlib = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:zlib'</span>);
5341cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:http'</span>);
5351cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:fs'</span>);
5361cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { pipeline } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream'</span>);
5371cb0ef41Sopenharmony_ci
5381cb0ef41Sopenharmony_ci<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>,
5391cb0ef41Sopenharmony_ci                           <span class="hljs-attr">path</span>: <span class="hljs-string">'/'</span>,
5401cb0ef41Sopenharmony_ci                           <span class="hljs-attr">port</span>: <span class="hljs-number">80</span>,
5411cb0ef41Sopenharmony_ci                           <span class="hljs-attr">headers</span>: { <span class="hljs-string">'Accept-Encoding'</span>: <span class="hljs-string">'br,gzip,deflate'</span> } });
5421cb0ef41Sopenharmony_cirequest.<span class="hljs-title function_">on</span>(<span class="hljs-string">'response'</span>, <span class="hljs-function">(<span class="hljs-params">response</span>) =></span> {
5431cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> output = fs.<span class="hljs-title function_">createWriteStream</span>(<span class="hljs-string">'example.com_index.html'</span>);
5441cb0ef41Sopenharmony_ci
5451cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> <span class="hljs-title function_">onError</span> = (<span class="hljs-params">err</span>) => {
5461cb0ef41Sopenharmony_ci    <span class="hljs-keyword">if</span> (err) {
5471cb0ef41Sopenharmony_ci      <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
5481cb0ef41Sopenharmony_ci      process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
5491cb0ef41Sopenharmony_ci    }
5501cb0ef41Sopenharmony_ci  };
5511cb0ef41Sopenharmony_ci
5521cb0ef41Sopenharmony_ci  <span class="hljs-keyword">switch</span> (response.<span class="hljs-property">headers</span>[<span class="hljs-string">'content-encoding'</span>]) {
5531cb0ef41Sopenharmony_ci    <span class="hljs-keyword">case</span> <span class="hljs-string">'br'</span>:
5541cb0ef41Sopenharmony_ci      <span class="hljs-title function_">pipeline</span>(response, zlib.<span class="hljs-title function_">createBrotliDecompress</span>(), output, onError);
5551cb0ef41Sopenharmony_ci      <span class="hljs-keyword">break</span>;
5561cb0ef41Sopenharmony_ci    <span class="hljs-comment">// Or, just use zlib.createUnzip() to handle both of the following cases:</span>
5571cb0ef41Sopenharmony_ci    <span class="hljs-keyword">case</span> <span class="hljs-string">'gzip'</span>:
5581cb0ef41Sopenharmony_ci      <span class="hljs-title function_">pipeline</span>(response, zlib.<span class="hljs-title function_">createGunzip</span>(), output, onError);
5591cb0ef41Sopenharmony_ci      <span class="hljs-keyword">break</span>;
5601cb0ef41Sopenharmony_ci    <span class="hljs-keyword">case</span> <span class="hljs-string">'deflate'</span>:
5611cb0ef41Sopenharmony_ci      <span class="hljs-title function_">pipeline</span>(response, zlib.<span class="hljs-title function_">createInflate</span>(), output, onError);
5621cb0ef41Sopenharmony_ci      <span class="hljs-keyword">break</span>;
5631cb0ef41Sopenharmony_ci    <span class="hljs-attr">default</span>:
5641cb0ef41Sopenharmony_ci      <span class="hljs-title function_">pipeline</span>(response, output, onError);
5651cb0ef41Sopenharmony_ci      <span class="hljs-keyword">break</span>;
5661cb0ef41Sopenharmony_ci  }
5671cb0ef41Sopenharmony_ci});</code> <button class="copy-button">copy</button></pre>
5681cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-comment">// server example</span>
5691cb0ef41Sopenharmony_ci<span class="hljs-comment">// Running a gzip operation on every request is quite expensive.</span>
5701cb0ef41Sopenharmony_ci<span class="hljs-comment">// It would be much more efficient to cache the compressed buffer.</span>
5711cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> zlib = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:zlib'</span>);
5721cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:http'</span>);
5731cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> fs = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:fs'</span>);
5741cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { pipeline } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream'</span>);
5751cb0ef41Sopenharmony_ci
5761cb0ef41Sopenharmony_cihttp.<span class="hljs-title function_">createServer</span>(<span class="hljs-function">(<span class="hljs-params">request, response</span>) =></span> {
5771cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> raw = fs.<span class="hljs-title function_">createReadStream</span>(<span class="hljs-string">'index.html'</span>);
5781cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Store both a compressed and an uncompressed version of the resource.</span>
5791cb0ef41Sopenharmony_ci  response.<span class="hljs-title function_">setHeader</span>(<span class="hljs-string">'Vary'</span>, <span class="hljs-string">'Accept-Encoding'</span>);
5801cb0ef41Sopenharmony_ci  <span class="hljs-keyword">let</span> acceptEncoding = request.<span class="hljs-property">headers</span>[<span class="hljs-string">'accept-encoding'</span>];
5811cb0ef41Sopenharmony_ci  <span class="hljs-keyword">if</span> (!acceptEncoding) {
5821cb0ef41Sopenharmony_ci    acceptEncoding = <span class="hljs-string">''</span>;
5831cb0ef41Sopenharmony_ci  }
5841cb0ef41Sopenharmony_ci
5851cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> <span class="hljs-title function_">onError</span> = (<span class="hljs-params">err</span>) => {
5861cb0ef41Sopenharmony_ci    <span class="hljs-keyword">if</span> (err) {
5871cb0ef41Sopenharmony_ci      <span class="hljs-comment">// If an error occurs, there's not much we can do because</span>
5881cb0ef41Sopenharmony_ci      <span class="hljs-comment">// the server has already sent the 200 response code and</span>
5891cb0ef41Sopenharmony_ci      <span class="hljs-comment">// some amount of data has already been sent to the client.</span>
5901cb0ef41Sopenharmony_ci      <span class="hljs-comment">// The best we can do is terminate the response immediately</span>
5911cb0ef41Sopenharmony_ci      <span class="hljs-comment">// and log the error.</span>
5921cb0ef41Sopenharmony_ci      response.<span class="hljs-title function_">end</span>();
5931cb0ef41Sopenharmony_ci      <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
5941cb0ef41Sopenharmony_ci    }
5951cb0ef41Sopenharmony_ci  };
5961cb0ef41Sopenharmony_ci
5971cb0ef41Sopenharmony_ci  <span class="hljs-comment">// Note: This is not a conformant accept-encoding parser.</span>
5981cb0ef41Sopenharmony_ci  <span class="hljs-comment">// See https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3</span>
5991cb0ef41Sopenharmony_ci  <span class="hljs-keyword">if</span> (<span class="hljs-regexp">/\bdeflate\b/</span>.<span class="hljs-title function_">test</span>(acceptEncoding)) {
6001cb0ef41Sopenharmony_ci    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> });
6011cb0ef41Sopenharmony_ci    <span class="hljs-title function_">pipeline</span>(raw, zlib.<span class="hljs-title function_">createDeflate</span>(), response, onError);
6021cb0ef41Sopenharmony_ci  } <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)) {
6031cb0ef41Sopenharmony_ci    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> });
6041cb0ef41Sopenharmony_ci    <span class="hljs-title function_">pipeline</span>(raw, zlib.<span class="hljs-title function_">createGzip</span>(), response, onError);
6051cb0ef41Sopenharmony_ci  } <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)) {
6061cb0ef41Sopenharmony_ci    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> });
6071cb0ef41Sopenharmony_ci    <span class="hljs-title function_">pipeline</span>(raw, zlib.<span class="hljs-title function_">createBrotliCompress</span>(), response, onError);
6081cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">else</span> {
6091cb0ef41Sopenharmony_ci    response.<span class="hljs-title function_">writeHead</span>(<span class="hljs-number">200</span>, {});
6101cb0ef41Sopenharmony_ci    <span class="hljs-title function_">pipeline</span>(raw, response, onError);
6111cb0ef41Sopenharmony_ci  }
6121cb0ef41Sopenharmony_ci}).<span class="hljs-title function_">listen</span>(<span class="hljs-number">1337</span>);</code> <button class="copy-button">copy</button></pre>
6131cb0ef41Sopenharmony_ci<p>By default, the <code>zlib</code> methods will throw an error when decompressing
6141cb0ef41Sopenharmony_citruncated data. However, if it is known that the data is incomplete, or
6151cb0ef41Sopenharmony_cithe desire is to inspect only the beginning of a compressed file, it is
6161cb0ef41Sopenharmony_cipossible to suppress the default error handling by changing the flushing
6171cb0ef41Sopenharmony_cimethod that is used to decompress the last chunk of input data:</p>
6181cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-comment">// This is a truncated version of the buffer from the above examples</span>
6191cb0ef41Sopenharmony_ci<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>);
6201cb0ef41Sopenharmony_ci
6211cb0ef41Sopenharmony_cizlib.<span class="hljs-title function_">unzip</span>(
6221cb0ef41Sopenharmony_ci  buffer,
6231cb0ef41Sopenharmony_ci  <span class="hljs-comment">// For Brotli, the equivalent is zlib.constants.BROTLI_OPERATION_FLUSH.</span>
6241cb0ef41Sopenharmony_ci  { <span class="hljs-attr">finishFlush</span>: zlib.<span class="hljs-property">constants</span>.<span class="hljs-property">Z_SYNC_FLUSH</span> },
6251cb0ef41Sopenharmony_ci  <span class="hljs-function">(<span class="hljs-params">err, buffer</span>) =></span> {
6261cb0ef41Sopenharmony_ci    <span class="hljs-keyword">if</span> (err) {
6271cb0ef41Sopenharmony_ci      <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
6281cb0ef41Sopenharmony_ci      process.<span class="hljs-property">exitCode</span> = <span class="hljs-number">1</span>;
6291cb0ef41Sopenharmony_ci    }
6301cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(buffer.<span class="hljs-title function_">toString</span>());
6311cb0ef41Sopenharmony_ci  });</code> <button class="copy-button">copy</button></pre>
6321cb0ef41Sopenharmony_ci<p>This will not change the behavior in other error-throwing situations, e.g.
6331cb0ef41Sopenharmony_ciwhen the input data has an invalid format. Using this method, it will not be
6341cb0ef41Sopenharmony_cipossible to determine whether the input ended prematurely or lacks the
6351cb0ef41Sopenharmony_ciintegrity checks, making it necessary to manually check that the
6361cb0ef41Sopenharmony_cidecompressed result is valid.</p>
6371cb0ef41Sopenharmony_ci</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>
6381cb0ef41Sopenharmony_ci
6391cb0ef41Sopenharmony_ci<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>
6401cb0ef41Sopenharmony_ci<p>From <code>zlib/zconf.h</code>, modified for Node.js usage:</p>
6411cb0ef41Sopenharmony_ci<p>The memory requirements for deflate are (in bytes):</p>
6421cb0ef41Sopenharmony_ci<!-- eslint-disable semi -->
6431cb0ef41Sopenharmony_ci<pre><code class="language-js">(<span class="hljs-number">1</span> &#x3C;&#x3C; (windowBits + <span class="hljs-number">2</span>)) + (<span class="hljs-number">1</span> &#x3C;&#x3C; (memLevel + <span class="hljs-number">9</span>))</code> <button class="copy-button">copy</button></pre>
6441cb0ef41Sopenharmony_ci<p>That is: 128K for <code>windowBits</code> = 15 + 128K for <code>memLevel</code> = 8
6451cb0ef41Sopenharmony_ci(default values) plus a few kilobytes for small objects.</p>
6461cb0ef41Sopenharmony_ci<p>For example, to reduce the default memory requirements from 256K to 128K, the
6471cb0ef41Sopenharmony_cioptions should be set to:</p>
6481cb0ef41Sopenharmony_ci<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>
6491cb0ef41Sopenharmony_ci<p>This will, however, generally degrade compression.</p>
6501cb0ef41Sopenharmony_ci<p>The memory requirements for inflate are (in bytes) <code>1 &#x3C;&#x3C; windowBits</code>.
6511cb0ef41Sopenharmony_ciThat is, 32K for <code>windowBits</code> = 15 (default value) plus a few kilobytes
6521cb0ef41Sopenharmony_cifor small objects.</p>
6531cb0ef41Sopenharmony_ci<p>This is in addition to a single internal output slab buffer of size
6541cb0ef41Sopenharmony_ci<code>chunkSize</code>, which defaults to 16K.</p>
6551cb0ef41Sopenharmony_ci<p>The speed of <code>zlib</code> compression is affected most dramatically by the
6561cb0ef41Sopenharmony_ci<code>level</code> setting. A higher level will result in better compression, but
6571cb0ef41Sopenharmony_ciwill take longer to complete. A lower level will result in less
6581cb0ef41Sopenharmony_cicompression, but will be much faster.</p>
6591cb0ef41Sopenharmony_ci<p>In general, greater memory usage options will mean that Node.js has to make
6601cb0ef41Sopenharmony_cifewer calls to <code>zlib</code> because it will be able to process more data on
6611cb0ef41Sopenharmony_cieach <code>write</code> operation. So, this is another factor that affects the
6621cb0ef41Sopenharmony_cispeed, at the cost of memory usage.</p>
6631cb0ef41Sopenharmony_ci<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>
6641cb0ef41Sopenharmony_ci<p>There are equivalents to the zlib options for Brotli-based streams, although
6651cb0ef41Sopenharmony_cithese options have different ranges than the zlib ones:</p>
6661cb0ef41Sopenharmony_ci<ul>
6671cb0ef41Sopenharmony_ci<li>zlib's <code>level</code> option matches Brotli's <code>BROTLI_PARAM_QUALITY</code> option.</li>
6681cb0ef41Sopenharmony_ci<li>zlib's <code>windowBits</code> option matches Brotli's <code>BROTLI_PARAM_LGWIN</code> option.</li>
6691cb0ef41Sopenharmony_ci</ul>
6701cb0ef41Sopenharmony_ci<p>See <a href="#brotli-constants">below</a> for more details on Brotli-specific options.</p>
6711cb0ef41Sopenharmony_ci</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>
6721cb0ef41Sopenharmony_ci<p>Calling <a href="#zlibflushkind-callback"><code>.flush()</code></a> on a compression stream will make <code>zlib</code> return as much
6731cb0ef41Sopenharmony_cioutput as currently possible. This may come at the cost of degraded compression
6741cb0ef41Sopenharmony_ciquality, but can be useful when data needs to be available as soon as possible.</p>
6751cb0ef41Sopenharmony_ci<p>In the following example, <code>flush()</code> is used to write a compressed partial
6761cb0ef41Sopenharmony_ciHTTP response to the client:</p>
6771cb0ef41Sopenharmony_ci<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>);
6781cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> http = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:http'</span>);
6791cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { pipeline } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream'</span>);
6801cb0ef41Sopenharmony_ci
6811cb0ef41Sopenharmony_cihttp.<span class="hljs-title function_">createServer</span>(<span class="hljs-function">(<span class="hljs-params">request, response</span>) =></span> {
6821cb0ef41Sopenharmony_ci  <span class="hljs-comment">// For the sake of simplicity, the Accept-Encoding checks are omitted.</span>
6831cb0ef41Sopenharmony_ci  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> });
6841cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> output = zlib.<span class="hljs-title function_">createGzip</span>();
6851cb0ef41Sopenharmony_ci  <span class="hljs-keyword">let</span> i;
6861cb0ef41Sopenharmony_ci
6871cb0ef41Sopenharmony_ci  <span class="hljs-title function_">pipeline</span>(output, response, <span class="hljs-function">(<span class="hljs-params">err</span>) =></span> {
6881cb0ef41Sopenharmony_ci    <span class="hljs-keyword">if</span> (err) {
6891cb0ef41Sopenharmony_ci      <span class="hljs-comment">// If an error occurs, there's not much we can do because</span>
6901cb0ef41Sopenharmony_ci      <span class="hljs-comment">// the server has already sent the 200 response code and</span>
6911cb0ef41Sopenharmony_ci      <span class="hljs-comment">// some amount of data has already been sent to the client.</span>
6921cb0ef41Sopenharmony_ci      <span class="hljs-comment">// The best we can do is terminate the response immediately</span>
6931cb0ef41Sopenharmony_ci      <span class="hljs-comment">// and log the error.</span>
6941cb0ef41Sopenharmony_ci      <span class="hljs-built_in">clearInterval</span>(i);
6951cb0ef41Sopenharmony_ci      response.<span class="hljs-title function_">end</span>();
6961cb0ef41Sopenharmony_ci      <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">error</span>(<span class="hljs-string">'An error occurred:'</span>, err);
6971cb0ef41Sopenharmony_ci    }
6981cb0ef41Sopenharmony_ci  });
6991cb0ef41Sopenharmony_ci
7001cb0ef41Sopenharmony_ci  i = <span class="hljs-built_in">setInterval</span>(<span class="hljs-function">() =></span> {
7011cb0ef41Sopenharmony_ci    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> {
7021cb0ef41Sopenharmony_ci      <span class="hljs-comment">// The data has been passed to zlib, but the compression algorithm may</span>
7031cb0ef41Sopenharmony_ci      <span class="hljs-comment">// have decided to buffer the data for more efficient compression.</span>
7041cb0ef41Sopenharmony_ci      <span class="hljs-comment">// Calling .flush() will make the data available as soon as the client</span>
7051cb0ef41Sopenharmony_ci      <span class="hljs-comment">// is ready to receive it.</span>
7061cb0ef41Sopenharmony_ci      output.<span class="hljs-title function_">flush</span>();
7071cb0ef41Sopenharmony_ci    });
7081cb0ef41Sopenharmony_ci  }, <span class="hljs-number">1000</span>);
7091cb0ef41Sopenharmony_ci}).<span class="hljs-title function_">listen</span>(<span class="hljs-number">1337</span>);</code> <button class="copy-button">copy</button></pre>
7101cb0ef41Sopenharmony_ci</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>
7111cb0ef41Sopenharmony_ci<div class="api_metadata">
7121cb0ef41Sopenharmony_ci<span>Added in: v0.5.8</span>
7131cb0ef41Sopenharmony_ci</div>
7141cb0ef41Sopenharmony_ci
7151cb0ef41Sopenharmony_ci<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>
7161cb0ef41Sopenharmony_ci<p>All of the constants defined in <code>zlib.h</code> are also defined on
7171cb0ef41Sopenharmony_ci<code>require('node:zlib').constants</code>. In the normal course of operations, it will
7181cb0ef41Sopenharmony_cinot be necessary to use these constants. They are documented so that their
7191cb0ef41Sopenharmony_cipresence is not surprising. This section is taken almost directly from the
7201cb0ef41Sopenharmony_ci<a href="https://zlib.net/manual.html#Constants">zlib documentation</a>.</p>
7211cb0ef41Sopenharmony_ci<p>Previously, the constants were available directly from <code>require('node:zlib')</code>,
7221cb0ef41Sopenharmony_cifor instance <code>zlib.Z_NO_FLUSH</code>. Accessing the constants directly from the module
7231cb0ef41Sopenharmony_ciis currently still possible but is deprecated.</p>
7241cb0ef41Sopenharmony_ci<p>Allowed flush values.</p>
7251cb0ef41Sopenharmony_ci<ul>
7261cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_NO_FLUSH</code></li>
7271cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_PARTIAL_FLUSH</code></li>
7281cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_SYNC_FLUSH</code></li>
7291cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_FULL_FLUSH</code></li>
7301cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_FINISH</code></li>
7311cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_BLOCK</code></li>
7321cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_TREES</code></li>
7331cb0ef41Sopenharmony_ci</ul>
7341cb0ef41Sopenharmony_ci<p>Return codes for the compression/decompression functions. Negative
7351cb0ef41Sopenharmony_civalues are errors, positive values are used for special but normal
7361cb0ef41Sopenharmony_cievents.</p>
7371cb0ef41Sopenharmony_ci<ul>
7381cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_OK</code></li>
7391cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_STREAM_END</code></li>
7401cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_NEED_DICT</code></li>
7411cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_ERRNO</code></li>
7421cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_STREAM_ERROR</code></li>
7431cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_DATA_ERROR</code></li>
7441cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_MEM_ERROR</code></li>
7451cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_BUF_ERROR</code></li>
7461cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_VERSION_ERROR</code></li>
7471cb0ef41Sopenharmony_ci</ul>
7481cb0ef41Sopenharmony_ci<p>Compression levels.</p>
7491cb0ef41Sopenharmony_ci<ul>
7501cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_NO_COMPRESSION</code></li>
7511cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_BEST_SPEED</code></li>
7521cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_BEST_COMPRESSION</code></li>
7531cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_DEFAULT_COMPRESSION</code></li>
7541cb0ef41Sopenharmony_ci</ul>
7551cb0ef41Sopenharmony_ci<p>Compression strategy.</p>
7561cb0ef41Sopenharmony_ci<ul>
7571cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_FILTERED</code></li>
7581cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_HUFFMAN_ONLY</code></li>
7591cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_RLE</code></li>
7601cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_FIXED</code></li>
7611cb0ef41Sopenharmony_ci<li><code>zlib.constants.Z_DEFAULT_STRATEGY</code></li>
7621cb0ef41Sopenharmony_ci</ul>
7631cb0ef41Sopenharmony_ci<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>
7641cb0ef41Sopenharmony_ci<div class="api_metadata">
7651cb0ef41Sopenharmony_ci<span>Added in: v11.7.0, v10.16.0</span>
7661cb0ef41Sopenharmony_ci</div>
7671cb0ef41Sopenharmony_ci<p>There are several options and other constants available for Brotli-based
7681cb0ef41Sopenharmony_cistreams:</p>
7691cb0ef41Sopenharmony_ci<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>
7701cb0ef41Sopenharmony_ci<p>The following values are valid flush operations for Brotli-based streams:</p>
7711cb0ef41Sopenharmony_ci<ul>
7721cb0ef41Sopenharmony_ci<li><code>zlib.constants.BROTLI_OPERATION_PROCESS</code> (default for all operations)</li>
7731cb0ef41Sopenharmony_ci<li><code>zlib.constants.BROTLI_OPERATION_FLUSH</code> (default when calling <code>.flush()</code>)</li>
7741cb0ef41Sopenharmony_ci<li><code>zlib.constants.BROTLI_OPERATION_FINISH</code> (default for the last chunk)</li>
7751cb0ef41Sopenharmony_ci<li><code>zlib.constants.BROTLI_OPERATION_EMIT_METADATA</code>
7761cb0ef41Sopenharmony_ci<ul>
7771cb0ef41Sopenharmony_ci<li>This particular operation may be hard to use in a Node.js context,
7781cb0ef41Sopenharmony_cias the streaming layer makes it hard to know which data will end up
7791cb0ef41Sopenharmony_ciin this frame. Also, there is currently no way to consume this data through
7801cb0ef41Sopenharmony_cithe Node.js API.</li>
7811cb0ef41Sopenharmony_ci</ul>
7821cb0ef41Sopenharmony_ci</li>
7831cb0ef41Sopenharmony_ci</ul>
7841cb0ef41Sopenharmony_ci<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>
7851cb0ef41Sopenharmony_ci<p>There are several options that can be set on Brotli encoders, affecting
7861cb0ef41Sopenharmony_cicompression efficiency and speed. Both the keys and the values can be accessed
7871cb0ef41Sopenharmony_cias properties of the <code>zlib.constants</code> object.</p>
7881cb0ef41Sopenharmony_ci<p>The most important options are:</p>
7891cb0ef41Sopenharmony_ci<ul>
7901cb0ef41Sopenharmony_ci<li><code>BROTLI_PARAM_MODE</code>
7911cb0ef41Sopenharmony_ci<ul>
7921cb0ef41Sopenharmony_ci<li><code>BROTLI_MODE_GENERIC</code> (default)</li>
7931cb0ef41Sopenharmony_ci<li><code>BROTLI_MODE_TEXT</code>, adjusted for UTF-8 text</li>
7941cb0ef41Sopenharmony_ci<li><code>BROTLI_MODE_FONT</code>, adjusted for WOFF 2.0 fonts</li>
7951cb0ef41Sopenharmony_ci</ul>
7961cb0ef41Sopenharmony_ci</li>
7971cb0ef41Sopenharmony_ci<li><code>BROTLI_PARAM_QUALITY</code>
7981cb0ef41Sopenharmony_ci<ul>
7991cb0ef41Sopenharmony_ci<li>Ranges from <code>BROTLI_MIN_QUALITY</code> to <code>BROTLI_MAX_QUALITY</code>,
8001cb0ef41Sopenharmony_ciwith a default of <code>BROTLI_DEFAULT_QUALITY</code>.</li>
8011cb0ef41Sopenharmony_ci</ul>
8021cb0ef41Sopenharmony_ci</li>
8031cb0ef41Sopenharmony_ci<li><code>BROTLI_PARAM_SIZE_HINT</code>
8041cb0ef41Sopenharmony_ci<ul>
8051cb0ef41Sopenharmony_ci<li>Integer value representing the expected input size;
8061cb0ef41Sopenharmony_cidefaults to <code>0</code> for an unknown input size.</li>
8071cb0ef41Sopenharmony_ci</ul>
8081cb0ef41Sopenharmony_ci</li>
8091cb0ef41Sopenharmony_ci</ul>
8101cb0ef41Sopenharmony_ci<p>The following flags can be set for advanced control over the compression
8111cb0ef41Sopenharmony_cialgorithm and memory usage tuning:</p>
8121cb0ef41Sopenharmony_ci<ul>
8131cb0ef41Sopenharmony_ci<li><code>BROTLI_PARAM_LGWIN</code>
8141cb0ef41Sopenharmony_ci<ul>
8151cb0ef41Sopenharmony_ci<li>Ranges from <code>BROTLI_MIN_WINDOW_BITS</code> to <code>BROTLI_MAX_WINDOW_BITS</code>,
8161cb0ef41Sopenharmony_ciwith a default of <code>BROTLI_DEFAULT_WINDOW</code>, or up to
8171cb0ef41Sopenharmony_ci<code>BROTLI_LARGE_MAX_WINDOW_BITS</code> if the <code>BROTLI_PARAM_LARGE_WINDOW</code> flag
8181cb0ef41Sopenharmony_ciis set.</li>
8191cb0ef41Sopenharmony_ci</ul>
8201cb0ef41Sopenharmony_ci</li>
8211cb0ef41Sopenharmony_ci<li><code>BROTLI_PARAM_LGBLOCK</code>
8221cb0ef41Sopenharmony_ci<ul>
8231cb0ef41Sopenharmony_ci<li>Ranges from <code>BROTLI_MIN_INPUT_BLOCK_BITS</code> to <code>BROTLI_MAX_INPUT_BLOCK_BITS</code>.</li>
8241cb0ef41Sopenharmony_ci</ul>
8251cb0ef41Sopenharmony_ci</li>
8261cb0ef41Sopenharmony_ci<li><code>BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING</code>
8271cb0ef41Sopenharmony_ci<ul>
8281cb0ef41Sopenharmony_ci<li>Boolean flag that decreases compression ratio in favour of
8291cb0ef41Sopenharmony_cidecompression speed.</li>
8301cb0ef41Sopenharmony_ci</ul>
8311cb0ef41Sopenharmony_ci</li>
8321cb0ef41Sopenharmony_ci<li><code>BROTLI_PARAM_LARGE_WINDOW</code>
8331cb0ef41Sopenharmony_ci<ul>
8341cb0ef41Sopenharmony_ci<li>Boolean flag enabling “Large Window Brotli” mode (not compatible with the
8351cb0ef41Sopenharmony_ciBrotli format as standardized in <a href="https://www.rfc-editor.org/rfc/rfc7932.txt">RFC 7932</a>).</li>
8361cb0ef41Sopenharmony_ci</ul>
8371cb0ef41Sopenharmony_ci</li>
8381cb0ef41Sopenharmony_ci<li><code>BROTLI_PARAM_NPOSTFIX</code>
8391cb0ef41Sopenharmony_ci<ul>
8401cb0ef41Sopenharmony_ci<li>Ranges from <code>0</code> to <code>BROTLI_MAX_NPOSTFIX</code>.</li>
8411cb0ef41Sopenharmony_ci</ul>
8421cb0ef41Sopenharmony_ci</li>
8431cb0ef41Sopenharmony_ci<li><code>BROTLI_PARAM_NDIRECT</code>
8441cb0ef41Sopenharmony_ci<ul>
8451cb0ef41Sopenharmony_ci<li>Ranges from <code>0</code> to <code>15 &#x3C;&#x3C; NPOSTFIX</code> in steps of <code>1 &#x3C;&#x3C; NPOSTFIX</code>.</li>
8461cb0ef41Sopenharmony_ci</ul>
8471cb0ef41Sopenharmony_ci</li>
8481cb0ef41Sopenharmony_ci</ul>
8491cb0ef41Sopenharmony_ci<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>
8501cb0ef41Sopenharmony_ci<p>These advanced options are available for controlling decompression:</p>
8511cb0ef41Sopenharmony_ci<ul>
8521cb0ef41Sopenharmony_ci<li><code>BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION</code>
8531cb0ef41Sopenharmony_ci<ul>
8541cb0ef41Sopenharmony_ci<li>Boolean flag that affects internal memory allocation patterns.</li>
8551cb0ef41Sopenharmony_ci</ul>
8561cb0ef41Sopenharmony_ci</li>
8571cb0ef41Sopenharmony_ci<li><code>BROTLI_DECODER_PARAM_LARGE_WINDOW</code>
8581cb0ef41Sopenharmony_ci<ul>
8591cb0ef41Sopenharmony_ci<li>Boolean flag enabling “Large Window Brotli” mode (not compatible with the
8601cb0ef41Sopenharmony_ciBrotli format as standardized in <a href="https://www.rfc-editor.org/rfc/rfc7932.txt">RFC 7932</a>).</li>
8611cb0ef41Sopenharmony_ci</ul>
8621cb0ef41Sopenharmony_ci</li>
8631cb0ef41Sopenharmony_ci</ul>
8641cb0ef41Sopenharmony_ci</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>
8651cb0ef41Sopenharmony_ci<div class="api_metadata">
8661cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
8671cb0ef41Sopenharmony_ci<table>
8681cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
8691cb0ef41Sopenharmony_ci<tr><td>v14.5.0, v12.19.0</td>
8701cb0ef41Sopenharmony_ci<td><p>The <code>maxOutputLength</code> option is supported now.</p></td></tr>
8711cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
8721cb0ef41Sopenharmony_ci<td><p>The <code>dictionary</code> option can be an <code>ArrayBuffer</code>.</p></td></tr>
8731cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
8741cb0ef41Sopenharmony_ci<td><p>The <code>dictionary</code> option can be an <code>Uint8Array</code> now.</p></td></tr>
8751cb0ef41Sopenharmony_ci<tr><td>v5.11.0</td>
8761cb0ef41Sopenharmony_ci<td><p>The <code>finishFlush</code> option is supported now.</p></td></tr>
8771cb0ef41Sopenharmony_ci<tr><td>v0.11.1</td>
8781cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.11.1</span></p></td></tr>
8791cb0ef41Sopenharmony_ci</tbody></table>
8801cb0ef41Sopenharmony_ci</details>
8811cb0ef41Sopenharmony_ci</div>
8821cb0ef41Sopenharmony_ci
8831cb0ef41Sopenharmony_ci<p>Each zlib-based class takes an <code>options</code> object. No options are required.</p>
8841cb0ef41Sopenharmony_ci<p>Some options are only relevant when compressing and are
8851cb0ef41Sopenharmony_ciignored by the decompression classes.</p>
8861cb0ef41Sopenharmony_ci<ul>
8871cb0ef41Sopenharmony_ci<li><code>flush</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <strong>Default:</strong> <code>zlib.constants.Z_NO_FLUSH</code></li>
8881cb0ef41Sopenharmony_ci<li><code>finishFlush</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <strong>Default:</strong> <code>zlib.constants.Z_FINISH</code></li>
8891cb0ef41Sopenharmony_ci<li><code>chunkSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <strong>Default:</strong> <code>16 * 1024</code></li>
8901cb0ef41Sopenharmony_ci<li><code>windowBits</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
8911cb0ef41Sopenharmony_ci<li><code>level</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> (compression only)</li>
8921cb0ef41Sopenharmony_ci<li><code>memLevel</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> (compression only)</li>
8931cb0ef41Sopenharmony_ci<li><code>strategy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> (compression only)</li>
8941cb0ef41Sopenharmony_ci<li><code>dictionary</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> (deflate/inflate only,
8951cb0ef41Sopenharmony_ciempty dictionary by default)</li>
8961cb0ef41Sopenharmony_ci<li><code>info</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> (If <code>true</code>, returns an object with <code>buffer</code> and <code>engine</code>.)</li>
8971cb0ef41Sopenharmony_ci<li><code>maxOutputLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> Limits output size when using
8981cb0ef41Sopenharmony_ci<a href="#convenience-methods">convenience methods</a>. <strong>Default:</strong> <a href="buffer.html#bufferkmaxlength"><code>buffer.kMaxLength</code></a></li>
8991cb0ef41Sopenharmony_ci</ul>
9001cb0ef41Sopenharmony_ci<p>See the <a href="https://zlib.net/manual.html#Advanced"><code>deflateInit2</code> and <code>inflateInit2</code></a> documentation for more
9011cb0ef41Sopenharmony_ciinformation.</p>
9021cb0ef41Sopenharmony_ci</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>
9031cb0ef41Sopenharmony_ci<div class="api_metadata">
9041cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
9051cb0ef41Sopenharmony_ci<table>
9061cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
9071cb0ef41Sopenharmony_ci<tr><td>v14.5.0, v12.19.0</td>
9081cb0ef41Sopenharmony_ci<td><p>The <code>maxOutputLength</code> option is supported now.</p></td></tr>
9091cb0ef41Sopenharmony_ci<tr><td>v11.7.0</td>
9101cb0ef41Sopenharmony_ci<td><p><span>Added in: v11.7.0</span></p></td></tr>
9111cb0ef41Sopenharmony_ci</tbody></table>
9121cb0ef41Sopenharmony_ci</details>
9131cb0ef41Sopenharmony_ci</div>
9141cb0ef41Sopenharmony_ci
9151cb0ef41Sopenharmony_ci<p>Each Brotli-based class takes an <code>options</code> object. All options are optional.</p>
9161cb0ef41Sopenharmony_ci<ul>
9171cb0ef41Sopenharmony_ci<li><code>flush</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <strong>Default:</strong> <code>zlib.constants.BROTLI_OPERATION_PROCESS</code></li>
9181cb0ef41Sopenharmony_ci<li><code>finishFlush</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <strong>Default:</strong> <code>zlib.constants.BROTLI_OPERATION_FINISH</code></li>
9191cb0ef41Sopenharmony_ci<li><code>chunkSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> <strong>Default:</strong> <code>16 * 1024</code></li>
9201cb0ef41Sopenharmony_ci<li><code>params</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a> Key-value object containing indexed <a href="#brotli-constants">Brotli parameters</a>.</li>
9211cb0ef41Sopenharmony_ci<li><code>maxOutputLength</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a> Limits output size when using
9221cb0ef41Sopenharmony_ci<a href="#convenience-methods">convenience methods</a>. <strong>Default:</strong> <a href="buffer.html#bufferkmaxlength"><code>buffer.kMaxLength</code></a></li>
9231cb0ef41Sopenharmony_ci</ul>
9241cb0ef41Sopenharmony_ci<p>For example:</p>
9251cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> stream = zlib.<span class="hljs-title function_">createBrotliCompress</span>({
9261cb0ef41Sopenharmony_ci  <span class="hljs-attr">chunkSize</span>: <span class="hljs-number">32</span> * <span class="hljs-number">1024</span>,
9271cb0ef41Sopenharmony_ci  <span class="hljs-attr">params</span>: {
9281cb0ef41Sopenharmony_ci    [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>,
9291cb0ef41Sopenharmony_ci    [zlib.<span class="hljs-property">constants</span>.<span class="hljs-property">BROTLI_PARAM_QUALITY</span>]: <span class="hljs-number">4</span>,
9301cb0ef41Sopenharmony_ci    [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>,
9311cb0ef41Sopenharmony_ci  },
9321cb0ef41Sopenharmony_ci});</code> <button class="copy-button">copy</button></pre>
9331cb0ef41Sopenharmony_ci</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>
9341cb0ef41Sopenharmony_ci<div class="api_metadata">
9351cb0ef41Sopenharmony_ci<span>Added in: v11.7.0, v10.16.0</span>
9361cb0ef41Sopenharmony_ci</div>
9371cb0ef41Sopenharmony_ci<p>Compress data using the Brotli algorithm.</p>
9381cb0ef41Sopenharmony_ci</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>
9391cb0ef41Sopenharmony_ci<div class="api_metadata">
9401cb0ef41Sopenharmony_ci<span>Added in: v11.7.0, v10.16.0</span>
9411cb0ef41Sopenharmony_ci</div>
9421cb0ef41Sopenharmony_ci<p>Decompress data using the Brotli algorithm.</p>
9431cb0ef41Sopenharmony_ci</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>
9441cb0ef41Sopenharmony_ci<div class="api_metadata">
9451cb0ef41Sopenharmony_ci<span>Added in: v0.5.8</span>
9461cb0ef41Sopenharmony_ci</div>
9471cb0ef41Sopenharmony_ci<p>Compress data using deflate.</p>
9481cb0ef41Sopenharmony_ci</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>
9491cb0ef41Sopenharmony_ci<div class="api_metadata">
9501cb0ef41Sopenharmony_ci<span>Added in: v0.5.8</span>
9511cb0ef41Sopenharmony_ci</div>
9521cb0ef41Sopenharmony_ci<p>Compress data using deflate, and do not append a <code>zlib</code> header.</p>
9531cb0ef41Sopenharmony_ci</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>
9541cb0ef41Sopenharmony_ci<div class="api_metadata">
9551cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
9561cb0ef41Sopenharmony_ci<table>
9571cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
9581cb0ef41Sopenharmony_ci<tr><td>v6.0.0</td>
9591cb0ef41Sopenharmony_ci<td><p>Trailing garbage at the end of the input stream will now result in an <code>'error'</code> event.</p></td></tr>
9601cb0ef41Sopenharmony_ci<tr><td>v5.9.0</td>
9611cb0ef41Sopenharmony_ci<td><p>Multiple concatenated gzip file members are supported now.</p></td></tr>
9621cb0ef41Sopenharmony_ci<tr><td>v5.0.0</td>
9631cb0ef41Sopenharmony_ci<td><p>A truncated input stream will now result in an <code>'error'</code> event.</p></td></tr>
9641cb0ef41Sopenharmony_ci<tr><td>v0.5.8</td>
9651cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.5.8</span></p></td></tr>
9661cb0ef41Sopenharmony_ci</tbody></table>
9671cb0ef41Sopenharmony_ci</details>
9681cb0ef41Sopenharmony_ci</div>
9691cb0ef41Sopenharmony_ci<p>Decompress a gzip stream.</p>
9701cb0ef41Sopenharmony_ci</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>
9711cb0ef41Sopenharmony_ci<div class="api_metadata">
9721cb0ef41Sopenharmony_ci<span>Added in: v0.5.8</span>
9731cb0ef41Sopenharmony_ci</div>
9741cb0ef41Sopenharmony_ci<p>Compress data using gzip.</p>
9751cb0ef41Sopenharmony_ci</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>
9761cb0ef41Sopenharmony_ci<div class="api_metadata">
9771cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
9781cb0ef41Sopenharmony_ci<table>
9791cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
9801cb0ef41Sopenharmony_ci<tr><td>v5.0.0</td>
9811cb0ef41Sopenharmony_ci<td><p>A truncated input stream will now result in an <code>'error'</code> event.</p></td></tr>
9821cb0ef41Sopenharmony_ci<tr><td>v0.5.8</td>
9831cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.5.8</span></p></td></tr>
9841cb0ef41Sopenharmony_ci</tbody></table>
9851cb0ef41Sopenharmony_ci</details>
9861cb0ef41Sopenharmony_ci</div>
9871cb0ef41Sopenharmony_ci<p>Decompress a deflate stream.</p>
9881cb0ef41Sopenharmony_ci</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>
9891cb0ef41Sopenharmony_ci<div class="api_metadata">
9901cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
9911cb0ef41Sopenharmony_ci<table>
9921cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
9931cb0ef41Sopenharmony_ci<tr><td>v6.8.0</td>
9941cb0ef41Sopenharmony_ci<td><p>Custom dictionaries are now supported by <code>InflateRaw</code>.</p></td></tr>
9951cb0ef41Sopenharmony_ci<tr><td>v5.0.0</td>
9961cb0ef41Sopenharmony_ci<td><p>A truncated input stream will now result in an <code>'error'</code> event.</p></td></tr>
9971cb0ef41Sopenharmony_ci<tr><td>v0.5.8</td>
9981cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.5.8</span></p></td></tr>
9991cb0ef41Sopenharmony_ci</tbody></table>
10001cb0ef41Sopenharmony_ci</details>
10011cb0ef41Sopenharmony_ci</div>
10021cb0ef41Sopenharmony_ci<p>Decompress a raw deflate stream.</p>
10031cb0ef41Sopenharmony_ci</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>
10041cb0ef41Sopenharmony_ci<div class="api_metadata">
10051cb0ef41Sopenharmony_ci<span>Added in: v0.5.8</span>
10061cb0ef41Sopenharmony_ci</div>
10071cb0ef41Sopenharmony_ci<p>Decompress either a Gzip- or Deflate-compressed stream by auto-detecting
10081cb0ef41Sopenharmony_cithe header.</p>
10091cb0ef41Sopenharmony_ci</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>
10101cb0ef41Sopenharmony_ci<div class="api_metadata">
10111cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
10121cb0ef41Sopenharmony_ci<table>
10131cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
10141cb0ef41Sopenharmony_ci<tr><td>v11.7.0, v10.16.0</td>
10151cb0ef41Sopenharmony_ci<td><p>This class was renamed from <code>Zlib</code> to <code>ZlibBase</code>.</p></td></tr>
10161cb0ef41Sopenharmony_ci<tr><td>v0.5.8</td>
10171cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.5.8</span></p></td></tr>
10181cb0ef41Sopenharmony_ci</tbody></table>
10191cb0ef41Sopenharmony_ci</details>
10201cb0ef41Sopenharmony_ci</div>
10211cb0ef41Sopenharmony_ci<p>Not exported by the <code>node:zlib</code> module. It is documented here because it is the
10221cb0ef41Sopenharmony_cibase class of the compressor/decompressor classes.</p>
10231cb0ef41Sopenharmony_ci<p>This class inherits from <a href="stream.html#class-streamtransform"><code>stream.Transform</code></a>, allowing <code>node:zlib</code> objects to
10241cb0ef41Sopenharmony_cibe used in pipes and similar stream operations.</p>
10251cb0ef41Sopenharmony_ci<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>
10261cb0ef41Sopenharmony_ci<div class="api_metadata">
10271cb0ef41Sopenharmony_ci<span>Added in: v8.1.0</span><span>Deprecated since: v10.0.0</span>
10281cb0ef41Sopenharmony_ci</div>
10291cb0ef41Sopenharmony_ci<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>
10301cb0ef41Sopenharmony_ci<ul>
10311cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
10321cb0ef41Sopenharmony_ci</ul>
10331cb0ef41Sopenharmony_ci<p>Deprecated alias for <a href="#zlibbyteswritten"><code>zlib.bytesWritten</code></a>. This original name was chosen
10341cb0ef41Sopenharmony_cibecause it also made sense to interpret the value as the number of bytes
10351cb0ef41Sopenharmony_ciread by the engine, but is inconsistent with other streams in Node.js that
10361cb0ef41Sopenharmony_ciexpose values under these names.</p>
10371cb0ef41Sopenharmony_ci<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>
10381cb0ef41Sopenharmony_ci<div class="api_metadata">
10391cb0ef41Sopenharmony_ci<span>Added in: v10.0.0</span>
10401cb0ef41Sopenharmony_ci</div>
10411cb0ef41Sopenharmony_ci<ul>
10421cb0ef41Sopenharmony_ci<li><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
10431cb0ef41Sopenharmony_ci</ul>
10441cb0ef41Sopenharmony_ci<p>The <code>zlib.bytesWritten</code> property specifies the number of bytes written to
10451cb0ef41Sopenharmony_cithe engine, before the bytes are processed (compressed or decompressed,
10461cb0ef41Sopenharmony_cias appropriate for the derived class).</p>
10471cb0ef41Sopenharmony_ci<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>
10481cb0ef41Sopenharmony_ci<div class="api_metadata">
10491cb0ef41Sopenharmony_ci<span>Added in: v0.9.4</span>
10501cb0ef41Sopenharmony_ci</div>
10511cb0ef41Sopenharmony_ci<ul>
10521cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
10531cb0ef41Sopenharmony_ci</ul>
10541cb0ef41Sopenharmony_ci<p>Close the underlying handle.</p>
10551cb0ef41Sopenharmony_ci<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>
10561cb0ef41Sopenharmony_ci<div class="api_metadata">
10571cb0ef41Sopenharmony_ci<span>Added in: v0.5.8</span>
10581cb0ef41Sopenharmony_ci</div>
10591cb0ef41Sopenharmony_ci<ul>
10601cb0ef41Sopenharmony_ci<li><code>kind</code> <strong>Default:</strong> <code>zlib.constants.Z_FULL_FLUSH</code> for zlib-based streams,
10611cb0ef41Sopenharmony_ci<code>zlib.constants.BROTLI_OPERATION_FLUSH</code> for Brotli-based streams.</li>
10621cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
10631cb0ef41Sopenharmony_ci</ul>
10641cb0ef41Sopenharmony_ci<p>Flush pending data. Don't call this frivolously, premature flushes negatively
10651cb0ef41Sopenharmony_ciimpact the effectiveness of the compression algorithm.</p>
10661cb0ef41Sopenharmony_ci<p>Calling this only flushes data from the internal <code>zlib</code> state, and does not
10671cb0ef41Sopenharmony_ciperform flushing of any kind on the streams level. Rather, it behaves like a
10681cb0ef41Sopenharmony_cinormal call to <code>.write()</code>, i.e. it will be queued up behind other pending
10691cb0ef41Sopenharmony_ciwrites and will only produce output when data is being read from the stream.</p>
10701cb0ef41Sopenharmony_ci<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>
10711cb0ef41Sopenharmony_ci<div class="api_metadata">
10721cb0ef41Sopenharmony_ci<span>Added in: v0.11.4</span>
10731cb0ef41Sopenharmony_ci</div>
10741cb0ef41Sopenharmony_ci<ul>
10751cb0ef41Sopenharmony_ci<li><code>level</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
10761cb0ef41Sopenharmony_ci<li><code>strategy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;integer></a></li>
10771cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
10781cb0ef41Sopenharmony_ci</ul>
10791cb0ef41Sopenharmony_ci<p>This function is only available for zlib-based streams, i.e. not Brotli.</p>
10801cb0ef41Sopenharmony_ci<p>Dynamically update the compression level and compression strategy.
10811cb0ef41Sopenharmony_ciOnly applicable to deflate algorithm.</p>
10821cb0ef41Sopenharmony_ci<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>
10831cb0ef41Sopenharmony_ci<div class="api_metadata">
10841cb0ef41Sopenharmony_ci<span>Added in: v0.7.0</span>
10851cb0ef41Sopenharmony_ci</div>
10861cb0ef41Sopenharmony_ci<p>Reset the compressor/decompressor to factory defaults. Only applicable to
10871cb0ef41Sopenharmony_cithe inflate and deflate algorithms.</p>
10881cb0ef41Sopenharmony_ci</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>
10891cb0ef41Sopenharmony_ci<div class="api_metadata">
10901cb0ef41Sopenharmony_ci<span>Added in: v7.0.0</span>
10911cb0ef41Sopenharmony_ci</div>
10921cb0ef41Sopenharmony_ci<p>Provides an object enumerating Zlib-related constants.</p>
10931cb0ef41Sopenharmony_ci</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>
10941cb0ef41Sopenharmony_ci<div class="api_metadata">
10951cb0ef41Sopenharmony_ci<span>Added in: v11.7.0, v10.16.0</span>
10961cb0ef41Sopenharmony_ci</div>
10971cb0ef41Sopenharmony_ci<ul>
10981cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-brotlioptions" class="type">&#x3C;brotli options></a></li>
10991cb0ef41Sopenharmony_ci</ul>
11001cb0ef41Sopenharmony_ci<p>Creates and returns a new <a href="#class-zlibbrotlicompress"><code>BrotliCompress</code></a> object.</p>
11011cb0ef41Sopenharmony_ci</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>
11021cb0ef41Sopenharmony_ci<div class="api_metadata">
11031cb0ef41Sopenharmony_ci<span>Added in: v11.7.0, v10.16.0</span>
11041cb0ef41Sopenharmony_ci</div>
11051cb0ef41Sopenharmony_ci<ul>
11061cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-brotlioptions" class="type">&#x3C;brotli options></a></li>
11071cb0ef41Sopenharmony_ci</ul>
11081cb0ef41Sopenharmony_ci<p>Creates and returns a new <a href="#class-zlibbrotlidecompress"><code>BrotliDecompress</code></a> object.</p>
11091cb0ef41Sopenharmony_ci</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>
11101cb0ef41Sopenharmony_ci<div class="api_metadata">
11111cb0ef41Sopenharmony_ci<span>Added in: v0.5.8</span>
11121cb0ef41Sopenharmony_ci</div>
11131cb0ef41Sopenharmony_ci<ul>
11141cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
11151cb0ef41Sopenharmony_ci</ul>
11161cb0ef41Sopenharmony_ci<p>Creates and returns a new <a href="#class-zlibdeflate"><code>Deflate</code></a> object.</p>
11171cb0ef41Sopenharmony_ci</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>
11181cb0ef41Sopenharmony_ci<div class="api_metadata">
11191cb0ef41Sopenharmony_ci<span>Added in: v0.5.8</span>
11201cb0ef41Sopenharmony_ci</div>
11211cb0ef41Sopenharmony_ci<ul>
11221cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
11231cb0ef41Sopenharmony_ci</ul>
11241cb0ef41Sopenharmony_ci<p>Creates and returns a new <a href="#class-zlibdeflateraw"><code>DeflateRaw</code></a> object.</p>
11251cb0ef41Sopenharmony_ci<p>An upgrade of zlib from 1.2.8 to 1.2.11 changed behavior when <code>windowBits</code>
11261cb0ef41Sopenharmony_ciis set to 8 for raw deflate streams. zlib would automatically set <code>windowBits</code>
11271cb0ef41Sopenharmony_cito 9 if was initially set to 8. Newer versions of zlib will throw an exception,
11281cb0ef41Sopenharmony_ciso Node.js restored the original behavior of upgrading a value of 8 to 9,
11291cb0ef41Sopenharmony_cisince passing <code>windowBits = 9</code> to zlib actually results in a compressed stream
11301cb0ef41Sopenharmony_cithat effectively uses an 8-bit window only.</p>
11311cb0ef41Sopenharmony_ci</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>
11321cb0ef41Sopenharmony_ci<div class="api_metadata">
11331cb0ef41Sopenharmony_ci<span>Added in: v0.5.8</span>
11341cb0ef41Sopenharmony_ci</div>
11351cb0ef41Sopenharmony_ci<ul>
11361cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
11371cb0ef41Sopenharmony_ci</ul>
11381cb0ef41Sopenharmony_ci<p>Creates and returns a new <a href="#class-zlibgunzip"><code>Gunzip</code></a> object.</p>
11391cb0ef41Sopenharmony_ci</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>
11401cb0ef41Sopenharmony_ci<div class="api_metadata">
11411cb0ef41Sopenharmony_ci<span>Added in: v0.5.8</span>
11421cb0ef41Sopenharmony_ci</div>
11431cb0ef41Sopenharmony_ci<ul>
11441cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
11451cb0ef41Sopenharmony_ci</ul>
11461cb0ef41Sopenharmony_ci<p>Creates and returns a new <a href="#class-zlibgzip"><code>Gzip</code></a> object.
11471cb0ef41Sopenharmony_ciSee <a href="#zlib">example</a>.</p>
11481cb0ef41Sopenharmony_ci</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>
11491cb0ef41Sopenharmony_ci<div class="api_metadata">
11501cb0ef41Sopenharmony_ci<span>Added in: v0.5.8</span>
11511cb0ef41Sopenharmony_ci</div>
11521cb0ef41Sopenharmony_ci<ul>
11531cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
11541cb0ef41Sopenharmony_ci</ul>
11551cb0ef41Sopenharmony_ci<p>Creates and returns a new <a href="#class-zlibinflate"><code>Inflate</code></a> object.</p>
11561cb0ef41Sopenharmony_ci</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>
11571cb0ef41Sopenharmony_ci<div class="api_metadata">
11581cb0ef41Sopenharmony_ci<span>Added in: v0.5.8</span>
11591cb0ef41Sopenharmony_ci</div>
11601cb0ef41Sopenharmony_ci<ul>
11611cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
11621cb0ef41Sopenharmony_ci</ul>
11631cb0ef41Sopenharmony_ci<p>Creates and returns a new <a href="#class-zlibinflateraw"><code>InflateRaw</code></a> object.</p>
11641cb0ef41Sopenharmony_ci</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>
11651cb0ef41Sopenharmony_ci<div class="api_metadata">
11661cb0ef41Sopenharmony_ci<span>Added in: v0.5.8</span>
11671cb0ef41Sopenharmony_ci</div>
11681cb0ef41Sopenharmony_ci<ul>
11691cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
11701cb0ef41Sopenharmony_ci</ul>
11711cb0ef41Sopenharmony_ci<p>Creates and returns a new <a href="#class-zlibunzip"><code>Unzip</code></a> object.</p>
11721cb0ef41Sopenharmony_ci</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>
11731cb0ef41Sopenharmony_ci
11741cb0ef41Sopenharmony_ci<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>,
11751cb0ef41Sopenharmony_ci<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
11761cb0ef41Sopenharmony_cito supply options to the <code>zlib</code> classes and will call the supplied callback
11771cb0ef41Sopenharmony_ciwith <code>callback(error, result)</code>.</p>
11781cb0ef41Sopenharmony_ci<p>Every method has a <code>*Sync</code> counterpart, which accept the same arguments, but
11791cb0ef41Sopenharmony_ciwithout a callback.</p>
11801cb0ef41Sopenharmony_ci<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>
11811cb0ef41Sopenharmony_ci<div class="api_metadata">
11821cb0ef41Sopenharmony_ci<span>Added in: v11.7.0, v10.16.0</span>
11831cb0ef41Sopenharmony_ci</div>
11841cb0ef41Sopenharmony_ci<ul>
11851cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
11861cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-brotlioptions" class="type">&#x3C;brotli options></a></li>
11871cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
11881cb0ef41Sopenharmony_ci</ul>
11891cb0ef41Sopenharmony_ci<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>
11901cb0ef41Sopenharmony_ci<div class="api_metadata">
11911cb0ef41Sopenharmony_ci<span>Added in: v11.7.0, v10.16.0</span>
11921cb0ef41Sopenharmony_ci</div>
11931cb0ef41Sopenharmony_ci<ul>
11941cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
11951cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-brotlioptions" class="type">&#x3C;brotli options></a></li>
11961cb0ef41Sopenharmony_ci</ul>
11971cb0ef41Sopenharmony_ci<p>Compress a chunk of data with <a href="#class-zlibbrotlicompress"><code>BrotliCompress</code></a>.</p>
11981cb0ef41Sopenharmony_ci<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>
11991cb0ef41Sopenharmony_ci<div class="api_metadata">
12001cb0ef41Sopenharmony_ci<span>Added in: v11.7.0, v10.16.0</span>
12011cb0ef41Sopenharmony_ci</div>
12021cb0ef41Sopenharmony_ci<ul>
12031cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
12041cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-brotlioptions" class="type">&#x3C;brotli options></a></li>
12051cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
12061cb0ef41Sopenharmony_ci</ul>
12071cb0ef41Sopenharmony_ci<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>
12081cb0ef41Sopenharmony_ci<div class="api_metadata">
12091cb0ef41Sopenharmony_ci<span>Added in: v11.7.0, v10.16.0</span>
12101cb0ef41Sopenharmony_ci</div>
12111cb0ef41Sopenharmony_ci<ul>
12121cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
12131cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-brotlioptions" class="type">&#x3C;brotli options></a></li>
12141cb0ef41Sopenharmony_ci</ul>
12151cb0ef41Sopenharmony_ci<p>Decompress a chunk of data with <a href="#class-zlibbrotlidecompress"><code>BrotliDecompress</code></a>.</p>
12161cb0ef41Sopenharmony_ci<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>
12171cb0ef41Sopenharmony_ci<div class="api_metadata">
12181cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
12191cb0ef41Sopenharmony_ci<table>
12201cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
12211cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
12221cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
12231cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
12241cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
12251cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
12261cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
12271cb0ef41Sopenharmony_ci<tr><td>v0.6.0</td>
12281cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.6.0</span></p></td></tr>
12291cb0ef41Sopenharmony_ci</tbody></table>
12301cb0ef41Sopenharmony_ci</details>
12311cb0ef41Sopenharmony_ci</div>
12321cb0ef41Sopenharmony_ci<ul>
12331cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
12341cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
12351cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
12361cb0ef41Sopenharmony_ci</ul>
12371cb0ef41Sopenharmony_ci<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>
12381cb0ef41Sopenharmony_ci<div class="api_metadata">
12391cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
12401cb0ef41Sopenharmony_ci<table>
12411cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
12421cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
12431cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
12441cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
12451cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
12461cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
12471cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
12481cb0ef41Sopenharmony_ci<tr><td>v0.11.12</td>
12491cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.11.12</span></p></td></tr>
12501cb0ef41Sopenharmony_ci</tbody></table>
12511cb0ef41Sopenharmony_ci</details>
12521cb0ef41Sopenharmony_ci</div>
12531cb0ef41Sopenharmony_ci<ul>
12541cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
12551cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
12561cb0ef41Sopenharmony_ci</ul>
12571cb0ef41Sopenharmony_ci<p>Compress a chunk of data with <a href="#class-zlibdeflate"><code>Deflate</code></a>.</p>
12581cb0ef41Sopenharmony_ci<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>
12591cb0ef41Sopenharmony_ci<div class="api_metadata">
12601cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
12611cb0ef41Sopenharmony_ci<table>
12621cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
12631cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
12641cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
12651cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
12661cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
12671cb0ef41Sopenharmony_ci<tr><td>v0.6.0</td>
12681cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.6.0</span></p></td></tr>
12691cb0ef41Sopenharmony_ci</tbody></table>
12701cb0ef41Sopenharmony_ci</details>
12711cb0ef41Sopenharmony_ci</div>
12721cb0ef41Sopenharmony_ci<ul>
12731cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
12741cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
12751cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
12761cb0ef41Sopenharmony_ci</ul>
12771cb0ef41Sopenharmony_ci<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>
12781cb0ef41Sopenharmony_ci<div class="api_metadata">
12791cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
12801cb0ef41Sopenharmony_ci<table>
12811cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
12821cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
12831cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
12841cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
12851cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
12861cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
12871cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
12881cb0ef41Sopenharmony_ci<tr><td>v0.11.12</td>
12891cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.11.12</span></p></td></tr>
12901cb0ef41Sopenharmony_ci</tbody></table>
12911cb0ef41Sopenharmony_ci</details>
12921cb0ef41Sopenharmony_ci</div>
12931cb0ef41Sopenharmony_ci<ul>
12941cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
12951cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
12961cb0ef41Sopenharmony_ci</ul>
12971cb0ef41Sopenharmony_ci<p>Compress a chunk of data with <a href="#class-zlibdeflateraw"><code>DeflateRaw</code></a>.</p>
12981cb0ef41Sopenharmony_ci<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>
12991cb0ef41Sopenharmony_ci<div class="api_metadata">
13001cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
13011cb0ef41Sopenharmony_ci<table>
13021cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
13031cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
13041cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
13051cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
13061cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
13071cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
13081cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
13091cb0ef41Sopenharmony_ci<tr><td>v0.6.0</td>
13101cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.6.0</span></p></td></tr>
13111cb0ef41Sopenharmony_ci</tbody></table>
13121cb0ef41Sopenharmony_ci</details>
13131cb0ef41Sopenharmony_ci</div>
13141cb0ef41Sopenharmony_ci<ul>
13151cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
13161cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
13171cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
13181cb0ef41Sopenharmony_ci</ul>
13191cb0ef41Sopenharmony_ci<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>
13201cb0ef41Sopenharmony_ci<div class="api_metadata">
13211cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
13221cb0ef41Sopenharmony_ci<table>
13231cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
13241cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
13251cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
13261cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
13271cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
13281cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
13291cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
13301cb0ef41Sopenharmony_ci<tr><td>v0.11.12</td>
13311cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.11.12</span></p></td></tr>
13321cb0ef41Sopenharmony_ci</tbody></table>
13331cb0ef41Sopenharmony_ci</details>
13341cb0ef41Sopenharmony_ci</div>
13351cb0ef41Sopenharmony_ci<ul>
13361cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
13371cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
13381cb0ef41Sopenharmony_ci</ul>
13391cb0ef41Sopenharmony_ci<p>Decompress a chunk of data with <a href="#class-zlibgunzip"><code>Gunzip</code></a>.</p>
13401cb0ef41Sopenharmony_ci<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>
13411cb0ef41Sopenharmony_ci<div class="api_metadata">
13421cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
13431cb0ef41Sopenharmony_ci<table>
13441cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
13451cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
13461cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
13471cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
13481cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
13491cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
13501cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
13511cb0ef41Sopenharmony_ci<tr><td>v0.6.0</td>
13521cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.6.0</span></p></td></tr>
13531cb0ef41Sopenharmony_ci</tbody></table>
13541cb0ef41Sopenharmony_ci</details>
13551cb0ef41Sopenharmony_ci</div>
13561cb0ef41Sopenharmony_ci<ul>
13571cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
13581cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
13591cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
13601cb0ef41Sopenharmony_ci</ul>
13611cb0ef41Sopenharmony_ci<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>
13621cb0ef41Sopenharmony_ci<div class="api_metadata">
13631cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
13641cb0ef41Sopenharmony_ci<table>
13651cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
13661cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
13671cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
13681cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
13691cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
13701cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
13711cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
13721cb0ef41Sopenharmony_ci<tr><td>v0.11.12</td>
13731cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.11.12</span></p></td></tr>
13741cb0ef41Sopenharmony_ci</tbody></table>
13751cb0ef41Sopenharmony_ci</details>
13761cb0ef41Sopenharmony_ci</div>
13771cb0ef41Sopenharmony_ci<ul>
13781cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
13791cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
13801cb0ef41Sopenharmony_ci</ul>
13811cb0ef41Sopenharmony_ci<p>Compress a chunk of data with <a href="#class-zlibgzip"><code>Gzip</code></a>.</p>
13821cb0ef41Sopenharmony_ci<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>
13831cb0ef41Sopenharmony_ci<div class="api_metadata">
13841cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
13851cb0ef41Sopenharmony_ci<table>
13861cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
13871cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
13881cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
13891cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
13901cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
13911cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
13921cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
13931cb0ef41Sopenharmony_ci<tr><td>v0.6.0</td>
13941cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.6.0</span></p></td></tr>
13951cb0ef41Sopenharmony_ci</tbody></table>
13961cb0ef41Sopenharmony_ci</details>
13971cb0ef41Sopenharmony_ci</div>
13981cb0ef41Sopenharmony_ci<ul>
13991cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
14001cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
14011cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
14021cb0ef41Sopenharmony_ci</ul>
14031cb0ef41Sopenharmony_ci<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>
14041cb0ef41Sopenharmony_ci<div class="api_metadata">
14051cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
14061cb0ef41Sopenharmony_ci<table>
14071cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
14081cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
14091cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
14101cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
14111cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
14121cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
14131cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
14141cb0ef41Sopenharmony_ci<tr><td>v0.11.12</td>
14151cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.11.12</span></p></td></tr>
14161cb0ef41Sopenharmony_ci</tbody></table>
14171cb0ef41Sopenharmony_ci</details>
14181cb0ef41Sopenharmony_ci</div>
14191cb0ef41Sopenharmony_ci<ul>
14201cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
14211cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
14221cb0ef41Sopenharmony_ci</ul>
14231cb0ef41Sopenharmony_ci<p>Decompress a chunk of data with <a href="#class-zlibinflate"><code>Inflate</code></a>.</p>
14241cb0ef41Sopenharmony_ci<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>
14251cb0ef41Sopenharmony_ci<div class="api_metadata">
14261cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
14271cb0ef41Sopenharmony_ci<table>
14281cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
14291cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
14301cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
14311cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
14321cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
14331cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
14341cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
14351cb0ef41Sopenharmony_ci<tr><td>v0.6.0</td>
14361cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.6.0</span></p></td></tr>
14371cb0ef41Sopenharmony_ci</tbody></table>
14381cb0ef41Sopenharmony_ci</details>
14391cb0ef41Sopenharmony_ci</div>
14401cb0ef41Sopenharmony_ci<ul>
14411cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
14421cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
14431cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
14441cb0ef41Sopenharmony_ci</ul>
14451cb0ef41Sopenharmony_ci<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>
14461cb0ef41Sopenharmony_ci<div class="api_metadata">
14471cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
14481cb0ef41Sopenharmony_ci<table>
14491cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
14501cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
14511cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
14521cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
14531cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
14541cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
14551cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
14561cb0ef41Sopenharmony_ci<tr><td>v0.11.12</td>
14571cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.11.12</span></p></td></tr>
14581cb0ef41Sopenharmony_ci</tbody></table>
14591cb0ef41Sopenharmony_ci</details>
14601cb0ef41Sopenharmony_ci</div>
14611cb0ef41Sopenharmony_ci<ul>
14621cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
14631cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
14641cb0ef41Sopenharmony_ci</ul>
14651cb0ef41Sopenharmony_ci<p>Decompress a chunk of data with <a href="#class-zlibinflateraw"><code>InflateRaw</code></a>.</p>
14661cb0ef41Sopenharmony_ci<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>
14671cb0ef41Sopenharmony_ci<div class="api_metadata">
14681cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
14691cb0ef41Sopenharmony_ci<table>
14701cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
14711cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
14721cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
14731cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
14741cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
14751cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
14761cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
14771cb0ef41Sopenharmony_ci<tr><td>v0.6.0</td>
14781cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.6.0</span></p></td></tr>
14791cb0ef41Sopenharmony_ci</tbody></table>
14801cb0ef41Sopenharmony_ci</details>
14811cb0ef41Sopenharmony_ci</div>
14821cb0ef41Sopenharmony_ci<ul>
14831cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
14841cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
14851cb0ef41Sopenharmony_ci<li><code>callback</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a></li>
14861cb0ef41Sopenharmony_ci</ul>
14871cb0ef41Sopenharmony_ci<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>
14881cb0ef41Sopenharmony_ci<div class="api_metadata">
14891cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
14901cb0ef41Sopenharmony_ci<table>
14911cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
14921cb0ef41Sopenharmony_ci<tr><td>v9.4.0</td>
14931cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>ArrayBuffer</code>.</p></td></tr>
14941cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
14951cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be any <code>TypedArray</code> or <code>DataView</code>.</p></td></tr>
14961cb0ef41Sopenharmony_ci<tr><td>v8.0.0</td>
14971cb0ef41Sopenharmony_ci<td><p>The <code>buffer</code> parameter can be an <code>Uint8Array</code> now.</p></td></tr>
14981cb0ef41Sopenharmony_ci<tr><td>v0.11.12</td>
14991cb0ef41Sopenharmony_ci<td><p><span>Added in: v0.11.12</span></p></td></tr>
15001cb0ef41Sopenharmony_ci</tbody></table>
15011cb0ef41Sopenharmony_ci</details>
15021cb0ef41Sopenharmony_ci</div>
15031cb0ef41Sopenharmony_ci<ul>
15041cb0ef41Sopenharmony_ci<li><code>buffer</code> <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> | <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
15051cb0ef41Sopenharmony_ci<li><code>options</code> <a href="zlib.html#class-options" class="type">&#x3C;zlib options></a></li>
15061cb0ef41Sopenharmony_ci</ul>
15071cb0ef41Sopenharmony_ci<p>Decompress a chunk of data with <a href="#class-zlibunzip"><code>Unzip</code></a>.</p></section>
15081cb0ef41Sopenharmony_ci        <!-- API END -->
15091cb0ef41Sopenharmony_ci      </div>
15101cb0ef41Sopenharmony_ci    </div>
15111cb0ef41Sopenharmony_ci  </div>
15121cb0ef41Sopenharmony_ci</body>
15131cb0ef41Sopenharmony_ci</html>
1514