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>Web Streams API | 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/webstreams.html">
121cb0ef41Sopenharmony_ci  <script async defer src="assets/api.js" type="text/javascript"></script>
131cb0ef41Sopenharmony_ci  <style>@media(max-width:358px){.with-17-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:654px){.with-54-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:334px){.with-14-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:678px){.with-57-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:622px){.with-50-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}@media(max-width:638px){.with-52-chars>.js-flavor-selector{float:none;margin:0 0 1em auto;}}</style>
141cb0ef41Sopenharmony_ci</head>
151cb0ef41Sopenharmony_ci<body class="alt apidoc" id="api-section-webstreams">
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 active">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">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="webstreams" 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_1"><a href="#web-streams-api">Web Streams API</a></span>
1241cb0ef41Sopenharmony_ci<ul>
1251cb0ef41Sopenharmony_ci<li><a href="#overview">Overview</a>
1261cb0ef41Sopenharmony_ci<ul>
1271cb0ef41Sopenharmony_ci<li><a href="#example-readablestream">Example <code>ReadableStream</code></a></li>
1281cb0ef41Sopenharmony_ci</ul>
1291cb0ef41Sopenharmony_ci</li>
1301cb0ef41Sopenharmony_ci<li><a href="#api">API</a>
1311cb0ef41Sopenharmony_ci<ul>
1321cb0ef41Sopenharmony_ci<li><a href="#class-readablestream">Class: <code>ReadableStream</code></a>
1331cb0ef41Sopenharmony_ci<ul>
1341cb0ef41Sopenharmony_ci<li><a href="#new-readablestreamunderlyingsource--strategy"><code>new ReadableStream([underlyingSource [, strategy]])</code></a></li>
1351cb0ef41Sopenharmony_ci<li><a href="#readablestreamlocked"><code>readableStream.locked</code></a></li>
1361cb0ef41Sopenharmony_ci<li><a href="#readablestreamcancelreason"><code>readableStream.cancel([reason])</code></a></li>
1371cb0ef41Sopenharmony_ci<li><a href="#readablestreamgetreaderoptions"><code>readableStream.getReader([options])</code></a></li>
1381cb0ef41Sopenharmony_ci<li><a href="#readablestreampipethroughtransform-options"><code>readableStream.pipeThrough(transform[, options])</code></a></li>
1391cb0ef41Sopenharmony_ci<li><a href="#readablestreampipetodestination-options"><code>readableStream.pipeTo(destination[, options])</code></a></li>
1401cb0ef41Sopenharmony_ci<li><a href="#readablestreamtee"><code>readableStream.tee()</code></a></li>
1411cb0ef41Sopenharmony_ci<li><a href="#readablestreamvaluesoptions"><code>readableStream.values([options])</code></a></li>
1421cb0ef41Sopenharmony_ci<li><a href="#async-iteration">Async Iteration</a></li>
1431cb0ef41Sopenharmony_ci<li><a href="#transferring-with-postmessage">Transferring with <code>postMessage()</code></a></li>
1441cb0ef41Sopenharmony_ci</ul>
1451cb0ef41Sopenharmony_ci</li>
1461cb0ef41Sopenharmony_ci<li><a href="#class-readablestreamdefaultreader">Class: <code>ReadableStreamDefaultReader</code></a>
1471cb0ef41Sopenharmony_ci<ul>
1481cb0ef41Sopenharmony_ci<li><a href="#new-readablestreamdefaultreaderstream"><code>new ReadableStreamDefaultReader(stream)</code></a></li>
1491cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultreadercancelreason"><code>readableStreamDefaultReader.cancel([reason])</code></a></li>
1501cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultreaderclosed"><code>readableStreamDefaultReader.closed</code></a></li>
1511cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultreaderread"><code>readableStreamDefaultReader.read()</code></a></li>
1521cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultreaderreleaselock"><code>readableStreamDefaultReader.releaseLock()</code></a></li>
1531cb0ef41Sopenharmony_ci</ul>
1541cb0ef41Sopenharmony_ci</li>
1551cb0ef41Sopenharmony_ci<li><a href="#class-readablestreambyobreader">Class: <code>ReadableStreamBYOBReader</code></a>
1561cb0ef41Sopenharmony_ci<ul>
1571cb0ef41Sopenharmony_ci<li><a href="#new-readablestreambyobreaderstream"><code>new ReadableStreamBYOBReader(stream)</code></a></li>
1581cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobreadercancelreason"><code>readableStreamBYOBReader.cancel([reason])</code></a></li>
1591cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobreaderclosed"><code>readableStreamBYOBReader.closed</code></a></li>
1601cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobreaderreadview"><code>readableStreamBYOBReader.read(view)</code></a></li>
1611cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobreaderreleaselock"><code>readableStreamBYOBReader.releaseLock()</code></a></li>
1621cb0ef41Sopenharmony_ci</ul>
1631cb0ef41Sopenharmony_ci</li>
1641cb0ef41Sopenharmony_ci<li><a href="#class-readablestreamdefaultcontroller">Class: <code>ReadableStreamDefaultController</code></a>
1651cb0ef41Sopenharmony_ci<ul>
1661cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultcontrollerclose"><code>readableStreamDefaultController.close()</code></a></li>
1671cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultcontrollerdesiredsize"><code>readableStreamDefaultController.desiredSize</code></a></li>
1681cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultcontrollerenqueuechunk"><code>readableStreamDefaultController.enqueue([chunk])</code></a></li>
1691cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultcontrollererrorerror"><code>readableStreamDefaultController.error([error])</code></a></li>
1701cb0ef41Sopenharmony_ci</ul>
1711cb0ef41Sopenharmony_ci</li>
1721cb0ef41Sopenharmony_ci<li><a href="#class-readablebytestreamcontroller">Class: <code>ReadableByteStreamController</code></a>
1731cb0ef41Sopenharmony_ci<ul>
1741cb0ef41Sopenharmony_ci<li><a href="#readablebytestreamcontrollerbyobrequest"><code>readableByteStreamController.byobRequest</code></a></li>
1751cb0ef41Sopenharmony_ci<li><a href="#readablebytestreamcontrollerclose"><code>readableByteStreamController.close()</code></a></li>
1761cb0ef41Sopenharmony_ci<li><a href="#readablebytestreamcontrollerdesiredsize"><code>readableByteStreamController.desiredSize</code></a></li>
1771cb0ef41Sopenharmony_ci<li><a href="#readablebytestreamcontrollerenqueuechunk"><code>readableByteStreamController.enqueue(chunk)</code></a></li>
1781cb0ef41Sopenharmony_ci<li><a href="#readablebytestreamcontrollererrorerror"><code>readableByteStreamController.error([error])</code></a></li>
1791cb0ef41Sopenharmony_ci</ul>
1801cb0ef41Sopenharmony_ci</li>
1811cb0ef41Sopenharmony_ci<li><a href="#class-readablestreambyobrequest">Class: <code>ReadableStreamBYOBRequest</code></a>
1821cb0ef41Sopenharmony_ci<ul>
1831cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobrequestrespondbyteswritten"><code>readableStreamBYOBRequest.respond(bytesWritten)</code></a></li>
1841cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobrequestrespondwithnewviewview"><code>readableStreamBYOBRequest.respondWithNewView(view)</code></a></li>
1851cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobrequestview"><code>readableStreamBYOBRequest.view</code></a></li>
1861cb0ef41Sopenharmony_ci</ul>
1871cb0ef41Sopenharmony_ci</li>
1881cb0ef41Sopenharmony_ci<li><a href="#class-writablestream">Class: <code>WritableStream</code></a>
1891cb0ef41Sopenharmony_ci<ul>
1901cb0ef41Sopenharmony_ci<li><a href="#new-writablestreamunderlyingsink-strategy"><code>new WritableStream([underlyingSink[, strategy]])</code></a></li>
1911cb0ef41Sopenharmony_ci<li><a href="#writablestreamabortreason"><code>writableStream.abort([reason])</code></a></li>
1921cb0ef41Sopenharmony_ci<li><a href="#writablestreamclose"><code>writableStream.close()</code></a></li>
1931cb0ef41Sopenharmony_ci<li><a href="#writablestreamgetwriter"><code>writableStream.getWriter()</code></a></li>
1941cb0ef41Sopenharmony_ci<li><a href="#writablestreamlocked"><code>writableStream.locked</code></a></li>
1951cb0ef41Sopenharmony_ci<li><a href="#transferring-with-postmessage_1">Transferring with postMessage()</a></li>
1961cb0ef41Sopenharmony_ci</ul>
1971cb0ef41Sopenharmony_ci</li>
1981cb0ef41Sopenharmony_ci<li><a href="#class-writablestreamdefaultwriter">Class: <code>WritableStreamDefaultWriter</code></a>
1991cb0ef41Sopenharmony_ci<ul>
2001cb0ef41Sopenharmony_ci<li><a href="#new-writablestreamdefaultwriterstream"><code>new WritableStreamDefaultWriter(stream)</code></a></li>
2011cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterabortreason"><code>writableStreamDefaultWriter.abort([reason])</code></a></li>
2021cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterclose"><code>writableStreamDefaultWriter.close()</code></a></li>
2031cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterclosed"><code>writableStreamDefaultWriter.closed</code></a></li>
2041cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterdesiredsize"><code>writableStreamDefaultWriter.desiredSize</code></a></li>
2051cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterready"><code>writableStreamDefaultWriter.ready</code></a></li>
2061cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterreleaselock"><code>writableStreamDefaultWriter.releaseLock()</code></a></li>
2071cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterwritechunk"><code>writableStreamDefaultWriter.write([chunk])</code></a></li>
2081cb0ef41Sopenharmony_ci</ul>
2091cb0ef41Sopenharmony_ci</li>
2101cb0ef41Sopenharmony_ci<li><a href="#class-writablestreamdefaultcontroller">Class: <code>WritableStreamDefaultController</code></a>
2111cb0ef41Sopenharmony_ci<ul>
2121cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultcontrollererrorerror"><code>writableStreamDefaultController.error([error])</code></a></li>
2131cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultcontrollersignal"><code>writableStreamDefaultController.signal</code></a></li>
2141cb0ef41Sopenharmony_ci</ul>
2151cb0ef41Sopenharmony_ci</li>
2161cb0ef41Sopenharmony_ci<li><a href="#class-transformstream">Class: <code>TransformStream</code></a>
2171cb0ef41Sopenharmony_ci<ul>
2181cb0ef41Sopenharmony_ci<li><a href="#new-transformstreamtransformer-writablestrategy-readablestrategy"><code>new TransformStream([transformer[, writableStrategy[, readableStrategy]]])</code></a></li>
2191cb0ef41Sopenharmony_ci<li><a href="#transformstreamreadable"><code>transformStream.readable</code></a></li>
2201cb0ef41Sopenharmony_ci<li><a href="#transformstreamwritable"><code>transformStream.writable</code></a></li>
2211cb0ef41Sopenharmony_ci<li><a href="#transferring-with-postmessage_2">Transferring with postMessage()</a></li>
2221cb0ef41Sopenharmony_ci</ul>
2231cb0ef41Sopenharmony_ci</li>
2241cb0ef41Sopenharmony_ci<li><a href="#class-transformstreamdefaultcontroller">Class: <code>TransformStreamDefaultController</code></a>
2251cb0ef41Sopenharmony_ci<ul>
2261cb0ef41Sopenharmony_ci<li><a href="#transformstreamdefaultcontrollerdesiredsize"><code>transformStreamDefaultController.desiredSize</code></a></li>
2271cb0ef41Sopenharmony_ci<li><a href="#transformstreamdefaultcontrollerenqueuechunk"><code>transformStreamDefaultController.enqueue([chunk])</code></a></li>
2281cb0ef41Sopenharmony_ci<li><a href="#transformstreamdefaultcontrollererrorreason"><code>transformStreamDefaultController.error([reason])</code></a></li>
2291cb0ef41Sopenharmony_ci<li><a href="#transformstreamdefaultcontrollerterminate"><code>transformStreamDefaultController.terminate()</code></a></li>
2301cb0ef41Sopenharmony_ci</ul>
2311cb0ef41Sopenharmony_ci</li>
2321cb0ef41Sopenharmony_ci<li><a href="#class-bytelengthqueuingstrategy">Class: <code>ByteLengthQueuingStrategy</code></a>
2331cb0ef41Sopenharmony_ci<ul>
2341cb0ef41Sopenharmony_ci<li><a href="#new-bytelengthqueuingstrategyinit"><code>new ByteLengthQueuingStrategy(init)</code></a></li>
2351cb0ef41Sopenharmony_ci<li><a href="#bytelengthqueuingstrategyhighwatermark"><code>byteLengthQueuingStrategy.highWaterMark</code></a></li>
2361cb0ef41Sopenharmony_ci<li><a href="#bytelengthqueuingstrategysize"><code>byteLengthQueuingStrategy.size</code></a></li>
2371cb0ef41Sopenharmony_ci</ul>
2381cb0ef41Sopenharmony_ci</li>
2391cb0ef41Sopenharmony_ci<li><a href="#class-countqueuingstrategy">Class: <code>CountQueuingStrategy</code></a>
2401cb0ef41Sopenharmony_ci<ul>
2411cb0ef41Sopenharmony_ci<li><a href="#new-countqueuingstrategyinit"><code>new CountQueuingStrategy(init)</code></a></li>
2421cb0ef41Sopenharmony_ci<li><a href="#countqueuingstrategyhighwatermark"><code>countQueuingStrategy.highWaterMark</code></a></li>
2431cb0ef41Sopenharmony_ci<li><a href="#countqueuingstrategysize"><code>countQueuingStrategy.size</code></a></li>
2441cb0ef41Sopenharmony_ci</ul>
2451cb0ef41Sopenharmony_ci</li>
2461cb0ef41Sopenharmony_ci<li><a href="#class-textencoderstream">Class: <code>TextEncoderStream</code></a>
2471cb0ef41Sopenharmony_ci<ul>
2481cb0ef41Sopenharmony_ci<li><a href="#new-textencoderstream"><code>new TextEncoderStream()</code></a></li>
2491cb0ef41Sopenharmony_ci<li><a href="#textencoderstreamencoding"><code>textEncoderStream.encoding</code></a></li>
2501cb0ef41Sopenharmony_ci<li><a href="#textencoderstreamreadable"><code>textEncoderStream.readable</code></a></li>
2511cb0ef41Sopenharmony_ci<li><a href="#textencoderstreamwritable"><code>textEncoderStream.writable</code></a></li>
2521cb0ef41Sopenharmony_ci</ul>
2531cb0ef41Sopenharmony_ci</li>
2541cb0ef41Sopenharmony_ci<li><a href="#class-textdecoderstream">Class: <code>TextDecoderStream</code></a>
2551cb0ef41Sopenharmony_ci<ul>
2561cb0ef41Sopenharmony_ci<li><a href="#new-textdecoderstreamencoding-options"><code>new TextDecoderStream([encoding[, options]])</code></a></li>
2571cb0ef41Sopenharmony_ci<li><a href="#textdecoderstreamencoding"><code>textDecoderStream.encoding</code></a></li>
2581cb0ef41Sopenharmony_ci<li><a href="#textdecoderstreamfatal"><code>textDecoderStream.fatal</code></a></li>
2591cb0ef41Sopenharmony_ci<li><a href="#textdecoderstreamignorebom"><code>textDecoderStream.ignoreBOM</code></a></li>
2601cb0ef41Sopenharmony_ci<li><a href="#textdecoderstreamreadable"><code>textDecoderStream.readable</code></a></li>
2611cb0ef41Sopenharmony_ci<li><a href="#textdecoderstreamwritable"><code>textDecoderStream.writable</code></a></li>
2621cb0ef41Sopenharmony_ci</ul>
2631cb0ef41Sopenharmony_ci</li>
2641cb0ef41Sopenharmony_ci<li><a href="#class-compressionstream">Class: <code>CompressionStream</code></a>
2651cb0ef41Sopenharmony_ci<ul>
2661cb0ef41Sopenharmony_ci<li><a href="#new-compressionstreamformat"><code>new CompressionStream(format)</code></a></li>
2671cb0ef41Sopenharmony_ci<li><a href="#compressionstreamreadable"><code>compressionStream.readable</code></a></li>
2681cb0ef41Sopenharmony_ci<li><a href="#compressionstreamwritable"><code>compressionStream.writable</code></a></li>
2691cb0ef41Sopenharmony_ci</ul>
2701cb0ef41Sopenharmony_ci</li>
2711cb0ef41Sopenharmony_ci<li><a href="#class-decompressionstream">Class: <code>DecompressionStream</code></a>
2721cb0ef41Sopenharmony_ci<ul>
2731cb0ef41Sopenharmony_ci<li><a href="#new-decompressionstreamformat"><code>new DecompressionStream(format)</code></a></li>
2741cb0ef41Sopenharmony_ci<li><a href="#decompressionstreamreadable"><code>decompressionStream.readable</code></a></li>
2751cb0ef41Sopenharmony_ci<li><a href="#decompressionstreamwritable"><code>decompressionStream.writable</code></a></li>
2761cb0ef41Sopenharmony_ci</ul>
2771cb0ef41Sopenharmony_ci</li>
2781cb0ef41Sopenharmony_ci<li><a href="#utility-consumers">Utility Consumers</a>
2791cb0ef41Sopenharmony_ci<ul>
2801cb0ef41Sopenharmony_ci<li><a href="#streamconsumersarraybufferstream"><code>streamConsumers.arrayBuffer(stream)</code></a></li>
2811cb0ef41Sopenharmony_ci<li><a href="#streamconsumersblobstream"><code>streamConsumers.blob(stream)</code></a></li>
2821cb0ef41Sopenharmony_ci<li><a href="#streamconsumersbufferstream"><code>streamConsumers.buffer(stream)</code></a></li>
2831cb0ef41Sopenharmony_ci<li><a href="#streamconsumersjsonstream"><code>streamConsumers.json(stream)</code></a></li>
2841cb0ef41Sopenharmony_ci<li><a href="#streamconsumerstextstream"><code>streamConsumers.text(stream)</code></a></li>
2851cb0ef41Sopenharmony_ci</ul>
2861cb0ef41Sopenharmony_ci</li>
2871cb0ef41Sopenharmony_ci</ul>
2881cb0ef41Sopenharmony_ci</li>
2891cb0ef41Sopenharmony_ci</ul>
2901cb0ef41Sopenharmony_ci</li>
2911cb0ef41Sopenharmony_ci</ul></div></div>
2921cb0ef41Sopenharmony_ci    </li>
2931cb0ef41Sopenharmony_ci  
2941cb0ef41Sopenharmony_ci            
2951cb0ef41Sopenharmony_ci    <li class="picker-header">
2961cb0ef41Sopenharmony_ci      <a href="#">
2971cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
2981cb0ef41Sopenharmony_ci        Index
2991cb0ef41Sopenharmony_ci      </a>
3001cb0ef41Sopenharmony_ci
3011cb0ef41Sopenharmony_ci      <div class="picker"><ul>
3021cb0ef41Sopenharmony_ci<li><a href="documentation.html" class="nav-documentation">About this documentation</a></li>
3031cb0ef41Sopenharmony_ci<li><a href="synopsis.html" class="nav-synopsis">Usage and example</a></li>
3041cb0ef41Sopenharmony_ci
3051cb0ef41Sopenharmony_ci      <li>
3061cb0ef41Sopenharmony_ci        <a href="index.html">Index</a>
3071cb0ef41Sopenharmony_ci      </li>
3081cb0ef41Sopenharmony_ci    </ul>
3091cb0ef41Sopenharmony_ci  
3101cb0ef41Sopenharmony_ci<hr class="line">
3111cb0ef41Sopenharmony_ci<ul>
3121cb0ef41Sopenharmony_ci<li><a href="assert.html" class="nav-assert">Assertion testing</a></li>
3131cb0ef41Sopenharmony_ci<li><a href="async_context.html" class="nav-async_context">Asynchronous context tracking</a></li>
3141cb0ef41Sopenharmony_ci<li><a href="async_hooks.html" class="nav-async_hooks">Async hooks</a></li>
3151cb0ef41Sopenharmony_ci<li><a href="buffer.html" class="nav-buffer">Buffer</a></li>
3161cb0ef41Sopenharmony_ci<li><a href="addons.html" class="nav-addons">C++ addons</a></li>
3171cb0ef41Sopenharmony_ci<li><a href="n-api.html" class="nav-n-api">C/C++ addons with Node-API</a></li>
3181cb0ef41Sopenharmony_ci<li><a href="embedding.html" class="nav-embedding">C++ embedder API</a></li>
3191cb0ef41Sopenharmony_ci<li><a href="child_process.html" class="nav-child_process">Child processes</a></li>
3201cb0ef41Sopenharmony_ci<li><a href="cluster.html" class="nav-cluster">Cluster</a></li>
3211cb0ef41Sopenharmony_ci<li><a href="cli.html" class="nav-cli">Command-line options</a></li>
3221cb0ef41Sopenharmony_ci<li><a href="console.html" class="nav-console">Console</a></li>
3231cb0ef41Sopenharmony_ci<li><a href="corepack.html" class="nav-corepack">Corepack</a></li>
3241cb0ef41Sopenharmony_ci<li><a href="crypto.html" class="nav-crypto">Crypto</a></li>
3251cb0ef41Sopenharmony_ci<li><a href="debugger.html" class="nav-debugger">Debugger</a></li>
3261cb0ef41Sopenharmony_ci<li><a href="deprecations.html" class="nav-deprecations">Deprecated APIs</a></li>
3271cb0ef41Sopenharmony_ci<li><a href="diagnostics_channel.html" class="nav-diagnostics_channel">Diagnostics Channel</a></li>
3281cb0ef41Sopenharmony_ci<li><a href="dns.html" class="nav-dns">DNS</a></li>
3291cb0ef41Sopenharmony_ci<li><a href="domain.html" class="nav-domain">Domain</a></li>
3301cb0ef41Sopenharmony_ci<li><a href="errors.html" class="nav-errors">Errors</a></li>
3311cb0ef41Sopenharmony_ci<li><a href="events.html" class="nav-events">Events</a></li>
3321cb0ef41Sopenharmony_ci<li><a href="fs.html" class="nav-fs">File system</a></li>
3331cb0ef41Sopenharmony_ci<li><a href="globals.html" class="nav-globals">Globals</a></li>
3341cb0ef41Sopenharmony_ci<li><a href="http.html" class="nav-http">HTTP</a></li>
3351cb0ef41Sopenharmony_ci<li><a href="http2.html" class="nav-http2">HTTP/2</a></li>
3361cb0ef41Sopenharmony_ci<li><a href="https.html" class="nav-https">HTTPS</a></li>
3371cb0ef41Sopenharmony_ci<li><a href="inspector.html" class="nav-inspector">Inspector</a></li>
3381cb0ef41Sopenharmony_ci<li><a href="intl.html" class="nav-intl">Internationalization</a></li>
3391cb0ef41Sopenharmony_ci<li><a href="modules.html" class="nav-modules">Modules: CommonJS modules</a></li>
3401cb0ef41Sopenharmony_ci<li><a href="esm.html" class="nav-esm">Modules: ECMAScript modules</a></li>
3411cb0ef41Sopenharmony_ci<li><a href="module.html" class="nav-module">Modules: <code>node:module</code> API</a></li>
3421cb0ef41Sopenharmony_ci<li><a href="packages.html" class="nav-packages">Modules: Packages</a></li>
3431cb0ef41Sopenharmony_ci<li><a href="net.html" class="nav-net">Net</a></li>
3441cb0ef41Sopenharmony_ci<li><a href="os.html" class="nav-os">OS</a></li>
3451cb0ef41Sopenharmony_ci<li><a href="path.html" class="nav-path">Path</a></li>
3461cb0ef41Sopenharmony_ci<li><a href="perf_hooks.html" class="nav-perf_hooks">Performance hooks</a></li>
3471cb0ef41Sopenharmony_ci<li><a href="permissions.html" class="nav-permissions">Permissions</a></li>
3481cb0ef41Sopenharmony_ci<li><a href="process.html" class="nav-process">Process</a></li>
3491cb0ef41Sopenharmony_ci<li><a href="punycode.html" class="nav-punycode">Punycode</a></li>
3501cb0ef41Sopenharmony_ci<li><a href="querystring.html" class="nav-querystring">Query strings</a></li>
3511cb0ef41Sopenharmony_ci<li><a href="readline.html" class="nav-readline">Readline</a></li>
3521cb0ef41Sopenharmony_ci<li><a href="repl.html" class="nav-repl">REPL</a></li>
3531cb0ef41Sopenharmony_ci<li><a href="report.html" class="nav-report">Report</a></li>
3541cb0ef41Sopenharmony_ci<li><a href="single-executable-applications.html" class="nav-single-executable-applications">Single executable applications</a></li>
3551cb0ef41Sopenharmony_ci<li><a href="stream.html" class="nav-stream">Stream</a></li>
3561cb0ef41Sopenharmony_ci<li><a href="string_decoder.html" class="nav-string_decoder">String decoder</a></li>
3571cb0ef41Sopenharmony_ci<li><a href="test.html" class="nav-test">Test runner</a></li>
3581cb0ef41Sopenharmony_ci<li><a href="timers.html" class="nav-timers">Timers</a></li>
3591cb0ef41Sopenharmony_ci<li><a href="tls.html" class="nav-tls">TLS/SSL</a></li>
3601cb0ef41Sopenharmony_ci<li><a href="tracing.html" class="nav-tracing">Trace events</a></li>
3611cb0ef41Sopenharmony_ci<li><a href="tty.html" class="nav-tty">TTY</a></li>
3621cb0ef41Sopenharmony_ci<li><a href="dgram.html" class="nav-dgram">UDP/datagram</a></li>
3631cb0ef41Sopenharmony_ci<li><a href="url.html" class="nav-url">URL</a></li>
3641cb0ef41Sopenharmony_ci<li><a href="util.html" class="nav-util">Utilities</a></li>
3651cb0ef41Sopenharmony_ci<li><a href="v8.html" class="nav-v8">V8</a></li>
3661cb0ef41Sopenharmony_ci<li><a href="vm.html" class="nav-vm">VM</a></li>
3671cb0ef41Sopenharmony_ci<li><a href="wasi.html" class="nav-wasi">WASI</a></li>
3681cb0ef41Sopenharmony_ci<li><a href="webcrypto.html" class="nav-webcrypto">Web Crypto API</a></li>
3691cb0ef41Sopenharmony_ci<li><a href="webstreams.html" class="nav-webstreams active">Web Streams API</a></li>
3701cb0ef41Sopenharmony_ci<li><a href="worker_threads.html" class="nav-worker_threads">Worker threads</a></li>
3711cb0ef41Sopenharmony_ci<li><a href="zlib.html" class="nav-zlib">Zlib</a></li>
3721cb0ef41Sopenharmony_ci</ul>
3731cb0ef41Sopenharmony_ci<hr class="line">
3741cb0ef41Sopenharmony_ci<ul>
3751cb0ef41Sopenharmony_ci<li><a href="https://github.com/nodejs/node" class="nav-https-github-com-nodejs-node">Code repository and issue tracker</a></li>
3761cb0ef41Sopenharmony_ci</ul></div>
3771cb0ef41Sopenharmony_ci    </li>
3781cb0ef41Sopenharmony_ci  
3791cb0ef41Sopenharmony_ci            
3801cb0ef41Sopenharmony_ci    <li class="picker-header">
3811cb0ef41Sopenharmony_ci      <a href="#">
3821cb0ef41Sopenharmony_ci        <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
3831cb0ef41Sopenharmony_ci        Other versions
3841cb0ef41Sopenharmony_ci      </a>
3851cb0ef41Sopenharmony_ci      <div class="picker"><ol id="alt-docs"><li><a href="https://nodejs.org/docs/latest-v21.x/api/webstreams.html">21.x</a></li>
3861cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v20.x/api/webstreams.html">20.x <b>LTS</b></a></li>
3871cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v19.x/api/webstreams.html">19.x</a></li>
3881cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v18.x/api/webstreams.html">18.x <b>LTS</b></a></li>
3891cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v17.x/api/webstreams.html">17.x</a></li>
3901cb0ef41Sopenharmony_ci<li><a href="https://nodejs.org/docs/latest-v16.x/api/webstreams.html">16.x</a></li></ol></div>
3911cb0ef41Sopenharmony_ci    </li>
3921cb0ef41Sopenharmony_ci  
3931cb0ef41Sopenharmony_ci            <li class="picker-header">
3941cb0ef41Sopenharmony_ci              <a href="#">
3951cb0ef41Sopenharmony_ci                <span class="collapsed-arrow">&#x25ba;</span><span class="expanded-arrow">&#x25bc;</span>
3961cb0ef41Sopenharmony_ci                Options
3971cb0ef41Sopenharmony_ci              </a>
3981cb0ef41Sopenharmony_ci        
3991cb0ef41Sopenharmony_ci              <div class="picker">
4001cb0ef41Sopenharmony_ci                <ul>
4011cb0ef41Sopenharmony_ci                  <li>
4021cb0ef41Sopenharmony_ci                    <a href="all.html">View on single page</a>
4031cb0ef41Sopenharmony_ci                  </li>
4041cb0ef41Sopenharmony_ci                  <li>
4051cb0ef41Sopenharmony_ci                    <a href="webstreams.json">View as JSON</a>
4061cb0ef41Sopenharmony_ci                  </li>
4071cb0ef41Sopenharmony_ci                  <li class="edit_on_github"><a href="https://github.com/nodejs/node/edit/main/doc/api/webstreams.md">Edit on GitHub</a></li>    
4081cb0ef41Sopenharmony_ci                </ul>
4091cb0ef41Sopenharmony_ci              </div>
4101cb0ef41Sopenharmony_ci            </li>
4111cb0ef41Sopenharmony_ci          </ul>
4121cb0ef41Sopenharmony_ci        </div>
4131cb0ef41Sopenharmony_ci        <hr>
4141cb0ef41Sopenharmony_ci      </header>
4151cb0ef41Sopenharmony_ci
4161cb0ef41Sopenharmony_ci      <details id="toc" open><summary>Table of contents</summary><ul>
4171cb0ef41Sopenharmony_ci<li><span class="stability_1"><a href="#web-streams-api">Web Streams API</a></span>
4181cb0ef41Sopenharmony_ci<ul>
4191cb0ef41Sopenharmony_ci<li><a href="#overview">Overview</a>
4201cb0ef41Sopenharmony_ci<ul>
4211cb0ef41Sopenharmony_ci<li><a href="#example-readablestream">Example <code>ReadableStream</code></a></li>
4221cb0ef41Sopenharmony_ci</ul>
4231cb0ef41Sopenharmony_ci</li>
4241cb0ef41Sopenharmony_ci<li><a href="#api">API</a>
4251cb0ef41Sopenharmony_ci<ul>
4261cb0ef41Sopenharmony_ci<li><a href="#class-readablestream">Class: <code>ReadableStream</code></a>
4271cb0ef41Sopenharmony_ci<ul>
4281cb0ef41Sopenharmony_ci<li><a href="#new-readablestreamunderlyingsource--strategy"><code>new ReadableStream([underlyingSource [, strategy]])</code></a></li>
4291cb0ef41Sopenharmony_ci<li><a href="#readablestreamlocked"><code>readableStream.locked</code></a></li>
4301cb0ef41Sopenharmony_ci<li><a href="#readablestreamcancelreason"><code>readableStream.cancel([reason])</code></a></li>
4311cb0ef41Sopenharmony_ci<li><a href="#readablestreamgetreaderoptions"><code>readableStream.getReader([options])</code></a></li>
4321cb0ef41Sopenharmony_ci<li><a href="#readablestreampipethroughtransform-options"><code>readableStream.pipeThrough(transform[, options])</code></a></li>
4331cb0ef41Sopenharmony_ci<li><a href="#readablestreampipetodestination-options"><code>readableStream.pipeTo(destination[, options])</code></a></li>
4341cb0ef41Sopenharmony_ci<li><a href="#readablestreamtee"><code>readableStream.tee()</code></a></li>
4351cb0ef41Sopenharmony_ci<li><a href="#readablestreamvaluesoptions"><code>readableStream.values([options])</code></a></li>
4361cb0ef41Sopenharmony_ci<li><a href="#async-iteration">Async Iteration</a></li>
4371cb0ef41Sopenharmony_ci<li><a href="#transferring-with-postmessage">Transferring with <code>postMessage()</code></a></li>
4381cb0ef41Sopenharmony_ci</ul>
4391cb0ef41Sopenharmony_ci</li>
4401cb0ef41Sopenharmony_ci<li><a href="#class-readablestreamdefaultreader">Class: <code>ReadableStreamDefaultReader</code></a>
4411cb0ef41Sopenharmony_ci<ul>
4421cb0ef41Sopenharmony_ci<li><a href="#new-readablestreamdefaultreaderstream"><code>new ReadableStreamDefaultReader(stream)</code></a></li>
4431cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultreadercancelreason"><code>readableStreamDefaultReader.cancel([reason])</code></a></li>
4441cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultreaderclosed"><code>readableStreamDefaultReader.closed</code></a></li>
4451cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultreaderread"><code>readableStreamDefaultReader.read()</code></a></li>
4461cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultreaderreleaselock"><code>readableStreamDefaultReader.releaseLock()</code></a></li>
4471cb0ef41Sopenharmony_ci</ul>
4481cb0ef41Sopenharmony_ci</li>
4491cb0ef41Sopenharmony_ci<li><a href="#class-readablestreambyobreader">Class: <code>ReadableStreamBYOBReader</code></a>
4501cb0ef41Sopenharmony_ci<ul>
4511cb0ef41Sopenharmony_ci<li><a href="#new-readablestreambyobreaderstream"><code>new ReadableStreamBYOBReader(stream)</code></a></li>
4521cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobreadercancelreason"><code>readableStreamBYOBReader.cancel([reason])</code></a></li>
4531cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobreaderclosed"><code>readableStreamBYOBReader.closed</code></a></li>
4541cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobreaderreadview"><code>readableStreamBYOBReader.read(view)</code></a></li>
4551cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobreaderreleaselock"><code>readableStreamBYOBReader.releaseLock()</code></a></li>
4561cb0ef41Sopenharmony_ci</ul>
4571cb0ef41Sopenharmony_ci</li>
4581cb0ef41Sopenharmony_ci<li><a href="#class-readablestreamdefaultcontroller">Class: <code>ReadableStreamDefaultController</code></a>
4591cb0ef41Sopenharmony_ci<ul>
4601cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultcontrollerclose"><code>readableStreamDefaultController.close()</code></a></li>
4611cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultcontrollerdesiredsize"><code>readableStreamDefaultController.desiredSize</code></a></li>
4621cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultcontrollerenqueuechunk"><code>readableStreamDefaultController.enqueue([chunk])</code></a></li>
4631cb0ef41Sopenharmony_ci<li><a href="#readablestreamdefaultcontrollererrorerror"><code>readableStreamDefaultController.error([error])</code></a></li>
4641cb0ef41Sopenharmony_ci</ul>
4651cb0ef41Sopenharmony_ci</li>
4661cb0ef41Sopenharmony_ci<li><a href="#class-readablebytestreamcontroller">Class: <code>ReadableByteStreamController</code></a>
4671cb0ef41Sopenharmony_ci<ul>
4681cb0ef41Sopenharmony_ci<li><a href="#readablebytestreamcontrollerbyobrequest"><code>readableByteStreamController.byobRequest</code></a></li>
4691cb0ef41Sopenharmony_ci<li><a href="#readablebytestreamcontrollerclose"><code>readableByteStreamController.close()</code></a></li>
4701cb0ef41Sopenharmony_ci<li><a href="#readablebytestreamcontrollerdesiredsize"><code>readableByteStreamController.desiredSize</code></a></li>
4711cb0ef41Sopenharmony_ci<li><a href="#readablebytestreamcontrollerenqueuechunk"><code>readableByteStreamController.enqueue(chunk)</code></a></li>
4721cb0ef41Sopenharmony_ci<li><a href="#readablebytestreamcontrollererrorerror"><code>readableByteStreamController.error([error])</code></a></li>
4731cb0ef41Sopenharmony_ci</ul>
4741cb0ef41Sopenharmony_ci</li>
4751cb0ef41Sopenharmony_ci<li><a href="#class-readablestreambyobrequest">Class: <code>ReadableStreamBYOBRequest</code></a>
4761cb0ef41Sopenharmony_ci<ul>
4771cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobrequestrespondbyteswritten"><code>readableStreamBYOBRequest.respond(bytesWritten)</code></a></li>
4781cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobrequestrespondwithnewviewview"><code>readableStreamBYOBRequest.respondWithNewView(view)</code></a></li>
4791cb0ef41Sopenharmony_ci<li><a href="#readablestreambyobrequestview"><code>readableStreamBYOBRequest.view</code></a></li>
4801cb0ef41Sopenharmony_ci</ul>
4811cb0ef41Sopenharmony_ci</li>
4821cb0ef41Sopenharmony_ci<li><a href="#class-writablestream">Class: <code>WritableStream</code></a>
4831cb0ef41Sopenharmony_ci<ul>
4841cb0ef41Sopenharmony_ci<li><a href="#new-writablestreamunderlyingsink-strategy"><code>new WritableStream([underlyingSink[, strategy]])</code></a></li>
4851cb0ef41Sopenharmony_ci<li><a href="#writablestreamabortreason"><code>writableStream.abort([reason])</code></a></li>
4861cb0ef41Sopenharmony_ci<li><a href="#writablestreamclose"><code>writableStream.close()</code></a></li>
4871cb0ef41Sopenharmony_ci<li><a href="#writablestreamgetwriter"><code>writableStream.getWriter()</code></a></li>
4881cb0ef41Sopenharmony_ci<li><a href="#writablestreamlocked"><code>writableStream.locked</code></a></li>
4891cb0ef41Sopenharmony_ci<li><a href="#transferring-with-postmessage_1">Transferring with postMessage()</a></li>
4901cb0ef41Sopenharmony_ci</ul>
4911cb0ef41Sopenharmony_ci</li>
4921cb0ef41Sopenharmony_ci<li><a href="#class-writablestreamdefaultwriter">Class: <code>WritableStreamDefaultWriter</code></a>
4931cb0ef41Sopenharmony_ci<ul>
4941cb0ef41Sopenharmony_ci<li><a href="#new-writablestreamdefaultwriterstream"><code>new WritableStreamDefaultWriter(stream)</code></a></li>
4951cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterabortreason"><code>writableStreamDefaultWriter.abort([reason])</code></a></li>
4961cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterclose"><code>writableStreamDefaultWriter.close()</code></a></li>
4971cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterclosed"><code>writableStreamDefaultWriter.closed</code></a></li>
4981cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterdesiredsize"><code>writableStreamDefaultWriter.desiredSize</code></a></li>
4991cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterready"><code>writableStreamDefaultWriter.ready</code></a></li>
5001cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterreleaselock"><code>writableStreamDefaultWriter.releaseLock()</code></a></li>
5011cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultwriterwritechunk"><code>writableStreamDefaultWriter.write([chunk])</code></a></li>
5021cb0ef41Sopenharmony_ci</ul>
5031cb0ef41Sopenharmony_ci</li>
5041cb0ef41Sopenharmony_ci<li><a href="#class-writablestreamdefaultcontroller">Class: <code>WritableStreamDefaultController</code></a>
5051cb0ef41Sopenharmony_ci<ul>
5061cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultcontrollererrorerror"><code>writableStreamDefaultController.error([error])</code></a></li>
5071cb0ef41Sopenharmony_ci<li><a href="#writablestreamdefaultcontrollersignal"><code>writableStreamDefaultController.signal</code></a></li>
5081cb0ef41Sopenharmony_ci</ul>
5091cb0ef41Sopenharmony_ci</li>
5101cb0ef41Sopenharmony_ci<li><a href="#class-transformstream">Class: <code>TransformStream</code></a>
5111cb0ef41Sopenharmony_ci<ul>
5121cb0ef41Sopenharmony_ci<li><a href="#new-transformstreamtransformer-writablestrategy-readablestrategy"><code>new TransformStream([transformer[, writableStrategy[, readableStrategy]]])</code></a></li>
5131cb0ef41Sopenharmony_ci<li><a href="#transformstreamreadable"><code>transformStream.readable</code></a></li>
5141cb0ef41Sopenharmony_ci<li><a href="#transformstreamwritable"><code>transformStream.writable</code></a></li>
5151cb0ef41Sopenharmony_ci<li><a href="#transferring-with-postmessage_2">Transferring with postMessage()</a></li>
5161cb0ef41Sopenharmony_ci</ul>
5171cb0ef41Sopenharmony_ci</li>
5181cb0ef41Sopenharmony_ci<li><a href="#class-transformstreamdefaultcontroller">Class: <code>TransformStreamDefaultController</code></a>
5191cb0ef41Sopenharmony_ci<ul>
5201cb0ef41Sopenharmony_ci<li><a href="#transformstreamdefaultcontrollerdesiredsize"><code>transformStreamDefaultController.desiredSize</code></a></li>
5211cb0ef41Sopenharmony_ci<li><a href="#transformstreamdefaultcontrollerenqueuechunk"><code>transformStreamDefaultController.enqueue([chunk])</code></a></li>
5221cb0ef41Sopenharmony_ci<li><a href="#transformstreamdefaultcontrollererrorreason"><code>transformStreamDefaultController.error([reason])</code></a></li>
5231cb0ef41Sopenharmony_ci<li><a href="#transformstreamdefaultcontrollerterminate"><code>transformStreamDefaultController.terminate()</code></a></li>
5241cb0ef41Sopenharmony_ci</ul>
5251cb0ef41Sopenharmony_ci</li>
5261cb0ef41Sopenharmony_ci<li><a href="#class-bytelengthqueuingstrategy">Class: <code>ByteLengthQueuingStrategy</code></a>
5271cb0ef41Sopenharmony_ci<ul>
5281cb0ef41Sopenharmony_ci<li><a href="#new-bytelengthqueuingstrategyinit"><code>new ByteLengthQueuingStrategy(init)</code></a></li>
5291cb0ef41Sopenharmony_ci<li><a href="#bytelengthqueuingstrategyhighwatermark"><code>byteLengthQueuingStrategy.highWaterMark</code></a></li>
5301cb0ef41Sopenharmony_ci<li><a href="#bytelengthqueuingstrategysize"><code>byteLengthQueuingStrategy.size</code></a></li>
5311cb0ef41Sopenharmony_ci</ul>
5321cb0ef41Sopenharmony_ci</li>
5331cb0ef41Sopenharmony_ci<li><a href="#class-countqueuingstrategy">Class: <code>CountQueuingStrategy</code></a>
5341cb0ef41Sopenharmony_ci<ul>
5351cb0ef41Sopenharmony_ci<li><a href="#new-countqueuingstrategyinit"><code>new CountQueuingStrategy(init)</code></a></li>
5361cb0ef41Sopenharmony_ci<li><a href="#countqueuingstrategyhighwatermark"><code>countQueuingStrategy.highWaterMark</code></a></li>
5371cb0ef41Sopenharmony_ci<li><a href="#countqueuingstrategysize"><code>countQueuingStrategy.size</code></a></li>
5381cb0ef41Sopenharmony_ci</ul>
5391cb0ef41Sopenharmony_ci</li>
5401cb0ef41Sopenharmony_ci<li><a href="#class-textencoderstream">Class: <code>TextEncoderStream</code></a>
5411cb0ef41Sopenharmony_ci<ul>
5421cb0ef41Sopenharmony_ci<li><a href="#new-textencoderstream"><code>new TextEncoderStream()</code></a></li>
5431cb0ef41Sopenharmony_ci<li><a href="#textencoderstreamencoding"><code>textEncoderStream.encoding</code></a></li>
5441cb0ef41Sopenharmony_ci<li><a href="#textencoderstreamreadable"><code>textEncoderStream.readable</code></a></li>
5451cb0ef41Sopenharmony_ci<li><a href="#textencoderstreamwritable"><code>textEncoderStream.writable</code></a></li>
5461cb0ef41Sopenharmony_ci</ul>
5471cb0ef41Sopenharmony_ci</li>
5481cb0ef41Sopenharmony_ci<li><a href="#class-textdecoderstream">Class: <code>TextDecoderStream</code></a>
5491cb0ef41Sopenharmony_ci<ul>
5501cb0ef41Sopenharmony_ci<li><a href="#new-textdecoderstreamencoding-options"><code>new TextDecoderStream([encoding[, options]])</code></a></li>
5511cb0ef41Sopenharmony_ci<li><a href="#textdecoderstreamencoding"><code>textDecoderStream.encoding</code></a></li>
5521cb0ef41Sopenharmony_ci<li><a href="#textdecoderstreamfatal"><code>textDecoderStream.fatal</code></a></li>
5531cb0ef41Sopenharmony_ci<li><a href="#textdecoderstreamignorebom"><code>textDecoderStream.ignoreBOM</code></a></li>
5541cb0ef41Sopenharmony_ci<li><a href="#textdecoderstreamreadable"><code>textDecoderStream.readable</code></a></li>
5551cb0ef41Sopenharmony_ci<li><a href="#textdecoderstreamwritable"><code>textDecoderStream.writable</code></a></li>
5561cb0ef41Sopenharmony_ci</ul>
5571cb0ef41Sopenharmony_ci</li>
5581cb0ef41Sopenharmony_ci<li><a href="#class-compressionstream">Class: <code>CompressionStream</code></a>
5591cb0ef41Sopenharmony_ci<ul>
5601cb0ef41Sopenharmony_ci<li><a href="#new-compressionstreamformat"><code>new CompressionStream(format)</code></a></li>
5611cb0ef41Sopenharmony_ci<li><a href="#compressionstreamreadable"><code>compressionStream.readable</code></a></li>
5621cb0ef41Sopenharmony_ci<li><a href="#compressionstreamwritable"><code>compressionStream.writable</code></a></li>
5631cb0ef41Sopenharmony_ci</ul>
5641cb0ef41Sopenharmony_ci</li>
5651cb0ef41Sopenharmony_ci<li><a href="#class-decompressionstream">Class: <code>DecompressionStream</code></a>
5661cb0ef41Sopenharmony_ci<ul>
5671cb0ef41Sopenharmony_ci<li><a href="#new-decompressionstreamformat"><code>new DecompressionStream(format)</code></a></li>
5681cb0ef41Sopenharmony_ci<li><a href="#decompressionstreamreadable"><code>decompressionStream.readable</code></a></li>
5691cb0ef41Sopenharmony_ci<li><a href="#decompressionstreamwritable"><code>decompressionStream.writable</code></a></li>
5701cb0ef41Sopenharmony_ci</ul>
5711cb0ef41Sopenharmony_ci</li>
5721cb0ef41Sopenharmony_ci<li><a href="#utility-consumers">Utility Consumers</a>
5731cb0ef41Sopenharmony_ci<ul>
5741cb0ef41Sopenharmony_ci<li><a href="#streamconsumersarraybufferstream"><code>streamConsumers.arrayBuffer(stream)</code></a></li>
5751cb0ef41Sopenharmony_ci<li><a href="#streamconsumersblobstream"><code>streamConsumers.blob(stream)</code></a></li>
5761cb0ef41Sopenharmony_ci<li><a href="#streamconsumersbufferstream"><code>streamConsumers.buffer(stream)</code></a></li>
5771cb0ef41Sopenharmony_ci<li><a href="#streamconsumersjsonstream"><code>streamConsumers.json(stream)</code></a></li>
5781cb0ef41Sopenharmony_ci<li><a href="#streamconsumerstextstream"><code>streamConsumers.text(stream)</code></a></li>
5791cb0ef41Sopenharmony_ci</ul>
5801cb0ef41Sopenharmony_ci</li>
5811cb0ef41Sopenharmony_ci</ul>
5821cb0ef41Sopenharmony_ci</li>
5831cb0ef41Sopenharmony_ci</ul>
5841cb0ef41Sopenharmony_ci</li>
5851cb0ef41Sopenharmony_ci</ul></details>
5861cb0ef41Sopenharmony_ci
5871cb0ef41Sopenharmony_ci      <div id="apicontent">
5881cb0ef41Sopenharmony_ci        <h2>Web Streams API<span><a class="mark" href="#web-streams-api" id="web-streams-api">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_web_streams_api"></a></h2>
5891cb0ef41Sopenharmony_ci
5901cb0ef41Sopenharmony_ci<div class="api_metadata">
5911cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
5921cb0ef41Sopenharmony_ci<table>
5931cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
5941cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
5951cb0ef41Sopenharmony_ci<td><p>Use of this API no longer emit a runtime warning.</p></td></tr>
5961cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
5971cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
5981cb0ef41Sopenharmony_ci</tbody></table>
5991cb0ef41Sopenharmony_ci</details>
6001cb0ef41Sopenharmony_ci</div>
6011cb0ef41Sopenharmony_ci<p></p><div class="api_stability api_stability_1"><a href="documentation.html#stability-index">Stability: 1</a> - Experimental.</div><p></p>
6021cb0ef41Sopenharmony_ci<p>An implementation of the <a href="https://streams.spec.whatwg.org/">WHATWG Streams Standard</a>.</p>
6031cb0ef41Sopenharmony_ci<section><h3>Overview<span><a class="mark" href="#overview" id="overview">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_overview"></a></h3>
6041cb0ef41Sopenharmony_ci<p>The <a href="https://streams.spec.whatwg.org/">WHATWG Streams Standard</a> (or "web streams") defines an API for handling
6051cb0ef41Sopenharmony_cistreaming data. It is similar to the Node.js <a href="stream.html">Streams</a> API but emerged later
6061cb0ef41Sopenharmony_ciand has become the "standard" API for streaming data across many JavaScript
6071cb0ef41Sopenharmony_cienvironments.</p>
6081cb0ef41Sopenharmony_ci<p>There are three primary types of objects:</p>
6091cb0ef41Sopenharmony_ci<ul>
6101cb0ef41Sopenharmony_ci<li><code>ReadableStream</code> - Represents a source of streaming data.</li>
6111cb0ef41Sopenharmony_ci<li><code>WritableStream</code> - Represents a destination for streaming data.</li>
6121cb0ef41Sopenharmony_ci<li><code>TransformStream</code> - Represents an algorithm for transforming streaming data.</li>
6131cb0ef41Sopenharmony_ci</ul>
6141cb0ef41Sopenharmony_ci<h4>Example <code>ReadableStream</code><span><a class="mark" href="#example-readablestream" id="example-readablestream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_example_readablestream"></a></h4>
6151cb0ef41Sopenharmony_ci<p>This example creates a simple <code>ReadableStream</code> that pushes the current
6161cb0ef41Sopenharmony_ci<code>performance.now()</code> timestamp once every second forever. An async iterable
6171cb0ef41Sopenharmony_ciis used to read the data from the stream.</p>
6181cb0ef41Sopenharmony_ci
6191cb0ef41Sopenharmony_ci<pre class="with-17-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> {
6201cb0ef41Sopenharmony_ci  <span class="hljs-title class_">ReadableStream</span>,
6211cb0ef41Sopenharmony_ci} <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream/web'</span>;
6221cb0ef41Sopenharmony_ci
6231cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> {
6241cb0ef41Sopenharmony_ci  <span class="hljs-built_in">setInterval</span> <span class="hljs-keyword">as</span> every,
6251cb0ef41Sopenharmony_ci} <span class="hljs-keyword">from</span> <span class="hljs-string">'node:timers/promises'</span>;
6261cb0ef41Sopenharmony_ci
6271cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> {
6281cb0ef41Sopenharmony_ci  performance,
6291cb0ef41Sopenharmony_ci} <span class="hljs-keyword">from</span> <span class="hljs-string">'node:perf_hooks'</span>;
6301cb0ef41Sopenharmony_ci
6311cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">SECOND</span> = <span class="hljs-number">1000</span>;
6321cb0ef41Sopenharmony_ci
6331cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ReadableStream</span>({
6341cb0ef41Sopenharmony_ci  <span class="hljs-keyword">async</span> <span class="hljs-title function_">start</span>(<span class="hljs-params">controller</span>) {
6351cb0ef41Sopenharmony_ci    <span class="hljs-keyword">for</span> <span class="hljs-keyword">await</span> (<span class="hljs-keyword">const</span> _ <span class="hljs-keyword">of</span> <span class="hljs-title function_">every</span>(<span class="hljs-variable constant_">SECOND</span>))
6361cb0ef41Sopenharmony_ci      controller.<span class="hljs-title function_">enqueue</span>(performance.<span class="hljs-title function_">now</span>());
6371cb0ef41Sopenharmony_ci  },
6381cb0ef41Sopenharmony_ci});
6391cb0ef41Sopenharmony_ci
6401cb0ef41Sopenharmony_ci<span class="hljs-keyword">for</span> <span class="hljs-keyword">await</span> (<span class="hljs-keyword">const</span> value <span class="hljs-keyword">of</span> stream)
6411cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(value);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> {
6421cb0ef41Sopenharmony_ci  <span class="hljs-title class_">ReadableStream</span>,
6431cb0ef41Sopenharmony_ci} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream/web'</span>);
6441cb0ef41Sopenharmony_ci
6451cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> {
6461cb0ef41Sopenharmony_ci  <span class="hljs-attr">setInterval</span>: every,
6471cb0ef41Sopenharmony_ci} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:timers/promises'</span>);
6481cb0ef41Sopenharmony_ci
6491cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> {
6501cb0ef41Sopenharmony_ci  performance,
6511cb0ef41Sopenharmony_ci} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:perf_hooks'</span>);
6521cb0ef41Sopenharmony_ci
6531cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> <span class="hljs-variable constant_">SECOND</span> = <span class="hljs-number">1000</span>;
6541cb0ef41Sopenharmony_ci
6551cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ReadableStream</span>({
6561cb0ef41Sopenharmony_ci  <span class="hljs-keyword">async</span> <span class="hljs-title function_">start</span>(<span class="hljs-params">controller</span>) {
6571cb0ef41Sopenharmony_ci    <span class="hljs-keyword">for</span> <span class="hljs-keyword">await</span> (<span class="hljs-keyword">const</span> _ <span class="hljs-keyword">of</span> <span class="hljs-title function_">every</span>(<span class="hljs-variable constant_">SECOND</span>))
6581cb0ef41Sopenharmony_ci      controller.<span class="hljs-title function_">enqueue</span>(performance.<span class="hljs-title function_">now</span>());
6591cb0ef41Sopenharmony_ci  },
6601cb0ef41Sopenharmony_ci});
6611cb0ef41Sopenharmony_ci
6621cb0ef41Sopenharmony_ci(<span class="hljs-keyword">async</span> () => {
6631cb0ef41Sopenharmony_ci  <span class="hljs-keyword">for</span> <span class="hljs-keyword">await</span> (<span class="hljs-keyword">const</span> value <span class="hljs-keyword">of</span> stream)
6641cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(value);
6651cb0ef41Sopenharmony_ci})();</code><button class="copy-button">copy</button></pre>
6661cb0ef41Sopenharmony_ci</section><section><h3>API<span><a class="mark" href="#api" id="api">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_api"></a></h3>
6671cb0ef41Sopenharmony_ci<h4>Class: <code>ReadableStream</code><span><a class="mark" href="#class-readablestream" id="class-readablestream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_readablestream"></a></h4>
6681cb0ef41Sopenharmony_ci<div class="api_metadata">
6691cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
6701cb0ef41Sopenharmony_ci<table>
6711cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
6721cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
6731cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
6741cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
6751cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
6761cb0ef41Sopenharmony_ci</tbody></table>
6771cb0ef41Sopenharmony_ci</details>
6781cb0ef41Sopenharmony_ci</div>
6791cb0ef41Sopenharmony_ci<h5><code>new ReadableStream([underlyingSource [, strategy]])</code><span><a class="mark" href="#new-readablestreamunderlyingsource--strategy" id="new-readablestreamunderlyingsource--strategy">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_new_readablestream_underlyingsource_strategy"></a></h5>
6801cb0ef41Sopenharmony_ci<div class="api_metadata">
6811cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
6821cb0ef41Sopenharmony_ci</div>
6831cb0ef41Sopenharmony_ci<!--lint disable maximum-line-length remark-lint-->
6841cb0ef41Sopenharmony_ci<ul>
6851cb0ef41Sopenharmony_ci<li><code>underlyingSource</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
6861cb0ef41Sopenharmony_ci<ul>
6871cb0ef41Sopenharmony_ci<li><code>start</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function that is invoked immediately when
6881cb0ef41Sopenharmony_cithe <code>ReadableStream</code> is created.
6891cb0ef41Sopenharmony_ci<ul>
6901cb0ef41Sopenharmony_ci<li><code>controller</code> <a href="webstreams.html#class-readablestreamdefaultcontroller" class="type">&#x3C;ReadableStreamDefaultController></a> | <a href="webstreams.html#class-readablebytestreamcontroller" class="type">&#x3C;ReadableByteStreamController></a></li>
6911cb0ef41Sopenharmony_ci<li>Returns: <code>undefined</code> or a promise fulfilled with <code>undefined</code>.</li>
6921cb0ef41Sopenharmony_ci</ul>
6931cb0ef41Sopenharmony_ci</li>
6941cb0ef41Sopenharmony_ci<li><code>pull</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function that is called repeatedly when the
6951cb0ef41Sopenharmony_ci<code>ReadableStream</code> internal queue is not full. The operation may be sync or
6961cb0ef41Sopenharmony_ciasync. If async, the function will not be called again until the previously
6971cb0ef41Sopenharmony_cireturned promise is fulfilled.
6981cb0ef41Sopenharmony_ci<ul>
6991cb0ef41Sopenharmony_ci<li><code>controller</code> <a href="webstreams.html#class-readablestreamdefaultcontroller" class="type">&#x3C;ReadableStreamDefaultController></a> | <a href="webstreams.html#class-readablebytestreamcontroller" class="type">&#x3C;ReadableByteStreamController></a></li>
7001cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
7011cb0ef41Sopenharmony_ci</ul>
7021cb0ef41Sopenharmony_ci</li>
7031cb0ef41Sopenharmony_ci<li><code>cancel</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function that is called when the
7041cb0ef41Sopenharmony_ci<code>ReadableStream</code> is canceled.
7051cb0ef41Sopenharmony_ci<ul>
7061cb0ef41Sopenharmony_ci<li><code>reason</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
7071cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
7081cb0ef41Sopenharmony_ci</ul>
7091cb0ef41Sopenharmony_ci</li>
7101cb0ef41Sopenharmony_ci<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Must be <code>'bytes'</code> or <code>undefined</code>.</li>
7111cb0ef41Sopenharmony_ci<li><code>autoAllocateChunkSize</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> Used only when <code>type</code> is equal to
7121cb0ef41Sopenharmony_ci<code>'bytes'</code>. When set to a non-zero value a view buffer is automatically
7131cb0ef41Sopenharmony_ciallocated to <code>ReadableByteStreamController.byobRequest</code>. When not set
7141cb0ef41Sopenharmony_cione must use stream's internal queues to transfer data via the default
7151cb0ef41Sopenharmony_cireader <code>ReadableStreamDefaultReader</code>.</li>
7161cb0ef41Sopenharmony_ci</ul>
7171cb0ef41Sopenharmony_ci</li>
7181cb0ef41Sopenharmony_ci<li><code>strategy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
7191cb0ef41Sopenharmony_ci<ul>
7201cb0ef41Sopenharmony_ci<li><code>highWaterMark</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The maximum internal queue size before backpressure
7211cb0ef41Sopenharmony_ciis applied.</li>
7221cb0ef41Sopenharmony_ci<li><code>size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function used to identify the size of each
7231cb0ef41Sopenharmony_cichunk of data.
7241cb0ef41Sopenharmony_ci<ul>
7251cb0ef41Sopenharmony_ci<li><code>chunk</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
7261cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
7271cb0ef41Sopenharmony_ci</ul>
7281cb0ef41Sopenharmony_ci</li>
7291cb0ef41Sopenharmony_ci</ul>
7301cb0ef41Sopenharmony_ci</li>
7311cb0ef41Sopenharmony_ci</ul>
7321cb0ef41Sopenharmony_ci<!--lint enable maximum-line-length remark-lint-->
7331cb0ef41Sopenharmony_ci<h5><code>readableStream.locked</code><span><a class="mark" href="#readablestreamlocked" id="readablestreamlocked">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestream_locked"></a></h5>
7341cb0ef41Sopenharmony_ci<div class="api_metadata">
7351cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
7361cb0ef41Sopenharmony_ci</div>
7371cb0ef41Sopenharmony_ci<ul>
7381cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> Set to <code>true</code> if there is an active reader for this
7391cb0ef41Sopenharmony_ci<a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>.</li>
7401cb0ef41Sopenharmony_ci</ul>
7411cb0ef41Sopenharmony_ci<p>The <code>readableStream.locked</code> property is <code>false</code> by default, and is
7421cb0ef41Sopenharmony_ciswitched to <code>true</code> while there is an active reader consuming the
7431cb0ef41Sopenharmony_cistream's data.</p>
7441cb0ef41Sopenharmony_ci<h5><code>readableStream.cancel([reason])</code><span><a class="mark" href="#readablestreamcancelreason" id="readablestreamcancelreason">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestream_cancel_reason"></a></h5>
7451cb0ef41Sopenharmony_ci<div class="api_metadata">
7461cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
7471cb0ef41Sopenharmony_ci</div>
7481cb0ef41Sopenharmony_ci<ul>
7491cb0ef41Sopenharmony_ci<li><code>reason</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
7501cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code> once cancelation has
7511cb0ef41Sopenharmony_cibeen completed.</li>
7521cb0ef41Sopenharmony_ci</ul>
7531cb0ef41Sopenharmony_ci<h5><code>readableStream.getReader([options])</code><span><a class="mark" href="#readablestreamgetreaderoptions" id="readablestreamgetreaderoptions">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestream_getreader_options"></a></h5>
7541cb0ef41Sopenharmony_ci<div class="api_metadata">
7551cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
7561cb0ef41Sopenharmony_ci</div>
7571cb0ef41Sopenharmony_ci<ul>
7581cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
7591cb0ef41Sopenharmony_ci<ul>
7601cb0ef41Sopenharmony_ci<li><code>mode</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> <code>'byob'</code> or <code>undefined</code></li>
7611cb0ef41Sopenharmony_ci</ul>
7621cb0ef41Sopenharmony_ci</li>
7631cb0ef41Sopenharmony_ci<li>Returns: <a href="webstreams.html#class-readablestreamdefaultreader" class="type">&#x3C;ReadableStreamDefaultReader></a> | <a href="webstreams.html#class-readablestreambyobreader" class="type">&#x3C;ReadableStreamBYOBReader></a></li>
7641cb0ef41Sopenharmony_ci</ul>
7651cb0ef41Sopenharmony_ci
7661cb0ef41Sopenharmony_ci<pre class="with-54-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">ReadableStream</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream/web'</span>;
7671cb0ef41Sopenharmony_ci
7681cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ReadableStream</span>();
7691cb0ef41Sopenharmony_ci
7701cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> reader = stream.<span class="hljs-title function_">getReader</span>();
7711cb0ef41Sopenharmony_ci
7721cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-keyword">await</span> reader.<span class="hljs-title function_">read</span>());</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { <span class="hljs-title class_">ReadableStream</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream/web'</span>);
7731cb0ef41Sopenharmony_ci
7741cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ReadableStream</span>();
7751cb0ef41Sopenharmony_ci
7761cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> reader = stream.<span class="hljs-title function_">getReader</span>();
7771cb0ef41Sopenharmony_ci
7781cb0ef41Sopenharmony_cireader.<span class="hljs-title function_">read</span>().<span class="hljs-title function_">then</span>(<span class="hljs-variable language_">console</span>.<span class="hljs-property">log</span>);</code><button class="copy-button">copy</button></pre>
7791cb0ef41Sopenharmony_ci<p>Causes the <code>readableStream.locked</code> to be <code>true</code>.</p>
7801cb0ef41Sopenharmony_ci<h5><code>readableStream.pipeThrough(transform[, options])</code><span><a class="mark" href="#readablestreampipethroughtransform-options" id="readablestreampipethroughtransform-options">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestream_pipethrough_transform_options"></a></h5>
7811cb0ef41Sopenharmony_ci<div class="api_metadata">
7821cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
7831cb0ef41Sopenharmony_ci</div>
7841cb0ef41Sopenharmony_ci<ul>
7851cb0ef41Sopenharmony_ci<li><code>transform</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
7861cb0ef41Sopenharmony_ci<ul>
7871cb0ef41Sopenharmony_ci<li><code>readable</code> <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> The <code>ReadableStream</code> to which
7881cb0ef41Sopenharmony_ci<code>transform.writable</code> will push the potentially modified data
7891cb0ef41Sopenharmony_ciis receives from this <code>ReadableStream</code>.</li>
7901cb0ef41Sopenharmony_ci<li><code>writable</code> <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a> The <code>WritableStream</code> to which this
7911cb0ef41Sopenharmony_ci<code>ReadableStream</code>'s data will be written.</li>
7921cb0ef41Sopenharmony_ci</ul>
7931cb0ef41Sopenharmony_ci</li>
7941cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
7951cb0ef41Sopenharmony_ci<ul>
7961cb0ef41Sopenharmony_ci<li><code>preventAbort</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, errors in this <code>ReadableStream</code>
7971cb0ef41Sopenharmony_ciwill not cause <code>transform.writable</code> to be aborted.</li>
7981cb0ef41Sopenharmony_ci<li><code>preventCancel</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, errors in the destination
7991cb0ef41Sopenharmony_ci<code>transform.writable</code> do not cause this <code>ReadableStream</code> to be
8001cb0ef41Sopenharmony_cicanceled.</li>
8011cb0ef41Sopenharmony_ci<li><code>preventClose</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, closing this <code>ReadableStream</code>
8021cb0ef41Sopenharmony_cidoes not cause <code>transform.writable</code> to be closed.</li>
8031cb0ef41Sopenharmony_ci<li><code>signal</code> <a href="globals.html#class-abortsignal" class="type">&#x3C;AbortSignal></a> Allows the transfer of data to be canceled
8041cb0ef41Sopenharmony_ciusing an <a href="globals.html#class-abortcontroller" class="type">&#x3C;AbortController></a>.</li>
8051cb0ef41Sopenharmony_ci</ul>
8061cb0ef41Sopenharmony_ci</li>
8071cb0ef41Sopenharmony_ci<li>Returns: <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> From <code>transform.readable</code>.</li>
8081cb0ef41Sopenharmony_ci</ul>
8091cb0ef41Sopenharmony_ci<p>Connects this <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> to the pair of <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> and
8101cb0ef41Sopenharmony_ci<a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a> provided in the <code>transform</code> argument such that the
8111cb0ef41Sopenharmony_cidata from this <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> is written in to <code>transform.writable</code>,
8121cb0ef41Sopenharmony_cipossibly transformed, then pushed to <code>transform.readable</code>. Once the
8131cb0ef41Sopenharmony_cipipeline is configured, <code>transform.readable</code> is returned.</p>
8141cb0ef41Sopenharmony_ci<p>Causes the <code>readableStream.locked</code> to be <code>true</code> while the pipe operation
8151cb0ef41Sopenharmony_ciis active.</p>
8161cb0ef41Sopenharmony_ci
8171cb0ef41Sopenharmony_ci<pre class="with-17-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> {
8181cb0ef41Sopenharmony_ci  <span class="hljs-title class_">ReadableStream</span>,
8191cb0ef41Sopenharmony_ci  <span class="hljs-title class_">TransformStream</span>,
8201cb0ef41Sopenharmony_ci} <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream/web'</span>;
8211cb0ef41Sopenharmony_ci
8221cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ReadableStream</span>({
8231cb0ef41Sopenharmony_ci  <span class="hljs-title function_">start</span>(<span class="hljs-params">controller</span>) {
8241cb0ef41Sopenharmony_ci    controller.<span class="hljs-title function_">enqueue</span>(<span class="hljs-string">'a'</span>);
8251cb0ef41Sopenharmony_ci  },
8261cb0ef41Sopenharmony_ci});
8271cb0ef41Sopenharmony_ci
8281cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> transform = <span class="hljs-keyword">new</span> <span class="hljs-title class_">TransformStream</span>({
8291cb0ef41Sopenharmony_ci  <span class="hljs-title function_">transform</span>(<span class="hljs-params">chunk, controller</span>) {
8301cb0ef41Sopenharmony_ci    controller.<span class="hljs-title function_">enqueue</span>(chunk.<span class="hljs-title function_">toUpperCase</span>());
8311cb0ef41Sopenharmony_ci  },
8321cb0ef41Sopenharmony_ci});
8331cb0ef41Sopenharmony_ci
8341cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> transformedStream = stream.<span class="hljs-title function_">pipeThrough</span>(transform);
8351cb0ef41Sopenharmony_ci
8361cb0ef41Sopenharmony_ci<span class="hljs-keyword">for</span> <span class="hljs-keyword">await</span> (<span class="hljs-keyword">const</span> chunk <span class="hljs-keyword">of</span> transformedStream)
8371cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(chunk);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> {
8381cb0ef41Sopenharmony_ci  <span class="hljs-title class_">ReadableStream</span>,
8391cb0ef41Sopenharmony_ci  <span class="hljs-title class_">TransformStream</span>,
8401cb0ef41Sopenharmony_ci} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream/web'</span>);
8411cb0ef41Sopenharmony_ci
8421cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ReadableStream</span>({
8431cb0ef41Sopenharmony_ci  <span class="hljs-title function_">start</span>(<span class="hljs-params">controller</span>) {
8441cb0ef41Sopenharmony_ci    controller.<span class="hljs-title function_">enqueue</span>(<span class="hljs-string">'a'</span>);
8451cb0ef41Sopenharmony_ci  },
8461cb0ef41Sopenharmony_ci});
8471cb0ef41Sopenharmony_ci
8481cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> transform = <span class="hljs-keyword">new</span> <span class="hljs-title class_">TransformStream</span>({
8491cb0ef41Sopenharmony_ci  <span class="hljs-title function_">transform</span>(<span class="hljs-params">chunk, controller</span>) {
8501cb0ef41Sopenharmony_ci    controller.<span class="hljs-title function_">enqueue</span>(chunk.<span class="hljs-title function_">toUpperCase</span>());
8511cb0ef41Sopenharmony_ci  },
8521cb0ef41Sopenharmony_ci});
8531cb0ef41Sopenharmony_ci
8541cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> transformedStream = stream.<span class="hljs-title function_">pipeThrough</span>(transform);
8551cb0ef41Sopenharmony_ci
8561cb0ef41Sopenharmony_ci(<span class="hljs-keyword">async</span> () => {
8571cb0ef41Sopenharmony_ci  <span class="hljs-keyword">for</span> <span class="hljs-keyword">await</span> (<span class="hljs-keyword">const</span> chunk <span class="hljs-keyword">of</span> transformedStream)
8581cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(chunk);
8591cb0ef41Sopenharmony_ci})();</code><button class="copy-button">copy</button></pre>
8601cb0ef41Sopenharmony_ci<h5><code>readableStream.pipeTo(destination[, options])</code><span><a class="mark" href="#readablestreampipetodestination-options" id="readablestreampipetodestination-options">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestream_pipeto_destination_options"></a></h5>
8611cb0ef41Sopenharmony_ci<div class="api_metadata">
8621cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
8631cb0ef41Sopenharmony_ci</div>
8641cb0ef41Sopenharmony_ci<ul>
8651cb0ef41Sopenharmony_ci<li><code>destination</code> <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a> A <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a> to which this
8661cb0ef41Sopenharmony_ci<code>ReadableStream</code>'s data will be written.</li>
8671cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
8681cb0ef41Sopenharmony_ci<ul>
8691cb0ef41Sopenharmony_ci<li><code>preventAbort</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, errors in this <code>ReadableStream</code>
8701cb0ef41Sopenharmony_ciwill not cause <code>destination</code> to be aborted.</li>
8711cb0ef41Sopenharmony_ci<li><code>preventCancel</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, errors in the <code>destination</code>
8721cb0ef41Sopenharmony_ciwill not cause this <code>ReadableStream</code> to be canceled.</li>
8731cb0ef41Sopenharmony_ci<li><code>preventClose</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, closing this <code>ReadableStream</code>
8741cb0ef41Sopenharmony_cidoes not cause <code>destination</code> to be closed.</li>
8751cb0ef41Sopenharmony_ci<li><code>signal</code> <a href="globals.html#class-abortsignal" class="type">&#x3C;AbortSignal></a> Allows the transfer of data to be canceled
8761cb0ef41Sopenharmony_ciusing an <a href="globals.html#class-abortcontroller" class="type">&#x3C;AbortController></a>.</li>
8771cb0ef41Sopenharmony_ci</ul>
8781cb0ef41Sopenharmony_ci</li>
8791cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code></li>
8801cb0ef41Sopenharmony_ci</ul>
8811cb0ef41Sopenharmony_ci<p>Causes the <code>readableStream.locked</code> to be <code>true</code> while the pipe operation
8821cb0ef41Sopenharmony_ciis active.</p>
8831cb0ef41Sopenharmony_ci<h5><code>readableStream.tee()</code><span><a class="mark" href="#readablestreamtee" id="readablestreamtee">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestream_tee"></a></h5>
8841cb0ef41Sopenharmony_ci<div class="api_metadata">
8851cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
8861cb0ef41Sopenharmony_ci<table>
8871cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
8881cb0ef41Sopenharmony_ci<tr><td>v18.10.0</td>
8891cb0ef41Sopenharmony_ci<td><p>Support teeing a readable byte stream.</p></td></tr>
8901cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
8911cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
8921cb0ef41Sopenharmony_ci</tbody></table>
8931cb0ef41Sopenharmony_ci</details>
8941cb0ef41Sopenharmony_ci</div>
8951cb0ef41Sopenharmony_ci<ul>
8961cb0ef41Sopenharmony_ci<li>Returns: <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream[]></a></li>
8971cb0ef41Sopenharmony_ci</ul>
8981cb0ef41Sopenharmony_ci<p>Returns a pair of new <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> instances to which this
8991cb0ef41Sopenharmony_ci<code>ReadableStream</code>'s data will be forwarded. Each will receive the
9001cb0ef41Sopenharmony_cisame data.</p>
9011cb0ef41Sopenharmony_ci<p>Causes the <code>readableStream.locked</code> to be <code>true</code>.</p>
9021cb0ef41Sopenharmony_ci<h5><code>readableStream.values([options])</code><span><a class="mark" href="#readablestreamvaluesoptions" id="readablestreamvaluesoptions">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestream_values_options"></a></h5>
9031cb0ef41Sopenharmony_ci<div class="api_metadata">
9041cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
9051cb0ef41Sopenharmony_ci</div>
9061cb0ef41Sopenharmony_ci<ul>
9071cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
9081cb0ef41Sopenharmony_ci<ul>
9091cb0ef41Sopenharmony_ci<li><code>preventCancel</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, prevents the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>
9101cb0ef41Sopenharmony_cifrom being closed when the async iterator abruptly terminates.
9111cb0ef41Sopenharmony_ci<strong>Default</strong>: <code>false</code>.</li>
9121cb0ef41Sopenharmony_ci</ul>
9131cb0ef41Sopenharmony_ci</li>
9141cb0ef41Sopenharmony_ci</ul>
9151cb0ef41Sopenharmony_ci<p>Creates and returns an async iterator usable for consuming this
9161cb0ef41Sopenharmony_ci<code>ReadableStream</code>'s data.</p>
9171cb0ef41Sopenharmony_ci<p>Causes the <code>readableStream.locked</code> to be <code>true</code> while the async iterator
9181cb0ef41Sopenharmony_ciis active.</p>
9191cb0ef41Sopenharmony_ci<pre><code class="language-js mjs"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">Buffer</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:buffer'</span>;
9201cb0ef41Sopenharmony_ci
9211cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ReadableStream</span>(<span class="hljs-title function_">getSomeSource</span>());
9221cb0ef41Sopenharmony_ci
9231cb0ef41Sopenharmony_ci<span class="hljs-keyword">for</span> <span class="hljs-keyword">await</span> (<span class="hljs-keyword">const</span> chunk <span class="hljs-keyword">of</span> stream.<span class="hljs-title function_">values</span>({ <span class="hljs-attr">preventCancel</span>: <span class="hljs-literal">true</span> }))
9241cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">from</span>(chunk).<span class="hljs-title function_">toString</span>());</code> <button class="copy-button">copy</button></pre>
9251cb0ef41Sopenharmony_ci<h5>Async Iteration<span><a class="mark" href="#async-iteration" id="async-iteration">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_async_iteration"></a></h5>
9261cb0ef41Sopenharmony_ci<p>The <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> object supports the async iterator protocol using
9271cb0ef41Sopenharmony_ci<code>for await</code> syntax.</p>
9281cb0ef41Sopenharmony_ci<pre><code class="language-js mjs"><span class="hljs-keyword">import</span> { <span class="hljs-title class_">Buffer</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:buffer'</span>;
9291cb0ef41Sopenharmony_ci
9301cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ReadableStream</span>(<span class="hljs-title function_">getSomeSource</span>());
9311cb0ef41Sopenharmony_ci
9321cb0ef41Sopenharmony_ci<span class="hljs-keyword">for</span> <span class="hljs-keyword">await</span> (<span class="hljs-keyword">const</span> chunk <span class="hljs-keyword">of</span> stream)
9331cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">from</span>(chunk).<span class="hljs-title function_">toString</span>());</code> <button class="copy-button">copy</button></pre>
9341cb0ef41Sopenharmony_ci<p>The async iterator will consume the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> until it terminates.</p>
9351cb0ef41Sopenharmony_ci<p>By default, if the async iterator exits early (via either a <code>break</code>,
9361cb0ef41Sopenharmony_ci<code>return</code>, or a <code>throw</code>), the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> will be closed. To prevent
9371cb0ef41Sopenharmony_ciautomatic closing of the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>, use the <code>readableStream.values()</code>
9381cb0ef41Sopenharmony_cimethod to acquire the async iterator and set the <code>preventCancel</code> option to
9391cb0ef41Sopenharmony_ci<code>true</code>.</p>
9401cb0ef41Sopenharmony_ci<p>The <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> must not be locked (that is, it must not have an existing
9411cb0ef41Sopenharmony_ciactive reader). During the async iteration, the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> will be locked.</p>
9421cb0ef41Sopenharmony_ci<h5>Transferring with <code>postMessage()</code><span><a class="mark" href="#transferring-with-postmessage" id="transferring-with-postmessage">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_transferring_with_postmessage"></a></h5>
9431cb0ef41Sopenharmony_ci<p>A <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> instance can be transferred using a <a href="worker_threads.html#class-messageport" class="type">&#x3C;MessagePort></a>.</p>
9441cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ReadableStream</span>(<span class="hljs-title function_">getReadableSourceSomehow</span>());
9451cb0ef41Sopenharmony_ci
9461cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { port1, port2 } = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MessageChannel</span>();
9471cb0ef41Sopenharmony_ci
9481cb0ef41Sopenharmony_ciport1.<span class="hljs-property">onmessage</span> = <span class="hljs-function">(<span class="hljs-params">{ data }</span>) =></span> {
9491cb0ef41Sopenharmony_ci  data.<span class="hljs-title function_">getReader</span>().<span class="hljs-title function_">read</span>().<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">chunk</span>) =></span> {
9501cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(chunk);
9511cb0ef41Sopenharmony_ci  });
9521cb0ef41Sopenharmony_ci};
9531cb0ef41Sopenharmony_ci
9541cb0ef41Sopenharmony_ciport2.<span class="hljs-title function_">postMessage</span>(stream, [stream]);</code> <button class="copy-button">copy</button></pre>
9551cb0ef41Sopenharmony_ci<h4>Class: <code>ReadableStreamDefaultReader</code><span><a class="mark" href="#class-readablestreamdefaultreader" id="class-readablestreamdefaultreader">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_readablestreamdefaultreader"></a></h4>
9561cb0ef41Sopenharmony_ci<div class="api_metadata">
9571cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
9581cb0ef41Sopenharmony_ci<table>
9591cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
9601cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
9611cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
9621cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
9631cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
9641cb0ef41Sopenharmony_ci</tbody></table>
9651cb0ef41Sopenharmony_ci</details>
9661cb0ef41Sopenharmony_ci</div>
9671cb0ef41Sopenharmony_ci<p>By default, calling <code>readableStream.getReader()</code> with no arguments
9681cb0ef41Sopenharmony_ciwill return an instance of <code>ReadableStreamDefaultReader</code>. The default
9691cb0ef41Sopenharmony_cireader treats the chunks of data passed through the stream as opaque
9701cb0ef41Sopenharmony_civalues, which allows the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> to work with generally any
9711cb0ef41Sopenharmony_ciJavaScript value.</p>
9721cb0ef41Sopenharmony_ci<h5><code>new ReadableStreamDefaultReader(stream)</code><span><a class="mark" href="#new-readablestreamdefaultreaderstream" id="new-readablestreamdefaultreaderstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_new_readablestreamdefaultreader_stream"></a></h5>
9731cb0ef41Sopenharmony_ci<div class="api_metadata">
9741cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
9751cb0ef41Sopenharmony_ci</div>
9761cb0ef41Sopenharmony_ci<ul>
9771cb0ef41Sopenharmony_ci<li><code>stream</code> <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a></li>
9781cb0ef41Sopenharmony_ci</ul>
9791cb0ef41Sopenharmony_ci<p>Creates a new <a href="webstreams.html#class-readablestreamdefaultreader" class="type">&#x3C;ReadableStreamDefaultReader></a> that is locked to the
9801cb0ef41Sopenharmony_cigiven <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>.</p>
9811cb0ef41Sopenharmony_ci<h5><code>readableStreamDefaultReader.cancel([reason])</code><span><a class="mark" href="#readablestreamdefaultreadercancelreason" id="readablestreamdefaultreadercancelreason">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreamdefaultreader_cancel_reason"></a></h5>
9821cb0ef41Sopenharmony_ci<div class="api_metadata">
9831cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
9841cb0ef41Sopenharmony_ci</div>
9851cb0ef41Sopenharmony_ci<ul>
9861cb0ef41Sopenharmony_ci<li><code>reason</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
9871cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
9881cb0ef41Sopenharmony_ci</ul>
9891cb0ef41Sopenharmony_ci<p>Cancels the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> and returns a promise that is fulfilled
9901cb0ef41Sopenharmony_ciwhen the underlying stream has been canceled.</p>
9911cb0ef41Sopenharmony_ci<h5><code>readableStreamDefaultReader.closed</code><span><a class="mark" href="#readablestreamdefaultreaderclosed" id="readablestreamdefaultreaderclosed">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreamdefaultreader_closed"></a></h5>
9921cb0ef41Sopenharmony_ci<div class="api_metadata">
9931cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
9941cb0ef41Sopenharmony_ci</div>
9951cb0ef41Sopenharmony_ci<ul>
9961cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a> Fulfilled with <code>undefined</code> when the associated
9971cb0ef41Sopenharmony_ci<a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> is closed or rejected if the stream errors or the reader's
9981cb0ef41Sopenharmony_cilock is released before the stream finishes closing.</li>
9991cb0ef41Sopenharmony_ci</ul>
10001cb0ef41Sopenharmony_ci<h5><code>readableStreamDefaultReader.read()</code><span><a class="mark" href="#readablestreamdefaultreaderread" id="readablestreamdefaultreaderread">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreamdefaultreader_read"></a></h5>
10011cb0ef41Sopenharmony_ci<div class="api_metadata">
10021cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
10031cb0ef41Sopenharmony_ci</div>
10041cb0ef41Sopenharmony_ci<ul>
10051cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with an object:
10061cb0ef41Sopenharmony_ci<ul>
10071cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a></li>
10081cb0ef41Sopenharmony_ci<li><code>done</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
10091cb0ef41Sopenharmony_ci</ul>
10101cb0ef41Sopenharmony_ci</li>
10111cb0ef41Sopenharmony_ci</ul>
10121cb0ef41Sopenharmony_ci<p>Requests the next chunk of data from the underlying <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>
10131cb0ef41Sopenharmony_ciand returns a promise that is fulfilled with the data once it is
10141cb0ef41Sopenharmony_ciavailable.</p>
10151cb0ef41Sopenharmony_ci<h5><code>readableStreamDefaultReader.releaseLock()</code><span><a class="mark" href="#readablestreamdefaultreaderreleaselock" id="readablestreamdefaultreaderreleaselock">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreamdefaultreader_releaselock"></a></h5>
10161cb0ef41Sopenharmony_ci<div class="api_metadata">
10171cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
10181cb0ef41Sopenharmony_ci</div>
10191cb0ef41Sopenharmony_ci<p>Releases this reader's lock on the underlying <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>.</p>
10201cb0ef41Sopenharmony_ci<h4>Class: <code>ReadableStreamBYOBReader</code><span><a class="mark" href="#class-readablestreambyobreader" id="class-readablestreambyobreader">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_readablestreambyobreader"></a></h4>
10211cb0ef41Sopenharmony_ci<div class="api_metadata">
10221cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
10231cb0ef41Sopenharmony_ci<table>
10241cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
10251cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
10261cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
10271cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
10281cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
10291cb0ef41Sopenharmony_ci</tbody></table>
10301cb0ef41Sopenharmony_ci</details>
10311cb0ef41Sopenharmony_ci</div>
10321cb0ef41Sopenharmony_ci<p>The <code>ReadableStreamBYOBReader</code> is an alternative consumer for
10331cb0ef41Sopenharmony_cibyte-oriented <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>s (those that are created with
10341cb0ef41Sopenharmony_ci<code>underlyingSource.type</code> set equal to <code>'bytes'</code> when the
10351cb0ef41Sopenharmony_ci<code>ReadableStream</code> was created).</p>
10361cb0ef41Sopenharmony_ci<p>The <code>BYOB</code> is short for "bring your own buffer". This is a
10371cb0ef41Sopenharmony_cipattern that allows for more efficient reading of byte-oriented
10381cb0ef41Sopenharmony_cidata that avoids extraneous copying.</p>
10391cb0ef41Sopenharmony_ci<pre><code class="language-js mjs"><span class="hljs-keyword">import</span> {
10401cb0ef41Sopenharmony_ci  open,
10411cb0ef41Sopenharmony_ci} <span class="hljs-keyword">from</span> <span class="hljs-string">'node:fs/promises'</span>;
10421cb0ef41Sopenharmony_ci
10431cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> {
10441cb0ef41Sopenharmony_ci  <span class="hljs-title class_">ReadableStream</span>,
10451cb0ef41Sopenharmony_ci} <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream/web'</span>;
10461cb0ef41Sopenharmony_ci
10471cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> { <span class="hljs-title class_">Buffer</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:buffer'</span>;
10481cb0ef41Sopenharmony_ci
10491cb0ef41Sopenharmony_ci<span class="hljs-keyword">class</span> <span class="hljs-title class_">Source</span> {
10501cb0ef41Sopenharmony_ci  type = <span class="hljs-string">'bytes'</span>;
10511cb0ef41Sopenharmony_ci  autoAllocateChunkSize = <span class="hljs-number">1024</span>;
10521cb0ef41Sopenharmony_ci
10531cb0ef41Sopenharmony_ci  <span class="hljs-keyword">async</span> <span class="hljs-title function_">start</span>(<span class="hljs-params">controller</span>) {
10541cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">this</span>.<span class="hljs-property">file</span> = <span class="hljs-keyword">await</span> <span class="hljs-title function_">open</span>(<span class="hljs-keyword">new</span> <span class="hljs-title function_">URL</span>(<span class="hljs-keyword">import</span>.<span class="hljs-property">meta</span>.<span class="hljs-property">url</span>));
10551cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">this</span>.<span class="hljs-property">controller</span> = controller;
10561cb0ef41Sopenharmony_ci  }
10571cb0ef41Sopenharmony_ci
10581cb0ef41Sopenharmony_ci  <span class="hljs-keyword">async</span> <span class="hljs-title function_">pull</span>(<span class="hljs-params">controller</span>) {
10591cb0ef41Sopenharmony_ci    <span class="hljs-keyword">const</span> view = controller.<span class="hljs-property">byobRequest</span>?.<span class="hljs-property">view</span>;
10601cb0ef41Sopenharmony_ci    <span class="hljs-keyword">const</span> {
10611cb0ef41Sopenharmony_ci      bytesRead,
10621cb0ef41Sopenharmony_ci    } = <span class="hljs-keyword">await</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">file</span>.<span class="hljs-title function_">read</span>({
10631cb0ef41Sopenharmony_ci      <span class="hljs-attr">buffer</span>: view,
10641cb0ef41Sopenharmony_ci      <span class="hljs-attr">offset</span>: view.<span class="hljs-property">byteOffset</span>,
10651cb0ef41Sopenharmony_ci      <span class="hljs-attr">length</span>: view.<span class="hljs-property">byteLength</span>,
10661cb0ef41Sopenharmony_ci    });
10671cb0ef41Sopenharmony_ci
10681cb0ef41Sopenharmony_ci    <span class="hljs-keyword">if</span> (bytesRead === <span class="hljs-number">0</span>) {
10691cb0ef41Sopenharmony_ci      <span class="hljs-keyword">await</span> <span class="hljs-variable language_">this</span>.<span class="hljs-property">file</span>.<span class="hljs-title function_">close</span>();
10701cb0ef41Sopenharmony_ci      <span class="hljs-variable language_">this</span>.<span class="hljs-property">controller</span>.<span class="hljs-title function_">close</span>();
10711cb0ef41Sopenharmony_ci    }
10721cb0ef41Sopenharmony_ci    controller.<span class="hljs-property">byobRequest</span>.<span class="hljs-title function_">respond</span>(bytesRead);
10731cb0ef41Sopenharmony_ci  }
10741cb0ef41Sopenharmony_ci}
10751cb0ef41Sopenharmony_ci
10761cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">ReadableStream</span>(<span class="hljs-keyword">new</span> <span class="hljs-title class_">Source</span>());
10771cb0ef41Sopenharmony_ci
10781cb0ef41Sopenharmony_ci<span class="hljs-keyword">async</span> <span class="hljs-keyword">function</span> <span class="hljs-title function_">read</span>(<span class="hljs-params">stream</span>) {
10791cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> reader = stream.<span class="hljs-title function_">getReader</span>({ <span class="hljs-attr">mode</span>: <span class="hljs-string">'byob'</span> });
10801cb0ef41Sopenharmony_ci
10811cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> chunks = [];
10821cb0ef41Sopenharmony_ci  <span class="hljs-keyword">let</span> result;
10831cb0ef41Sopenharmony_ci  <span class="hljs-keyword">do</span> {
10841cb0ef41Sopenharmony_ci    result = <span class="hljs-keyword">await</span> reader.<span class="hljs-title function_">read</span>(<span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">alloc</span>(<span class="hljs-number">100</span>));
10851cb0ef41Sopenharmony_ci    <span class="hljs-keyword">if</span> (result.<span class="hljs-property">value</span> !== <span class="hljs-literal">undefined</span>)
10861cb0ef41Sopenharmony_ci      chunks.<span class="hljs-title function_">push</span>(<span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">from</span>(result.<span class="hljs-property">value</span>));
10871cb0ef41Sopenharmony_ci  } <span class="hljs-keyword">while</span> (!result.<span class="hljs-property">done</span>);
10881cb0ef41Sopenharmony_ci
10891cb0ef41Sopenharmony_ci  <span class="hljs-keyword">return</span> <span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">concat</span>(chunks);
10901cb0ef41Sopenharmony_ci}
10911cb0ef41Sopenharmony_ci
10921cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> <span class="hljs-title function_">read</span>(stream);
10931cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">from</span>(data).<span class="hljs-title function_">toString</span>());</code> <button class="copy-button">copy</button></pre>
10941cb0ef41Sopenharmony_ci<h5><code>new ReadableStreamBYOBReader(stream)</code><span><a class="mark" href="#new-readablestreambyobreaderstream" id="new-readablestreambyobreaderstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_new_readablestreambyobreader_stream"></a></h5>
10951cb0ef41Sopenharmony_ci<div class="api_metadata">
10961cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
10971cb0ef41Sopenharmony_ci</div>
10981cb0ef41Sopenharmony_ci<ul>
10991cb0ef41Sopenharmony_ci<li><code>stream</code> <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a></li>
11001cb0ef41Sopenharmony_ci</ul>
11011cb0ef41Sopenharmony_ci<p>Creates a new <code>ReadableStreamBYOBReader</code> that is locked to the
11021cb0ef41Sopenharmony_cigiven <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>.</p>
11031cb0ef41Sopenharmony_ci<h5><code>readableStreamBYOBReader.cancel([reason])</code><span><a class="mark" href="#readablestreambyobreadercancelreason" id="readablestreambyobreadercancelreason">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreambyobreader_cancel_reason"></a></h5>
11041cb0ef41Sopenharmony_ci<div class="api_metadata">
11051cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
11061cb0ef41Sopenharmony_ci</div>
11071cb0ef41Sopenharmony_ci<ul>
11081cb0ef41Sopenharmony_ci<li><code>reason</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
11091cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
11101cb0ef41Sopenharmony_ci</ul>
11111cb0ef41Sopenharmony_ci<p>Cancels the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> and returns a promise that is fulfilled
11121cb0ef41Sopenharmony_ciwhen the underlying stream has been canceled.</p>
11131cb0ef41Sopenharmony_ci<h5><code>readableStreamBYOBReader.closed</code><span><a class="mark" href="#readablestreambyobreaderclosed" id="readablestreambyobreaderclosed">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreambyobreader_closed"></a></h5>
11141cb0ef41Sopenharmony_ci<div class="api_metadata">
11151cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
11161cb0ef41Sopenharmony_ci</div>
11171cb0ef41Sopenharmony_ci<ul>
11181cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a> Fulfilled with <code>undefined</code> when the associated
11191cb0ef41Sopenharmony_ci<a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> is closed or rejected if the stream errors or the reader's
11201cb0ef41Sopenharmony_cilock is released before the stream finishes closing.</li>
11211cb0ef41Sopenharmony_ci</ul>
11221cb0ef41Sopenharmony_ci<h5><code>readableStreamBYOBReader.read(view)</code><span><a class="mark" href="#readablestreambyobreaderreadview" id="readablestreambyobreaderreadview">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreambyobreader_read_view"></a></h5>
11231cb0ef41Sopenharmony_ci<div class="api_metadata">
11241cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
11251cb0ef41Sopenharmony_ci</div>
11261cb0ef41Sopenharmony_ci<ul>
11271cb0ef41Sopenharmony_ci<li><code>view</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></li>
11281cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with an object:
11291cb0ef41Sopenharmony_ci<ul>
11301cb0ef41Sopenharmony_ci<li><code>value</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a></li>
11311cb0ef41Sopenharmony_ci<li><code>done</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
11321cb0ef41Sopenharmony_ci</ul>
11331cb0ef41Sopenharmony_ci</li>
11341cb0ef41Sopenharmony_ci</ul>
11351cb0ef41Sopenharmony_ci<p>Requests the next chunk of data from the underlying <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>
11361cb0ef41Sopenharmony_ciand returns a promise that is fulfilled with the data once it is
11371cb0ef41Sopenharmony_ciavailable.</p>
11381cb0ef41Sopenharmony_ci<p>Do not pass a pooled <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> object instance in to this method.
11391cb0ef41Sopenharmony_ciPooled <code>Buffer</code> objects are created using <code>Buffer.allocUnsafe()</code>,
11401cb0ef41Sopenharmony_cior <code>Buffer.from()</code>, or are often returned by various <code>node:fs</code> module
11411cb0ef41Sopenharmony_cicallbacks. These types of <code>Buffer</code>s use a shared underlying
11421cb0ef41Sopenharmony_ci<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer" class="type">&#x3C;ArrayBuffer></a> object that contains all of the data from all of
11431cb0ef41Sopenharmony_cithe pooled <code>Buffer</code> instances. When a <code>Buffer</code>, <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray" class="type">&#x3C;TypedArray></a>,
11441cb0ef41Sopenharmony_cior <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView" class="type">&#x3C;DataView></a> is passed in to <code>readableStreamBYOBReader.read()</code>,
11451cb0ef41Sopenharmony_cithe view's underlying <code>ArrayBuffer</code> is <em>detached</em>, invalidating
11461cb0ef41Sopenharmony_ciall existing views that may exist on that <code>ArrayBuffer</code>. This
11471cb0ef41Sopenharmony_cican have disastrous consequences for your application.</p>
11481cb0ef41Sopenharmony_ci<h5><code>readableStreamBYOBReader.releaseLock()</code><span><a class="mark" href="#readablestreambyobreaderreleaselock" id="readablestreambyobreaderreleaselock">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreambyobreader_releaselock"></a></h5>
11491cb0ef41Sopenharmony_ci<div class="api_metadata">
11501cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
11511cb0ef41Sopenharmony_ci</div>
11521cb0ef41Sopenharmony_ci<p>Releases this reader's lock on the underlying <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>.</p>
11531cb0ef41Sopenharmony_ci<h4>Class: <code>ReadableStreamDefaultController</code><span><a class="mark" href="#class-readablestreamdefaultcontroller" id="class-readablestreamdefaultcontroller">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_readablestreamdefaultcontroller"></a></h4>
11541cb0ef41Sopenharmony_ci<div class="api_metadata">
11551cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
11561cb0ef41Sopenharmony_ci</div>
11571cb0ef41Sopenharmony_ci<p>Every <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> has a controller that is responsible for
11581cb0ef41Sopenharmony_cithe internal state and management of the stream's queue. The
11591cb0ef41Sopenharmony_ci<code>ReadableStreamDefaultController</code> is the default controller
11601cb0ef41Sopenharmony_ciimplementation for <code>ReadableStream</code>s that are not byte-oriented.</p>
11611cb0ef41Sopenharmony_ci<h5><code>readableStreamDefaultController.close()</code><span><a class="mark" href="#readablestreamdefaultcontrollerclose" id="readablestreamdefaultcontrollerclose">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreamdefaultcontroller_close"></a></h5>
11621cb0ef41Sopenharmony_ci<div class="api_metadata">
11631cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
11641cb0ef41Sopenharmony_ci</div>
11651cb0ef41Sopenharmony_ci<p>Closes the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> to which this controller is associated.</p>
11661cb0ef41Sopenharmony_ci<h5><code>readableStreamDefaultController.desiredSize</code><span><a class="mark" href="#readablestreamdefaultcontrollerdesiredsize" id="readablestreamdefaultcontrollerdesiredsize">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreamdefaultcontroller_desiredsize"></a></h5>
11671cb0ef41Sopenharmony_ci<div class="api_metadata">
11681cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
11691cb0ef41Sopenharmony_ci</div>
11701cb0ef41Sopenharmony_ci<ul>
11711cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
11721cb0ef41Sopenharmony_ci</ul>
11731cb0ef41Sopenharmony_ci<p>Returns the amount of data remaining to fill the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>'s
11741cb0ef41Sopenharmony_ciqueue.</p>
11751cb0ef41Sopenharmony_ci<h5><code>readableStreamDefaultController.enqueue([chunk])</code><span><a class="mark" href="#readablestreamdefaultcontrollerenqueuechunk" id="readablestreamdefaultcontrollerenqueuechunk">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreamdefaultcontroller_enqueue_chunk"></a></h5>
11761cb0ef41Sopenharmony_ci<div class="api_metadata">
11771cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
11781cb0ef41Sopenharmony_ci</div>
11791cb0ef41Sopenharmony_ci<ul>
11801cb0ef41Sopenharmony_ci<li><code>chunk</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
11811cb0ef41Sopenharmony_ci</ul>
11821cb0ef41Sopenharmony_ci<p>Appends a new chunk of data to the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>'s queue.</p>
11831cb0ef41Sopenharmony_ci<h5><code>readableStreamDefaultController.error([error])</code><span><a class="mark" href="#readablestreamdefaultcontrollererrorerror" id="readablestreamdefaultcontrollererrorerror">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreamdefaultcontroller_error_error"></a></h5>
11841cb0ef41Sopenharmony_ci<div class="api_metadata">
11851cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
11861cb0ef41Sopenharmony_ci</div>
11871cb0ef41Sopenharmony_ci<ul>
11881cb0ef41Sopenharmony_ci<li><code>error</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
11891cb0ef41Sopenharmony_ci</ul>
11901cb0ef41Sopenharmony_ci<p>Signals an error that causes the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> to error and close.</p>
11911cb0ef41Sopenharmony_ci<h4>Class: <code>ReadableByteStreamController</code><span><a class="mark" href="#class-readablebytestreamcontroller" id="class-readablebytestreamcontroller">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_readablebytestreamcontroller"></a></h4>
11921cb0ef41Sopenharmony_ci<div class="api_metadata">
11931cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
11941cb0ef41Sopenharmony_ci<table>
11951cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
11961cb0ef41Sopenharmony_ci<tr><td>v18.10.0</td>
11971cb0ef41Sopenharmony_ci<td><p>Support handling a BYOB pull request from a released reader.</p></td></tr>
11981cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
11991cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
12001cb0ef41Sopenharmony_ci</tbody></table>
12011cb0ef41Sopenharmony_ci</details>
12021cb0ef41Sopenharmony_ci</div>
12031cb0ef41Sopenharmony_ci<p>Every <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> has a controller that is responsible for
12041cb0ef41Sopenharmony_cithe internal state and management of the stream's queue. The
12051cb0ef41Sopenharmony_ci<code>ReadableByteStreamController</code> is for byte-oriented <code>ReadableStream</code>s.</p>
12061cb0ef41Sopenharmony_ci<h5><code>readableByteStreamController.byobRequest</code><span><a class="mark" href="#readablebytestreamcontrollerbyobrequest" id="readablebytestreamcontrollerbyobrequest">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablebytestreamcontroller_byobrequest"></a></h5>
12071cb0ef41Sopenharmony_ci<div class="api_metadata">
12081cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
12091cb0ef41Sopenharmony_ci</div>
12101cb0ef41Sopenharmony_ci<ul>
12111cb0ef41Sopenharmony_ci<li>Type: <a href="webstreams.html#class-readablestreambyobrequest" class="type">&#x3C;ReadableStreamBYOBRequest></a></li>
12121cb0ef41Sopenharmony_ci</ul>
12131cb0ef41Sopenharmony_ci<h5><code>readableByteStreamController.close()</code><span><a class="mark" href="#readablebytestreamcontrollerclose" id="readablebytestreamcontrollerclose">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablebytestreamcontroller_close"></a></h5>
12141cb0ef41Sopenharmony_ci<div class="api_metadata">
12151cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
12161cb0ef41Sopenharmony_ci</div>
12171cb0ef41Sopenharmony_ci<p>Closes the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> to which this controller is associated.</p>
12181cb0ef41Sopenharmony_ci<h5><code>readableByteStreamController.desiredSize</code><span><a class="mark" href="#readablebytestreamcontrollerdesiredsize" id="readablebytestreamcontrollerdesiredsize">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablebytestreamcontroller_desiredsize"></a></h5>
12191cb0ef41Sopenharmony_ci<div class="api_metadata">
12201cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
12211cb0ef41Sopenharmony_ci</div>
12221cb0ef41Sopenharmony_ci<ul>
12231cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
12241cb0ef41Sopenharmony_ci</ul>
12251cb0ef41Sopenharmony_ci<p>Returns the amount of data remaining to fill the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>'s
12261cb0ef41Sopenharmony_ciqueue.</p>
12271cb0ef41Sopenharmony_ci<h5><code>readableByteStreamController.enqueue(chunk)</code><span><a class="mark" href="#readablebytestreamcontrollerenqueuechunk" id="readablebytestreamcontrollerenqueuechunk">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablebytestreamcontroller_enqueue_chunk"></a></h5>
12281cb0ef41Sopenharmony_ci<div class="api_metadata">
12291cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
12301cb0ef41Sopenharmony_ci</div>
12311cb0ef41Sopenharmony_ci<ul>
12321cb0ef41Sopenharmony_ci<li><code>chunk</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></li>
12331cb0ef41Sopenharmony_ci</ul>
12341cb0ef41Sopenharmony_ci<p>Appends a new chunk of data to the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>'s queue.</p>
12351cb0ef41Sopenharmony_ci<h5><code>readableByteStreamController.error([error])</code><span><a class="mark" href="#readablebytestreamcontrollererrorerror" id="readablebytestreamcontrollererrorerror">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablebytestreamcontroller_error_error"></a></h5>
12361cb0ef41Sopenharmony_ci<div class="api_metadata">
12371cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
12381cb0ef41Sopenharmony_ci</div>
12391cb0ef41Sopenharmony_ci<ul>
12401cb0ef41Sopenharmony_ci<li><code>error</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
12411cb0ef41Sopenharmony_ci</ul>
12421cb0ef41Sopenharmony_ci<p>Signals an error that causes the <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> to error and close.</p>
12431cb0ef41Sopenharmony_ci<h4>Class: <code>ReadableStreamBYOBRequest</code><span><a class="mark" href="#class-readablestreambyobrequest" id="class-readablestreambyobrequest">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_readablestreambyobrequest"></a></h4>
12441cb0ef41Sopenharmony_ci<div class="api_metadata">
12451cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
12461cb0ef41Sopenharmony_ci<table>
12471cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
12481cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
12491cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
12501cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
12511cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
12521cb0ef41Sopenharmony_ci</tbody></table>
12531cb0ef41Sopenharmony_ci</details>
12541cb0ef41Sopenharmony_ci</div>
12551cb0ef41Sopenharmony_ci<p>When using <code>ReadableByteStreamController</code> in byte-oriented
12561cb0ef41Sopenharmony_cistreams, and when using the <code>ReadableStreamBYOBReader</code>,
12571cb0ef41Sopenharmony_cithe <code>readableByteStreamController.byobRequest</code> property
12581cb0ef41Sopenharmony_ciprovides access to a <code>ReadableStreamBYOBRequest</code> instance
12591cb0ef41Sopenharmony_cithat represents the current read request. The object
12601cb0ef41Sopenharmony_ciis used to gain access to the <code>ArrayBuffer</code>/<code>TypedArray</code>
12611cb0ef41Sopenharmony_cithat has been provided for the read request to fill,
12621cb0ef41Sopenharmony_ciand provides methods for signaling that the data has
12631cb0ef41Sopenharmony_cibeen provided.</p>
12641cb0ef41Sopenharmony_ci<h5><code>readableStreamBYOBRequest.respond(bytesWritten)</code><span><a class="mark" href="#readablestreambyobrequestrespondbyteswritten" id="readablestreambyobrequestrespondbyteswritten">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreambyobrequest_respond_byteswritten"></a></h5>
12651cb0ef41Sopenharmony_ci<div class="api_metadata">
12661cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
12671cb0ef41Sopenharmony_ci</div>
12681cb0ef41Sopenharmony_ci<ul>
12691cb0ef41Sopenharmony_ci<li><code>bytesWritten</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
12701cb0ef41Sopenharmony_ci</ul>
12711cb0ef41Sopenharmony_ci<p>Signals that a <code>bytesWritten</code> number of bytes have been written
12721cb0ef41Sopenharmony_cito <code>readableStreamBYOBRequest.view</code>.</p>
12731cb0ef41Sopenharmony_ci<h5><code>readableStreamBYOBRequest.respondWithNewView(view)</code><span><a class="mark" href="#readablestreambyobrequestrespondwithnewviewview" id="readablestreambyobrequestrespondwithnewviewview">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreambyobrequest_respondwithnewview_view"></a></h5>
12741cb0ef41Sopenharmony_ci<div class="api_metadata">
12751cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
12761cb0ef41Sopenharmony_ci</div>
12771cb0ef41Sopenharmony_ci<ul>
12781cb0ef41Sopenharmony_ci<li><code>view</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></li>
12791cb0ef41Sopenharmony_ci</ul>
12801cb0ef41Sopenharmony_ci<p>Signals that the request has been fulfilled with bytes written
12811cb0ef41Sopenharmony_cito a new <code>Buffer</code>, <code>TypedArray</code>, or <code>DataView</code>.</p>
12821cb0ef41Sopenharmony_ci<h5><code>readableStreamBYOBRequest.view</code><span><a class="mark" href="#readablestreambyobrequestview" id="readablestreambyobrequestview">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_readablestreambyobrequest_view"></a></h5>
12831cb0ef41Sopenharmony_ci<div class="api_metadata">
12841cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
12851cb0ef41Sopenharmony_ci</div>
12861cb0ef41Sopenharmony_ci<ul>
12871cb0ef41Sopenharmony_ci<li>Type: <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></li>
12881cb0ef41Sopenharmony_ci</ul>
12891cb0ef41Sopenharmony_ci<h4>Class: <code>WritableStream</code><span><a class="mark" href="#class-writablestream" id="class-writablestream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_writablestream"></a></h4>
12901cb0ef41Sopenharmony_ci<div class="api_metadata">
12911cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
12921cb0ef41Sopenharmony_ci<table>
12931cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
12941cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
12951cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
12961cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
12971cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
12981cb0ef41Sopenharmony_ci</tbody></table>
12991cb0ef41Sopenharmony_ci</details>
13001cb0ef41Sopenharmony_ci</div>
13011cb0ef41Sopenharmony_ci<p>The <code>WritableStream</code> is a destination to which stream data is sent.</p>
13021cb0ef41Sopenharmony_ci<pre><code class="language-js mjs"><span class="hljs-keyword">import</span> {
13031cb0ef41Sopenharmony_ci  <span class="hljs-title class_">WritableStream</span>,
13041cb0ef41Sopenharmony_ci} <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream/web'</span>;
13051cb0ef41Sopenharmony_ci
13061cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">WritableStream</span>({
13071cb0ef41Sopenharmony_ci  <span class="hljs-title function_">write</span>(<span class="hljs-params">chunk</span>) {
13081cb0ef41Sopenharmony_ci    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(chunk);
13091cb0ef41Sopenharmony_ci  },
13101cb0ef41Sopenharmony_ci});
13111cb0ef41Sopenharmony_ci
13121cb0ef41Sopenharmony_ci<span class="hljs-keyword">await</span> stream.<span class="hljs-title function_">getWriter</span>().<span class="hljs-title function_">write</span>(<span class="hljs-string">'Hello World'</span>);</code> <button class="copy-button">copy</button></pre>
13131cb0ef41Sopenharmony_ci<h5><code>new WritableStream([underlyingSink[, strategy]])</code><span><a class="mark" href="#new-writablestreamunderlyingsink-strategy" id="new-writablestreamunderlyingsink-strategy">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_new_writablestream_underlyingsink_strategy"></a></h5>
13141cb0ef41Sopenharmony_ci<div class="api_metadata">
13151cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
13161cb0ef41Sopenharmony_ci</div>
13171cb0ef41Sopenharmony_ci<ul>
13181cb0ef41Sopenharmony_ci<li><code>underlyingSink</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
13191cb0ef41Sopenharmony_ci<ul>
13201cb0ef41Sopenharmony_ci<li><code>start</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function that is invoked immediately when
13211cb0ef41Sopenharmony_cithe <code>WritableStream</code> is created.
13221cb0ef41Sopenharmony_ci<ul>
13231cb0ef41Sopenharmony_ci<li><code>controller</code> <a href="webstreams.html#class-writablestreamdefaultcontroller" class="type">&#x3C;WritableStreamDefaultController></a></li>
13241cb0ef41Sopenharmony_ci<li>Returns: <code>undefined</code> or a promise fulfilled with <code>undefined</code>.</li>
13251cb0ef41Sopenharmony_ci</ul>
13261cb0ef41Sopenharmony_ci</li>
13271cb0ef41Sopenharmony_ci<li><code>write</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function that is invoked when a chunk of
13281cb0ef41Sopenharmony_cidata has been written to the <code>WritableStream</code>.
13291cb0ef41Sopenharmony_ci<ul>
13301cb0ef41Sopenharmony_ci<li><code>chunk</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
13311cb0ef41Sopenharmony_ci<li><code>controller</code> <a href="webstreams.html#class-writablestreamdefaultcontroller" class="type">&#x3C;WritableStreamDefaultController></a></li>
13321cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
13331cb0ef41Sopenharmony_ci</ul>
13341cb0ef41Sopenharmony_ci</li>
13351cb0ef41Sopenharmony_ci<li><code>close</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function that is called when the
13361cb0ef41Sopenharmony_ci<code>WritableStream</code> is closed.
13371cb0ef41Sopenharmony_ci<ul>
13381cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
13391cb0ef41Sopenharmony_ci</ul>
13401cb0ef41Sopenharmony_ci</li>
13411cb0ef41Sopenharmony_ci<li><code>abort</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function that is called to abruptly close
13421cb0ef41Sopenharmony_cithe <code>WritableStream</code>.
13431cb0ef41Sopenharmony_ci<ul>
13441cb0ef41Sopenharmony_ci<li><code>reason</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
13451cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
13461cb0ef41Sopenharmony_ci</ul>
13471cb0ef41Sopenharmony_ci</li>
13481cb0ef41Sopenharmony_ci<li><code>type</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> The <code>type</code> option is reserved for future use and <em>must</em> be
13491cb0ef41Sopenharmony_ciundefined.</li>
13501cb0ef41Sopenharmony_ci</ul>
13511cb0ef41Sopenharmony_ci</li>
13521cb0ef41Sopenharmony_ci<li><code>strategy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
13531cb0ef41Sopenharmony_ci<ul>
13541cb0ef41Sopenharmony_ci<li><code>highWaterMark</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The maximum internal queue size before backpressure
13551cb0ef41Sopenharmony_ciis applied.</li>
13561cb0ef41Sopenharmony_ci<li><code>size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function used to identify the size of each
13571cb0ef41Sopenharmony_cichunk of data.
13581cb0ef41Sopenharmony_ci<ul>
13591cb0ef41Sopenharmony_ci<li><code>chunk</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
13601cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
13611cb0ef41Sopenharmony_ci</ul>
13621cb0ef41Sopenharmony_ci</li>
13631cb0ef41Sopenharmony_ci</ul>
13641cb0ef41Sopenharmony_ci</li>
13651cb0ef41Sopenharmony_ci</ul>
13661cb0ef41Sopenharmony_ci<h5><code>writableStream.abort([reason])</code><span><a class="mark" href="#writablestreamabortreason" id="writablestreamabortreason">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_writablestream_abort_reason"></a></h5>
13671cb0ef41Sopenharmony_ci<div class="api_metadata">
13681cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
13691cb0ef41Sopenharmony_ci</div>
13701cb0ef41Sopenharmony_ci<ul>
13711cb0ef41Sopenharmony_ci<li><code>reason</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
13721cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
13731cb0ef41Sopenharmony_ci</ul>
13741cb0ef41Sopenharmony_ci<p>Abruptly terminates the <code>WritableStream</code>. All queued writes will be
13751cb0ef41Sopenharmony_cicanceled with their associated promises rejected.</p>
13761cb0ef41Sopenharmony_ci<h5><code>writableStream.close()</code><span><a class="mark" href="#writablestreamclose" id="writablestreamclose">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_writablestream_close"></a></h5>
13771cb0ef41Sopenharmony_ci<div class="api_metadata">
13781cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
13791cb0ef41Sopenharmony_ci</div>
13801cb0ef41Sopenharmony_ci<ul>
13811cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
13821cb0ef41Sopenharmony_ci</ul>
13831cb0ef41Sopenharmony_ci<p>Closes the <code>WritableStream</code> when no additional writes are expected.</p>
13841cb0ef41Sopenharmony_ci<h5><code>writableStream.getWriter()</code><span><a class="mark" href="#writablestreamgetwriter" id="writablestreamgetwriter">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_writablestream_getwriter"></a></h5>
13851cb0ef41Sopenharmony_ci<div class="api_metadata">
13861cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
13871cb0ef41Sopenharmony_ci</div>
13881cb0ef41Sopenharmony_ci<ul>
13891cb0ef41Sopenharmony_ci<li>Returns: <a href="webstreams.html#class-writablestreamdefaultwriter" class="type">&#x3C;WritableStreamDefaultWriter></a></li>
13901cb0ef41Sopenharmony_ci</ul>
13911cb0ef41Sopenharmony_ci<p>Creates and returns a new writer instance that can be used to write
13921cb0ef41Sopenharmony_cidata into the <code>WritableStream</code>.</p>
13931cb0ef41Sopenharmony_ci<h5><code>writableStream.locked</code><span><a class="mark" href="#writablestreamlocked" id="writablestreamlocked">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_writablestream_locked"></a></h5>
13941cb0ef41Sopenharmony_ci<div class="api_metadata">
13951cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
13961cb0ef41Sopenharmony_ci</div>
13971cb0ef41Sopenharmony_ci<ul>
13981cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
13991cb0ef41Sopenharmony_ci</ul>
14001cb0ef41Sopenharmony_ci<p>The <code>writableStream.locked</code> property is <code>false</code> by default, and is
14011cb0ef41Sopenharmony_ciswitched to <code>true</code> while there is an active writer attached to this
14021cb0ef41Sopenharmony_ci<code>WritableStream</code>.</p>
14031cb0ef41Sopenharmony_ci<h5>Transferring with postMessage()<span><a class="mark" href="#transferring-with-postmessage_1" id="transferring-with-postmessage_1">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_transferring_with_postmessage_1"></a></h5>
14041cb0ef41Sopenharmony_ci<p>A <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a> instance can be transferred using a <a href="worker_threads.html#class-messageport" class="type">&#x3C;MessagePort></a>.</p>
14051cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">WritableStream</span>(<span class="hljs-title function_">getWritableSinkSomehow</span>());
14061cb0ef41Sopenharmony_ci
14071cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { port1, port2 } = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MessageChannel</span>();
14081cb0ef41Sopenharmony_ci
14091cb0ef41Sopenharmony_ciport1.<span class="hljs-property">onmessage</span> = <span class="hljs-function">(<span class="hljs-params">{ data }</span>) =></span> {
14101cb0ef41Sopenharmony_ci  data.<span class="hljs-title function_">getWriter</span>().<span class="hljs-title function_">write</span>(<span class="hljs-string">'hello'</span>);
14111cb0ef41Sopenharmony_ci};
14121cb0ef41Sopenharmony_ci
14131cb0ef41Sopenharmony_ciport2.<span class="hljs-title function_">postMessage</span>(stream, [stream]);</code> <button class="copy-button">copy</button></pre>
14141cb0ef41Sopenharmony_ci<h4>Class: <code>WritableStreamDefaultWriter</code><span><a class="mark" href="#class-writablestreamdefaultwriter" id="class-writablestreamdefaultwriter">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_writablestreamdefaultwriter"></a></h4>
14151cb0ef41Sopenharmony_ci<div class="api_metadata">
14161cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
14171cb0ef41Sopenharmony_ci<table>
14181cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
14191cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
14201cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
14211cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
14221cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
14231cb0ef41Sopenharmony_ci</tbody></table>
14241cb0ef41Sopenharmony_ci</details>
14251cb0ef41Sopenharmony_ci</div>
14261cb0ef41Sopenharmony_ci<h5><code>new WritableStreamDefaultWriter(stream)</code><span><a class="mark" href="#new-writablestreamdefaultwriterstream" id="new-writablestreamdefaultwriterstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_new_writablestreamdefaultwriter_stream"></a></h5>
14271cb0ef41Sopenharmony_ci<div class="api_metadata">
14281cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
14291cb0ef41Sopenharmony_ci</div>
14301cb0ef41Sopenharmony_ci<ul>
14311cb0ef41Sopenharmony_ci<li><code>stream</code> <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a></li>
14321cb0ef41Sopenharmony_ci</ul>
14331cb0ef41Sopenharmony_ci<p>Creates a new <code>WritableStreamDefaultWriter</code> that is locked to the given
14341cb0ef41Sopenharmony_ci<code>WritableStream</code>.</p>
14351cb0ef41Sopenharmony_ci<h5><code>writableStreamDefaultWriter.abort([reason])</code><span><a class="mark" href="#writablestreamdefaultwriterabortreason" id="writablestreamdefaultwriterabortreason">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_writablestreamdefaultwriter_abort_reason"></a></h5>
14361cb0ef41Sopenharmony_ci<div class="api_metadata">
14371cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
14381cb0ef41Sopenharmony_ci</div>
14391cb0ef41Sopenharmony_ci<ul>
14401cb0ef41Sopenharmony_ci<li><code>reason</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
14411cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
14421cb0ef41Sopenharmony_ci</ul>
14431cb0ef41Sopenharmony_ci<p>Abruptly terminates the <code>WritableStream</code>. All queued writes will be
14441cb0ef41Sopenharmony_cicanceled with their associated promises rejected.</p>
14451cb0ef41Sopenharmony_ci<h5><code>writableStreamDefaultWriter.close()</code><span><a class="mark" href="#writablestreamdefaultwriterclose" id="writablestreamdefaultwriterclose">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_writablestreamdefaultwriter_close"></a></h5>
14461cb0ef41Sopenharmony_ci<div class="api_metadata">
14471cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
14481cb0ef41Sopenharmony_ci</div>
14491cb0ef41Sopenharmony_ci<ul>
14501cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
14511cb0ef41Sopenharmony_ci</ul>
14521cb0ef41Sopenharmony_ci<p>Closes the <code>WritableStream</code> when no additional writes are expected.</p>
14531cb0ef41Sopenharmony_ci<h5><code>writableStreamDefaultWriter.closed</code><span><a class="mark" href="#writablestreamdefaultwriterclosed" id="writablestreamdefaultwriterclosed">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_writablestreamdefaultwriter_closed"></a></h5>
14541cb0ef41Sopenharmony_ci<div class="api_metadata">
14551cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
14561cb0ef41Sopenharmony_ci</div>
14571cb0ef41Sopenharmony_ci<ul>
14581cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a> Fulfilled with <code>undefined</code> when the associated
14591cb0ef41Sopenharmony_ci<a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a> is closed or rejected if the stream errors or the writer's
14601cb0ef41Sopenharmony_cilock is released before the stream finishes closing.</li>
14611cb0ef41Sopenharmony_ci</ul>
14621cb0ef41Sopenharmony_ci<h5><code>writableStreamDefaultWriter.desiredSize</code><span><a class="mark" href="#writablestreamdefaultwriterdesiredsize" id="writablestreamdefaultwriterdesiredsize">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_writablestreamdefaultwriter_desiredsize"></a></h5>
14631cb0ef41Sopenharmony_ci<div class="api_metadata">
14641cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
14651cb0ef41Sopenharmony_ci</div>
14661cb0ef41Sopenharmony_ci<ul>
14671cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
14681cb0ef41Sopenharmony_ci</ul>
14691cb0ef41Sopenharmony_ci<p>The amount of data required to fill the <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a>'s queue.</p>
14701cb0ef41Sopenharmony_ci<h5><code>writableStreamDefaultWriter.ready</code><span><a class="mark" href="#writablestreamdefaultwriterready" id="writablestreamdefaultwriterready">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_writablestreamdefaultwriter_ready"></a></h5>
14711cb0ef41Sopenharmony_ci<div class="api_metadata">
14721cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
14731cb0ef41Sopenharmony_ci</div>
14741cb0ef41Sopenharmony_ci<ul>
14751cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a> Fulfilled with <code>undefined</code> when the writer is ready
14761cb0ef41Sopenharmony_cito be used.</li>
14771cb0ef41Sopenharmony_ci</ul>
14781cb0ef41Sopenharmony_ci<h5><code>writableStreamDefaultWriter.releaseLock()</code><span><a class="mark" href="#writablestreamdefaultwriterreleaselock" id="writablestreamdefaultwriterreleaselock">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_writablestreamdefaultwriter_releaselock"></a></h5>
14791cb0ef41Sopenharmony_ci<div class="api_metadata">
14801cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
14811cb0ef41Sopenharmony_ci</div>
14821cb0ef41Sopenharmony_ci<p>Releases this writer's lock on the underlying <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a>.</p>
14831cb0ef41Sopenharmony_ci<h5><code>writableStreamDefaultWriter.write([chunk])</code><span><a class="mark" href="#writablestreamdefaultwriterwritechunk" id="writablestreamdefaultwriterwritechunk">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_writablestreamdefaultwriter_write_chunk"></a></h5>
14841cb0ef41Sopenharmony_ci<div class="api_metadata">
14851cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
14861cb0ef41Sopenharmony_ci</div>
14871cb0ef41Sopenharmony_ci<ul>
14881cb0ef41Sopenharmony_ci<li><code>chunk</code>: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
14891cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
14901cb0ef41Sopenharmony_ci</ul>
14911cb0ef41Sopenharmony_ci<p>Appends a new chunk of data to the <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a>'s queue.</p>
14921cb0ef41Sopenharmony_ci<h4>Class: <code>WritableStreamDefaultController</code><span><a class="mark" href="#class-writablestreamdefaultcontroller" id="class-writablestreamdefaultcontroller">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_writablestreamdefaultcontroller"></a></h4>
14931cb0ef41Sopenharmony_ci<div class="api_metadata">
14941cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
14951cb0ef41Sopenharmony_ci<table>
14961cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
14971cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
14981cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
14991cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
15001cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
15011cb0ef41Sopenharmony_ci</tbody></table>
15021cb0ef41Sopenharmony_ci</details>
15031cb0ef41Sopenharmony_ci</div>
15041cb0ef41Sopenharmony_ci<p>The <code>WritableStreamDefaultController</code> manage's the <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a>'s
15051cb0ef41Sopenharmony_ciinternal state.</p>
15061cb0ef41Sopenharmony_ci<h5><code>writableStreamDefaultController.error([error])</code><span><a class="mark" href="#writablestreamdefaultcontrollererrorerror" id="writablestreamdefaultcontrollererrorerror">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_writablestreamdefaultcontroller_error_error"></a></h5>
15071cb0ef41Sopenharmony_ci<div class="api_metadata">
15081cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
15091cb0ef41Sopenharmony_ci</div>
15101cb0ef41Sopenharmony_ci<ul>
15111cb0ef41Sopenharmony_ci<li><code>error</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
15121cb0ef41Sopenharmony_ci</ul>
15131cb0ef41Sopenharmony_ci<p>Called by user-code to signal that an error has occurred while processing
15141cb0ef41Sopenharmony_cithe <code>WritableStream</code> data. When called, the <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a> will be aborted,
15151cb0ef41Sopenharmony_ciwith currently pending writes canceled.</p>
15161cb0ef41Sopenharmony_ci<h5><code>writableStreamDefaultController.signal</code><span><a class="mark" href="#writablestreamdefaultcontrollersignal" id="writablestreamdefaultcontrollersignal">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_writablestreamdefaultcontroller_signal"></a></h5>
15171cb0ef41Sopenharmony_ci<ul>
15181cb0ef41Sopenharmony_ci<li>Type: <a href="globals.html#class-abortsignal" class="type">&#x3C;AbortSignal></a> An <code>AbortSignal</code> that can be used to cancel pending
15191cb0ef41Sopenharmony_ciwrite or close operations when a <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a> is aborted.</li>
15201cb0ef41Sopenharmony_ci</ul>
15211cb0ef41Sopenharmony_ci<h4>Class: <code>TransformStream</code><span><a class="mark" href="#class-transformstream" id="class-transformstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_transformstream"></a></h4>
15221cb0ef41Sopenharmony_ci<div class="api_metadata">
15231cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
15241cb0ef41Sopenharmony_ci<table>
15251cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
15261cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
15271cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
15281cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
15291cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
15301cb0ef41Sopenharmony_ci</tbody></table>
15311cb0ef41Sopenharmony_ci</details>
15321cb0ef41Sopenharmony_ci</div>
15331cb0ef41Sopenharmony_ci<p>A <code>TransformStream</code> consists of a <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> and a <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a> that
15341cb0ef41Sopenharmony_ciare connected such that the data written to the <code>WritableStream</code> is received,
15351cb0ef41Sopenharmony_ciand potentially transformed, before being pushed into the <code>ReadableStream</code>'s
15361cb0ef41Sopenharmony_ciqueue.</p>
15371cb0ef41Sopenharmony_ci<pre><code class="language-js mjs"><span class="hljs-keyword">import</span> {
15381cb0ef41Sopenharmony_ci  <span class="hljs-title class_">TransformStream</span>,
15391cb0ef41Sopenharmony_ci} <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream/web'</span>;
15401cb0ef41Sopenharmony_ci
15411cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> transform = <span class="hljs-keyword">new</span> <span class="hljs-title class_">TransformStream</span>({
15421cb0ef41Sopenharmony_ci  <span class="hljs-title function_">transform</span>(<span class="hljs-params">chunk, controller</span>) {
15431cb0ef41Sopenharmony_ci    controller.<span class="hljs-title function_">enqueue</span>(chunk.<span class="hljs-title function_">toUpperCase</span>());
15441cb0ef41Sopenharmony_ci  },
15451cb0ef41Sopenharmony_ci});
15461cb0ef41Sopenharmony_ci
15471cb0ef41Sopenharmony_ci<span class="hljs-keyword">await</span> <span class="hljs-title class_">Promise</span>.<span class="hljs-title function_">all</span>([
15481cb0ef41Sopenharmony_ci  transform.<span class="hljs-property">writable</span>.<span class="hljs-title function_">getWriter</span>().<span class="hljs-title function_">write</span>(<span class="hljs-string">'A'</span>),
15491cb0ef41Sopenharmony_ci  transform.<span class="hljs-property">readable</span>.<span class="hljs-title function_">getReader</span>().<span class="hljs-title function_">read</span>(),
15501cb0ef41Sopenharmony_ci]);</code> <button class="copy-button">copy</button></pre>
15511cb0ef41Sopenharmony_ci<h5><code>new TransformStream([transformer[, writableStrategy[, readableStrategy]]])</code><span><a class="mark" href="#new-transformstreamtransformer-writablestrategy-readablestrategy" id="new-transformstreamtransformer-writablestrategy-readablestrategy">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_new_transformstream_transformer_writablestrategy_readablestrategy"></a></h5>
15521cb0ef41Sopenharmony_ci<div class="api_metadata">
15531cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
15541cb0ef41Sopenharmony_ci</div>
15551cb0ef41Sopenharmony_ci<ul>
15561cb0ef41Sopenharmony_ci<li><code>transformer</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
15571cb0ef41Sopenharmony_ci<ul>
15581cb0ef41Sopenharmony_ci<li><code>start</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function that is invoked immediately when
15591cb0ef41Sopenharmony_cithe <code>TransformStream</code> is created.
15601cb0ef41Sopenharmony_ci<ul>
15611cb0ef41Sopenharmony_ci<li><code>controller</code> <a href="webstreams.html#class-transformstreamdefaultcontroller" class="type">&#x3C;TransformStreamDefaultController></a></li>
15621cb0ef41Sopenharmony_ci<li>Returns: <code>undefined</code> or a promise fulfilled with <code>undefined</code></li>
15631cb0ef41Sopenharmony_ci</ul>
15641cb0ef41Sopenharmony_ci</li>
15651cb0ef41Sopenharmony_ci<li><code>transform</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function that receives, and
15661cb0ef41Sopenharmony_cipotentially modifies, a chunk of data written to <code>transformStream.writable</code>,
15671cb0ef41Sopenharmony_cibefore forwarding that on to <code>transformStream.readable</code>.
15681cb0ef41Sopenharmony_ci<ul>
15691cb0ef41Sopenharmony_ci<li><code>chunk</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
15701cb0ef41Sopenharmony_ci<li><code>controller</code> <a href="webstreams.html#class-transformstreamdefaultcontroller" class="type">&#x3C;TransformStreamDefaultController></a></li>
15711cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
15721cb0ef41Sopenharmony_ci</ul>
15731cb0ef41Sopenharmony_ci</li>
15741cb0ef41Sopenharmony_ci<li><code>flush</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function that is called immediately before
15751cb0ef41Sopenharmony_cithe writable side of the <code>TransformStream</code> is closed, signaling the end of
15761cb0ef41Sopenharmony_cithe transformation process.
15771cb0ef41Sopenharmony_ci<ul>
15781cb0ef41Sopenharmony_ci<li><code>controller</code> <a href="webstreams.html#class-transformstreamdefaultcontroller" class="type">&#x3C;TransformStreamDefaultController></a></li>
15791cb0ef41Sopenharmony_ci<li>Returns: A promise fulfilled with <code>undefined</code>.</li>
15801cb0ef41Sopenharmony_ci</ul>
15811cb0ef41Sopenharmony_ci</li>
15821cb0ef41Sopenharmony_ci<li><code>readableType</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> the <code>readableType</code> option is reserved for future use
15831cb0ef41Sopenharmony_ciand <em>must</em> be <code>undefined</code>.</li>
15841cb0ef41Sopenharmony_ci<li><code>writableType</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a> the <code>writableType</code> option is reserved for future use
15851cb0ef41Sopenharmony_ciand <em>must</em> be <code>undefined</code>.</li>
15861cb0ef41Sopenharmony_ci</ul>
15871cb0ef41Sopenharmony_ci</li>
15881cb0ef41Sopenharmony_ci<li><code>writableStrategy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
15891cb0ef41Sopenharmony_ci<ul>
15901cb0ef41Sopenharmony_ci<li><code>highWaterMark</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The maximum internal queue size before backpressure
15911cb0ef41Sopenharmony_ciis applied.</li>
15921cb0ef41Sopenharmony_ci<li><code>size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function used to identify the size of each
15931cb0ef41Sopenharmony_cichunk of data.
15941cb0ef41Sopenharmony_ci<ul>
15951cb0ef41Sopenharmony_ci<li><code>chunk</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
15961cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
15971cb0ef41Sopenharmony_ci</ul>
15981cb0ef41Sopenharmony_ci</li>
15991cb0ef41Sopenharmony_ci</ul>
16001cb0ef41Sopenharmony_ci</li>
16011cb0ef41Sopenharmony_ci<li><code>readableStrategy</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
16021cb0ef41Sopenharmony_ci<ul>
16031cb0ef41Sopenharmony_ci<li><code>highWaterMark</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a> The maximum internal queue size before backpressure
16041cb0ef41Sopenharmony_ciis applied.</li>
16051cb0ef41Sopenharmony_ci<li><code>size</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a> A user-defined function used to identify the size of each
16061cb0ef41Sopenharmony_cichunk of data.
16071cb0ef41Sopenharmony_ci<ul>
16081cb0ef41Sopenharmony_ci<li><code>chunk</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
16091cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
16101cb0ef41Sopenharmony_ci</ul>
16111cb0ef41Sopenharmony_ci</li>
16121cb0ef41Sopenharmony_ci</ul>
16131cb0ef41Sopenharmony_ci</li>
16141cb0ef41Sopenharmony_ci</ul>
16151cb0ef41Sopenharmony_ci<h5><code>transformStream.readable</code><span><a class="mark" href="#transformstreamreadable" id="transformstreamreadable">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_transformstream_readable"></a></h5>
16161cb0ef41Sopenharmony_ci<div class="api_metadata">
16171cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
16181cb0ef41Sopenharmony_ci</div>
16191cb0ef41Sopenharmony_ci<ul>
16201cb0ef41Sopenharmony_ci<li>Type: <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a></li>
16211cb0ef41Sopenharmony_ci</ul>
16221cb0ef41Sopenharmony_ci<h5><code>transformStream.writable</code><span><a class="mark" href="#transformstreamwritable" id="transformstreamwritable">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_transformstream_writable"></a></h5>
16231cb0ef41Sopenharmony_ci<div class="api_metadata">
16241cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
16251cb0ef41Sopenharmony_ci</div>
16261cb0ef41Sopenharmony_ci<ul>
16271cb0ef41Sopenharmony_ci<li>Type: <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a></li>
16281cb0ef41Sopenharmony_ci</ul>
16291cb0ef41Sopenharmony_ci<h5>Transferring with postMessage()<span><a class="mark" href="#transferring-with-postmessage_2" id="transferring-with-postmessage_2">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_transferring_with_postmessage_2"></a></h5>
16301cb0ef41Sopenharmony_ci<p>A <a href="webstreams.html#class-transformstream" class="type">&#x3C;TransformStream></a> instance can be transferred using a <a href="worker_threads.html#class-messageport" class="type">&#x3C;MessagePort></a>.</p>
16311cb0ef41Sopenharmony_ci<pre><code class="language-js"><span class="hljs-keyword">const</span> stream = <span class="hljs-keyword">new</span> <span class="hljs-title class_">TransformStream</span>();
16321cb0ef41Sopenharmony_ci
16331cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { port1, port2 } = <span class="hljs-keyword">new</span> <span class="hljs-title class_">MessageChannel</span>();
16341cb0ef41Sopenharmony_ci
16351cb0ef41Sopenharmony_ciport1.<span class="hljs-property">onmessage</span> = <span class="hljs-function">(<span class="hljs-params">{ data }</span>) =></span> {
16361cb0ef41Sopenharmony_ci  <span class="hljs-keyword">const</span> { writable, readable } = data;
16371cb0ef41Sopenharmony_ci  <span class="hljs-comment">// ...</span>
16381cb0ef41Sopenharmony_ci};
16391cb0ef41Sopenharmony_ci
16401cb0ef41Sopenharmony_ciport2.<span class="hljs-title function_">postMessage</span>(stream, [stream]);</code> <button class="copy-button">copy</button></pre>
16411cb0ef41Sopenharmony_ci<h4>Class: <code>TransformStreamDefaultController</code><span><a class="mark" href="#class-transformstreamdefaultcontroller" id="class-transformstreamdefaultcontroller">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_transformstreamdefaultcontroller"></a></h4>
16421cb0ef41Sopenharmony_ci<div class="api_metadata">
16431cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
16441cb0ef41Sopenharmony_ci<table>
16451cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
16461cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
16471cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
16481cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
16491cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
16501cb0ef41Sopenharmony_ci</tbody></table>
16511cb0ef41Sopenharmony_ci</details>
16521cb0ef41Sopenharmony_ci</div>
16531cb0ef41Sopenharmony_ci<p>The <code>TransformStreamDefaultController</code> manages the internal state
16541cb0ef41Sopenharmony_ciof the <code>TransformStream</code>.</p>
16551cb0ef41Sopenharmony_ci<h5><code>transformStreamDefaultController.desiredSize</code><span><a class="mark" href="#transformstreamdefaultcontrollerdesiredsize" id="transformstreamdefaultcontrollerdesiredsize">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_transformstreamdefaultcontroller_desiredsize"></a></h5>
16561cb0ef41Sopenharmony_ci<div class="api_metadata">
16571cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
16581cb0ef41Sopenharmony_ci</div>
16591cb0ef41Sopenharmony_ci<ul>
16601cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
16611cb0ef41Sopenharmony_ci</ul>
16621cb0ef41Sopenharmony_ci<p>The amount of data required to fill the readable side's queue.</p>
16631cb0ef41Sopenharmony_ci<h5><code>transformStreamDefaultController.enqueue([chunk])</code><span><a class="mark" href="#transformstreamdefaultcontrollerenqueuechunk" id="transformstreamdefaultcontrollerenqueuechunk">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_transformstreamdefaultcontroller_enqueue_chunk"></a></h5>
16641cb0ef41Sopenharmony_ci<div class="api_metadata">
16651cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
16661cb0ef41Sopenharmony_ci</div>
16671cb0ef41Sopenharmony_ci<ul>
16681cb0ef41Sopenharmony_ci<li><code>chunk</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
16691cb0ef41Sopenharmony_ci</ul>
16701cb0ef41Sopenharmony_ci<p>Appends a chunk of data to the readable side's queue.</p>
16711cb0ef41Sopenharmony_ci<h5><code>transformStreamDefaultController.error([reason])</code><span><a class="mark" href="#transformstreamdefaultcontrollererrorreason" id="transformstreamdefaultcontrollererrorreason">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_transformstreamdefaultcontroller_error_reason"></a></h5>
16721cb0ef41Sopenharmony_ci<div class="api_metadata">
16731cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
16741cb0ef41Sopenharmony_ci</div>
16751cb0ef41Sopenharmony_ci<ul>
16761cb0ef41Sopenharmony_ci<li><code>reason</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
16771cb0ef41Sopenharmony_ci</ul>
16781cb0ef41Sopenharmony_ci<p>Signals to both the readable and writable side that an error has occurred
16791cb0ef41Sopenharmony_ciwhile processing the transform data, causing both sides to be abruptly
16801cb0ef41Sopenharmony_ciclosed.</p>
16811cb0ef41Sopenharmony_ci<h5><code>transformStreamDefaultController.terminate()</code><span><a class="mark" href="#transformstreamdefaultcontrollerterminate" id="transformstreamdefaultcontrollerterminate">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_transformstreamdefaultcontroller_terminate"></a></h5>
16821cb0ef41Sopenharmony_ci<div class="api_metadata">
16831cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
16841cb0ef41Sopenharmony_ci</div>
16851cb0ef41Sopenharmony_ci<p>Closes the readable side of the transport and causes the writable side
16861cb0ef41Sopenharmony_cito be abruptly closed with an error.</p>
16871cb0ef41Sopenharmony_ci<h4>Class: <code>ByteLengthQueuingStrategy</code><span><a class="mark" href="#class-bytelengthqueuingstrategy" id="class-bytelengthqueuingstrategy">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_bytelengthqueuingstrategy"></a></h4>
16881cb0ef41Sopenharmony_ci<div class="api_metadata">
16891cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
16901cb0ef41Sopenharmony_ci<table>
16911cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
16921cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
16931cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
16941cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
16951cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
16961cb0ef41Sopenharmony_ci</tbody></table>
16971cb0ef41Sopenharmony_ci</details>
16981cb0ef41Sopenharmony_ci</div>
16991cb0ef41Sopenharmony_ci<h5><code>new ByteLengthQueuingStrategy(init)</code><span><a class="mark" href="#new-bytelengthqueuingstrategyinit" id="new-bytelengthqueuingstrategyinit">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_new_bytelengthqueuingstrategy_init"></a></h5>
17001cb0ef41Sopenharmony_ci<div class="api_metadata">
17011cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
17021cb0ef41Sopenharmony_ci</div>
17031cb0ef41Sopenharmony_ci<ul>
17041cb0ef41Sopenharmony_ci<li><code>init</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
17051cb0ef41Sopenharmony_ci<ul>
17061cb0ef41Sopenharmony_ci<li><code>highWaterMark</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
17071cb0ef41Sopenharmony_ci</ul>
17081cb0ef41Sopenharmony_ci</li>
17091cb0ef41Sopenharmony_ci</ul>
17101cb0ef41Sopenharmony_ci<h5><code>byteLengthQueuingStrategy.highWaterMark</code><span><a class="mark" href="#bytelengthqueuingstrategyhighwatermark" id="bytelengthqueuingstrategyhighwatermark">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_bytelengthqueuingstrategy_highwatermark"></a></h5>
17111cb0ef41Sopenharmony_ci<div class="api_metadata">
17121cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
17131cb0ef41Sopenharmony_ci</div>
17141cb0ef41Sopenharmony_ci<ul>
17151cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
17161cb0ef41Sopenharmony_ci</ul>
17171cb0ef41Sopenharmony_ci<h5><code>byteLengthQueuingStrategy.size</code><span><a class="mark" href="#bytelengthqueuingstrategysize" id="bytelengthqueuingstrategysize">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_bytelengthqueuingstrategy_size"></a></h5>
17181cb0ef41Sopenharmony_ci<div class="api_metadata">
17191cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
17201cb0ef41Sopenharmony_ci</div>
17211cb0ef41Sopenharmony_ci<ul>
17221cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
17231cb0ef41Sopenharmony_ci<ul>
17241cb0ef41Sopenharmony_ci<li><code>chunk</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
17251cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
17261cb0ef41Sopenharmony_ci</ul>
17271cb0ef41Sopenharmony_ci</li>
17281cb0ef41Sopenharmony_ci</ul>
17291cb0ef41Sopenharmony_ci<h4>Class: <code>CountQueuingStrategy</code><span><a class="mark" href="#class-countqueuingstrategy" id="class-countqueuingstrategy">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_countqueuingstrategy"></a></h4>
17301cb0ef41Sopenharmony_ci<div class="api_metadata">
17311cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
17321cb0ef41Sopenharmony_ci<table>
17331cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
17341cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
17351cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
17361cb0ef41Sopenharmony_ci<tr><td>v16.5.0</td>
17371cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.5.0</span></p></td></tr>
17381cb0ef41Sopenharmony_ci</tbody></table>
17391cb0ef41Sopenharmony_ci</details>
17401cb0ef41Sopenharmony_ci</div>
17411cb0ef41Sopenharmony_ci<h5><code>new CountQueuingStrategy(init)</code><span><a class="mark" href="#new-countqueuingstrategyinit" id="new-countqueuingstrategyinit">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_new_countqueuingstrategy_init"></a></h5>
17421cb0ef41Sopenharmony_ci<div class="api_metadata">
17431cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
17441cb0ef41Sopenharmony_ci</div>
17451cb0ef41Sopenharmony_ci<ul>
17461cb0ef41Sopenharmony_ci<li><code>init</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
17471cb0ef41Sopenharmony_ci<ul>
17481cb0ef41Sopenharmony_ci<li><code>highWaterMark</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
17491cb0ef41Sopenharmony_ci</ul>
17501cb0ef41Sopenharmony_ci</li>
17511cb0ef41Sopenharmony_ci</ul>
17521cb0ef41Sopenharmony_ci<h5><code>countQueuingStrategy.highWaterMark</code><span><a class="mark" href="#countqueuingstrategyhighwatermark" id="countqueuingstrategyhighwatermark">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_countqueuingstrategy_highwatermark"></a></h5>
17531cb0ef41Sopenharmony_ci<div class="api_metadata">
17541cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
17551cb0ef41Sopenharmony_ci</div>
17561cb0ef41Sopenharmony_ci<ul>
17571cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
17581cb0ef41Sopenharmony_ci</ul>
17591cb0ef41Sopenharmony_ci<h5><code>countQueuingStrategy.size</code><span><a class="mark" href="#countqueuingstrategysize" id="countqueuingstrategysize">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_countqueuingstrategy_size"></a></h5>
17601cb0ef41Sopenharmony_ci<div class="api_metadata">
17611cb0ef41Sopenharmony_ci<span>Added in: v16.5.0</span>
17621cb0ef41Sopenharmony_ci</div>
17631cb0ef41Sopenharmony_ci<ul>
17641cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function" class="type">&#x3C;Function></a>
17651cb0ef41Sopenharmony_ci<ul>
17661cb0ef41Sopenharmony_ci<li><code>chunk</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types" class="type">&#x3C;any></a></li>
17671cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type" class="type">&#x3C;number></a></li>
17681cb0ef41Sopenharmony_ci</ul>
17691cb0ef41Sopenharmony_ci</li>
17701cb0ef41Sopenharmony_ci</ul>
17711cb0ef41Sopenharmony_ci<h4>Class: <code>TextEncoderStream</code><span><a class="mark" href="#class-textencoderstream" id="class-textencoderstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_textencoderstream"></a></h4>
17721cb0ef41Sopenharmony_ci<div class="api_metadata">
17731cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
17741cb0ef41Sopenharmony_ci<table>
17751cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
17761cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
17771cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
17781cb0ef41Sopenharmony_ci<tr><td>v16.6.0</td>
17791cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.6.0</span></p></td></tr>
17801cb0ef41Sopenharmony_ci</tbody></table>
17811cb0ef41Sopenharmony_ci</details>
17821cb0ef41Sopenharmony_ci</div>
17831cb0ef41Sopenharmony_ci<h5><code>new TextEncoderStream()</code><span><a class="mark" href="#new-textencoderstream" id="new-textencoderstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_new_textencoderstream"></a></h5>
17841cb0ef41Sopenharmony_ci<div class="api_metadata">
17851cb0ef41Sopenharmony_ci<span>Added in: v16.6.0</span>
17861cb0ef41Sopenharmony_ci</div>
17871cb0ef41Sopenharmony_ci<p>Creates a new <code>TextEncoderStream</code> instance.</p>
17881cb0ef41Sopenharmony_ci<h5><code>textEncoderStream.encoding</code><span><a class="mark" href="#textencoderstreamencoding" id="textencoderstreamencoding">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_textencoderstream_encoding"></a></h5>
17891cb0ef41Sopenharmony_ci<div class="api_metadata">
17901cb0ef41Sopenharmony_ci<span>Added in: v16.6.0</span>
17911cb0ef41Sopenharmony_ci</div>
17921cb0ef41Sopenharmony_ci<ul>
17931cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
17941cb0ef41Sopenharmony_ci</ul>
17951cb0ef41Sopenharmony_ci<p>The encoding supported by the <code>TextEncoderStream</code> instance.</p>
17961cb0ef41Sopenharmony_ci<h5><code>textEncoderStream.readable</code><span><a class="mark" href="#textencoderstreamreadable" id="textencoderstreamreadable">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_textencoderstream_readable"></a></h5>
17971cb0ef41Sopenharmony_ci<div class="api_metadata">
17981cb0ef41Sopenharmony_ci<span>Added in: v16.6.0</span>
17991cb0ef41Sopenharmony_ci</div>
18001cb0ef41Sopenharmony_ci<ul>
18011cb0ef41Sopenharmony_ci<li>Type: <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a></li>
18021cb0ef41Sopenharmony_ci</ul>
18031cb0ef41Sopenharmony_ci<h5><code>textEncoderStream.writable</code><span><a class="mark" href="#textencoderstreamwritable" id="textencoderstreamwritable">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_textencoderstream_writable"></a></h5>
18041cb0ef41Sopenharmony_ci<div class="api_metadata">
18051cb0ef41Sopenharmony_ci<span>Added in: v16.6.0</span>
18061cb0ef41Sopenharmony_ci</div>
18071cb0ef41Sopenharmony_ci<ul>
18081cb0ef41Sopenharmony_ci<li>Type: <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a></li>
18091cb0ef41Sopenharmony_ci</ul>
18101cb0ef41Sopenharmony_ci<h4>Class: <code>TextDecoderStream</code><span><a class="mark" href="#class-textdecoderstream" id="class-textdecoderstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_textdecoderstream"></a></h4>
18111cb0ef41Sopenharmony_ci<div class="api_metadata">
18121cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
18131cb0ef41Sopenharmony_ci<table>
18141cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
18151cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
18161cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
18171cb0ef41Sopenharmony_ci<tr><td>v16.6.0</td>
18181cb0ef41Sopenharmony_ci<td><p><span>Added in: v16.6.0</span></p></td></tr>
18191cb0ef41Sopenharmony_ci</tbody></table>
18201cb0ef41Sopenharmony_ci</details>
18211cb0ef41Sopenharmony_ci</div>
18221cb0ef41Sopenharmony_ci<h5><code>new TextDecoderStream([encoding[, options]])</code><span><a class="mark" href="#new-textdecoderstreamencoding-options" id="new-textdecoderstreamencoding-options">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_new_textdecoderstream_encoding_options"></a></h5>
18231cb0ef41Sopenharmony_ci<div class="api_metadata">
18241cb0ef41Sopenharmony_ci<span>Added in: v16.6.0</span>
18251cb0ef41Sopenharmony_ci</div>
18261cb0ef41Sopenharmony_ci<ul>
18271cb0ef41Sopenharmony_ci<li><code>encoding</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> Identifies the <code>encoding</code> that this <code>TextDecoder</code> instance
18281cb0ef41Sopenharmony_cisupports. <strong>Default:</strong> <code>'utf-8'</code>.</li>
18291cb0ef41Sopenharmony_ci<li><code>options</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object" class="type">&#x3C;Object></a>
18301cb0ef41Sopenharmony_ci<ul>
18311cb0ef41Sopenharmony_ci<li><code>fatal</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> <code>true</code> if decoding failures are fatal.</li>
18321cb0ef41Sopenharmony_ci<li><code>ignoreBOM</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a> When <code>true</code>, the <code>TextDecoderStream</code> will include the
18331cb0ef41Sopenharmony_cibyte order mark in the decoded result. When <code>false</code>, the byte order mark
18341cb0ef41Sopenharmony_ciwill be removed from the output. This option is only used when <code>encoding</code> is
18351cb0ef41Sopenharmony_ci<code>'utf-8'</code>, <code>'utf-16be'</code>, or <code>'utf-16le'</code>. <strong>Default:</strong> <code>false</code>.</li>
18361cb0ef41Sopenharmony_ci</ul>
18371cb0ef41Sopenharmony_ci</li>
18381cb0ef41Sopenharmony_ci</ul>
18391cb0ef41Sopenharmony_ci<p>Creates a new <code>TextDecoderStream</code> instance.</p>
18401cb0ef41Sopenharmony_ci<h5><code>textDecoderStream.encoding</code><span><a class="mark" href="#textdecoderstreamencoding" id="textdecoderstreamencoding">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_textdecoderstream_encoding"></a></h5>
18411cb0ef41Sopenharmony_ci<div class="api_metadata">
18421cb0ef41Sopenharmony_ci<span>Added in: v16.6.0</span>
18431cb0ef41Sopenharmony_ci</div>
18441cb0ef41Sopenharmony_ci<ul>
18451cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a></li>
18461cb0ef41Sopenharmony_ci</ul>
18471cb0ef41Sopenharmony_ci<p>The encoding supported by the <code>TextDecoderStream</code> instance.</p>
18481cb0ef41Sopenharmony_ci<h5><code>textDecoderStream.fatal</code><span><a class="mark" href="#textdecoderstreamfatal" id="textdecoderstreamfatal">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_textdecoderstream_fatal"></a></h5>
18491cb0ef41Sopenharmony_ci<div class="api_metadata">
18501cb0ef41Sopenharmony_ci<span>Added in: v16.6.0</span>
18511cb0ef41Sopenharmony_ci</div>
18521cb0ef41Sopenharmony_ci<ul>
18531cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
18541cb0ef41Sopenharmony_ci</ul>
18551cb0ef41Sopenharmony_ci<p>The value will be <code>true</code> if decoding errors result in a <code>TypeError</code> being
18561cb0ef41Sopenharmony_cithrown.</p>
18571cb0ef41Sopenharmony_ci<h5><code>textDecoderStream.ignoreBOM</code><span><a class="mark" href="#textdecoderstreamignorebom" id="textdecoderstreamignorebom">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_textdecoderstream_ignorebom"></a></h5>
18581cb0ef41Sopenharmony_ci<div class="api_metadata">
18591cb0ef41Sopenharmony_ci<span>Added in: v16.6.0</span>
18601cb0ef41Sopenharmony_ci</div>
18611cb0ef41Sopenharmony_ci<ul>
18621cb0ef41Sopenharmony_ci<li>Type: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type" class="type">&#x3C;boolean></a></li>
18631cb0ef41Sopenharmony_ci</ul>
18641cb0ef41Sopenharmony_ci<p>The value will be <code>true</code> if the decoding result will include the byte order
18651cb0ef41Sopenharmony_cimark.</p>
18661cb0ef41Sopenharmony_ci<h5><code>textDecoderStream.readable</code><span><a class="mark" href="#textdecoderstreamreadable" id="textdecoderstreamreadable">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_textdecoderstream_readable"></a></h5>
18671cb0ef41Sopenharmony_ci<div class="api_metadata">
18681cb0ef41Sopenharmony_ci<span>Added in: v16.6.0</span>
18691cb0ef41Sopenharmony_ci</div>
18701cb0ef41Sopenharmony_ci<ul>
18711cb0ef41Sopenharmony_ci<li>Type: <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a></li>
18721cb0ef41Sopenharmony_ci</ul>
18731cb0ef41Sopenharmony_ci<h5><code>textDecoderStream.writable</code><span><a class="mark" href="#textdecoderstreamwritable" id="textdecoderstreamwritable">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_textdecoderstream_writable"></a></h5>
18741cb0ef41Sopenharmony_ci<div class="api_metadata">
18751cb0ef41Sopenharmony_ci<span>Added in: v16.6.0</span>
18761cb0ef41Sopenharmony_ci</div>
18771cb0ef41Sopenharmony_ci<ul>
18781cb0ef41Sopenharmony_ci<li>Type: <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a></li>
18791cb0ef41Sopenharmony_ci</ul>
18801cb0ef41Sopenharmony_ci<h4>Class: <code>CompressionStream</code><span><a class="mark" href="#class-compressionstream" id="class-compressionstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_compressionstream"></a></h4>
18811cb0ef41Sopenharmony_ci<div class="api_metadata">
18821cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
18831cb0ef41Sopenharmony_ci<table>
18841cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
18851cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
18861cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
18871cb0ef41Sopenharmony_ci<tr><td>v17.0.0</td>
18881cb0ef41Sopenharmony_ci<td><p><span>Added in: v17.0.0</span></p></td></tr>
18891cb0ef41Sopenharmony_ci</tbody></table>
18901cb0ef41Sopenharmony_ci</details>
18911cb0ef41Sopenharmony_ci</div>
18921cb0ef41Sopenharmony_ci<h5><code>new CompressionStream(format)</code><span><a class="mark" href="#new-compressionstreamformat" id="new-compressionstreamformat">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_new_compressionstream_format"></a></h5>
18931cb0ef41Sopenharmony_ci<div class="api_metadata">
18941cb0ef41Sopenharmony_ci<span>Added in: v17.0.0</span>
18951cb0ef41Sopenharmony_ci</div>
18961cb0ef41Sopenharmony_ci<ul>
18971cb0ef41Sopenharmony_ci<li><code>format</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> One of either <code>'deflate'</code> or <code>'gzip'</code>.</li>
18981cb0ef41Sopenharmony_ci</ul>
18991cb0ef41Sopenharmony_ci<h5><code>compressionStream.readable</code><span><a class="mark" href="#compressionstreamreadable" id="compressionstreamreadable">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_compressionstream_readable"></a></h5>
19001cb0ef41Sopenharmony_ci<div class="api_metadata">
19011cb0ef41Sopenharmony_ci<span>Added in: v17.0.0</span>
19021cb0ef41Sopenharmony_ci</div>
19031cb0ef41Sopenharmony_ci<ul>
19041cb0ef41Sopenharmony_ci<li>Type: <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a></li>
19051cb0ef41Sopenharmony_ci</ul>
19061cb0ef41Sopenharmony_ci<h5><code>compressionStream.writable</code><span><a class="mark" href="#compressionstreamwritable" id="compressionstreamwritable">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_compressionstream_writable"></a></h5>
19071cb0ef41Sopenharmony_ci<div class="api_metadata">
19081cb0ef41Sopenharmony_ci<span>Added in: v17.0.0</span>
19091cb0ef41Sopenharmony_ci</div>
19101cb0ef41Sopenharmony_ci<ul>
19111cb0ef41Sopenharmony_ci<li>Type: <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a></li>
19121cb0ef41Sopenharmony_ci</ul>
19131cb0ef41Sopenharmony_ci<h4>Class: <code>DecompressionStream</code><span><a class="mark" href="#class-decompressionstream" id="class-decompressionstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_class_decompressionstream"></a></h4>
19141cb0ef41Sopenharmony_ci<div class="api_metadata">
19151cb0ef41Sopenharmony_ci<details class="changelog"><summary>History</summary>
19161cb0ef41Sopenharmony_ci<table>
19171cb0ef41Sopenharmony_ci<tbody><tr><th>Version</th><th>Changes</th></tr>
19181cb0ef41Sopenharmony_ci<tr><td>v18.0.0</td>
19191cb0ef41Sopenharmony_ci<td><p>This class is now exposed on the global object.</p></td></tr>
19201cb0ef41Sopenharmony_ci<tr><td>v17.0.0</td>
19211cb0ef41Sopenharmony_ci<td><p><span>Added in: v17.0.0</span></p></td></tr>
19221cb0ef41Sopenharmony_ci</tbody></table>
19231cb0ef41Sopenharmony_ci</details>
19241cb0ef41Sopenharmony_ci</div>
19251cb0ef41Sopenharmony_ci<h5><code>new DecompressionStream(format)</code><span><a class="mark" href="#new-decompressionstreamformat" id="new-decompressionstreamformat">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_new_decompressionstream_format"></a></h5>
19261cb0ef41Sopenharmony_ci<div class="api_metadata">
19271cb0ef41Sopenharmony_ci<span>Added in: v17.0.0</span>
19281cb0ef41Sopenharmony_ci</div>
19291cb0ef41Sopenharmony_ci<ul>
19301cb0ef41Sopenharmony_ci<li><code>format</code> <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type" class="type">&#x3C;string></a> One of either <code>'deflate'</code> or <code>'gzip'</code>.</li>
19311cb0ef41Sopenharmony_ci</ul>
19321cb0ef41Sopenharmony_ci<h5><code>decompressionStream.readable</code><span><a class="mark" href="#decompressionstreamreadable" id="decompressionstreamreadable">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_decompressionstream_readable"></a></h5>
19331cb0ef41Sopenharmony_ci<div class="api_metadata">
19341cb0ef41Sopenharmony_ci<span>Added in: v17.0.0</span>
19351cb0ef41Sopenharmony_ci</div>
19361cb0ef41Sopenharmony_ci<ul>
19371cb0ef41Sopenharmony_ci<li>Type: <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a></li>
19381cb0ef41Sopenharmony_ci</ul>
19391cb0ef41Sopenharmony_ci<h5><code>decompressionStream.writable</code><span><a class="mark" href="#decompressionstreamwritable" id="decompressionstreamwritable">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_decompressionstream_writable"></a></h5>
19401cb0ef41Sopenharmony_ci<div class="api_metadata">
19411cb0ef41Sopenharmony_ci<span>Added in: v17.0.0</span>
19421cb0ef41Sopenharmony_ci</div>
19431cb0ef41Sopenharmony_ci<ul>
19441cb0ef41Sopenharmony_ci<li>Type: <a href="webstreams.html#class-writablestream" class="type">&#x3C;WritableStream></a></li>
19451cb0ef41Sopenharmony_ci</ul>
19461cb0ef41Sopenharmony_ci<h4>Utility Consumers<span><a class="mark" href="#utility-consumers" id="utility-consumers">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_utility_consumers"></a></h4>
19471cb0ef41Sopenharmony_ci<div class="api_metadata">
19481cb0ef41Sopenharmony_ci<span>Added in: v16.7.0</span>
19491cb0ef41Sopenharmony_ci</div>
19501cb0ef41Sopenharmony_ci<p>The utility consumer functions provide common options for consuming
19511cb0ef41Sopenharmony_cistreams.</p>
19521cb0ef41Sopenharmony_ci<p>They are accessed using:</p>
19531cb0ef41Sopenharmony_ci
19541cb0ef41Sopenharmony_ci<pre class="with-14-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> {
19551cb0ef41Sopenharmony_ci  arrayBuffer,
19561cb0ef41Sopenharmony_ci  blob,
19571cb0ef41Sopenharmony_ci  buffer,
19581cb0ef41Sopenharmony_ci  json,
19591cb0ef41Sopenharmony_ci  text,
19601cb0ef41Sopenharmony_ci} <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream/consumers'</span>;</code><code class="language-js cjs"><span class="hljs-keyword">const</span> {
19611cb0ef41Sopenharmony_ci  arrayBuffer,
19621cb0ef41Sopenharmony_ci  blob,
19631cb0ef41Sopenharmony_ci  buffer,
19641cb0ef41Sopenharmony_ci  json,
19651cb0ef41Sopenharmony_ci  text,
19661cb0ef41Sopenharmony_ci} = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream/consumers'</span>);</code><button class="copy-button">copy</button></pre>
19671cb0ef41Sopenharmony_ci<h5><code>streamConsumers.arrayBuffer(stream)</code><span><a class="mark" href="#streamconsumersarraybufferstream" id="streamconsumersarraybufferstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_streamconsumers_arraybuffer_stream"></a></h5>
19681cb0ef41Sopenharmony_ci<div class="api_metadata">
19691cb0ef41Sopenharmony_ci<span>Added in: v16.7.0</span>
19701cb0ef41Sopenharmony_ci</div>
19711cb0ef41Sopenharmony_ci<ul>
19721cb0ef41Sopenharmony_ci<li><code>stream</code> <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> | <a href="stream.html#class-streamreadable" class="type">&#x3C;stream.Readable></a> | <a href="https://tc39.github.io/ecma262/#sec-asynciterator-interface" class="type">&#x3C;AsyncIterator></a></li>
19731cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a> Fulfills with an <code>ArrayBuffer</code> containing the full
19741cb0ef41Sopenharmony_cicontents of the stream.</li>
19751cb0ef41Sopenharmony_ci</ul>
19761cb0ef41Sopenharmony_ci
19771cb0ef41Sopenharmony_ci<pre class="with-57-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { arrayBuffer } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream/consumers'</span>;
19781cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> { <span class="hljs-title class_">Readable</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream'</span>;
19791cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> { <span class="hljs-title class_">TextEncoder</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:util'</span>;
19801cb0ef41Sopenharmony_ci
19811cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> encoder = <span class="hljs-keyword">new</span> <span class="hljs-title class_">TextEncoder</span>();
19821cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> dataArray = encoder.<span class="hljs-title function_">encode</span>(<span class="hljs-string">'hello world from consumers!'</span>);
19831cb0ef41Sopenharmony_ci
19841cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> readable = <span class="hljs-title class_">Readable</span>.<span class="hljs-title function_">from</span>(dataArray);
19851cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> <span class="hljs-title function_">arrayBuffer</span>(readable);
19861cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`from readable: <span class="hljs-subst">${data.byteLength}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { arrayBuffer } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream/consumers'</span>);
19871cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { <span class="hljs-title class_">Readable</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream'</span>);
19881cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { <span class="hljs-title class_">TextEncoder</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:util'</span>);
19891cb0ef41Sopenharmony_ci
19901cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> encoder = <span class="hljs-keyword">new</span> <span class="hljs-title class_">TextEncoder</span>();
19911cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> dataArray = encoder.<span class="hljs-title function_">encode</span>(<span class="hljs-string">'hello world from consumers!'</span>);
19921cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> readable = <span class="hljs-title class_">Readable</span>.<span class="hljs-title function_">from</span>(dataArray);
19931cb0ef41Sopenharmony_ci<span class="hljs-title function_">arrayBuffer</span>(readable).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">data</span>) =></span> {
19941cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`from readable: <span class="hljs-subst">${data.byteLength}</span>`</span>);
19951cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
19961cb0ef41Sopenharmony_ci<h5><code>streamConsumers.blob(stream)</code><span><a class="mark" href="#streamconsumersblobstream" id="streamconsumersblobstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_streamconsumers_blob_stream"></a></h5>
19971cb0ef41Sopenharmony_ci<div class="api_metadata">
19981cb0ef41Sopenharmony_ci<span>Added in: v16.7.0</span>
19991cb0ef41Sopenharmony_ci</div>
20001cb0ef41Sopenharmony_ci<ul>
20011cb0ef41Sopenharmony_ci<li><code>stream</code> <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> | <a href="stream.html#class-streamreadable" class="type">&#x3C;stream.Readable></a> | <a href="https://tc39.github.io/ecma262/#sec-asynciterator-interface" class="type">&#x3C;AsyncIterator></a></li>
20021cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a> Fulfills with a <a href="buffer.html#class-blob" class="type">&#x3C;Blob></a> containing the full contents
20031cb0ef41Sopenharmony_ciof the stream.</li>
20041cb0ef41Sopenharmony_ci</ul>
20051cb0ef41Sopenharmony_ci
20061cb0ef41Sopenharmony_ci<pre class="with-50-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { blob } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream/consumers'</span>;
20071cb0ef41Sopenharmony_ci
20081cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> dataBlob = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Blob</span>([<span class="hljs-string">'hello world from consumers!'</span>]);
20091cb0ef41Sopenharmony_ci
20101cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> readable = dataBlob.<span class="hljs-title function_">stream</span>();
20111cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> <span class="hljs-title function_">blob</span>(readable);
20121cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`from readable: <span class="hljs-subst">${data.size}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { blob } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream/consumers'</span>);
20131cb0ef41Sopenharmony_ci
20141cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> dataBlob = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Blob</span>([<span class="hljs-string">'hello world from consumers!'</span>]);
20151cb0ef41Sopenharmony_ci
20161cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> readable = dataBlob.<span class="hljs-title function_">stream</span>();
20171cb0ef41Sopenharmony_ci<span class="hljs-title function_">blob</span>(readable).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">data</span>) =></span> {
20181cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`from readable: <span class="hljs-subst">${data.size}</span>`</span>);
20191cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
20201cb0ef41Sopenharmony_ci<h5><code>streamConsumers.buffer(stream)</code><span><a class="mark" href="#streamconsumersbufferstream" id="streamconsumersbufferstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_streamconsumers_buffer_stream"></a></h5>
20211cb0ef41Sopenharmony_ci<div class="api_metadata">
20221cb0ef41Sopenharmony_ci<span>Added in: v16.7.0</span>
20231cb0ef41Sopenharmony_ci</div>
20241cb0ef41Sopenharmony_ci<ul>
20251cb0ef41Sopenharmony_ci<li><code>stream</code> <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> | <a href="stream.html#class-streamreadable" class="type">&#x3C;stream.Readable></a> | <a href="https://tc39.github.io/ecma262/#sec-asynciterator-interface" class="type">&#x3C;AsyncIterator></a></li>
20261cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a> Fulfills with a <a href="buffer.html#class-buffer" class="type">&#x3C;Buffer></a> containing the full
20271cb0ef41Sopenharmony_cicontents of the stream.</li>
20281cb0ef41Sopenharmony_ci</ul>
20291cb0ef41Sopenharmony_ci
20301cb0ef41Sopenharmony_ci<pre class="with-52-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { buffer } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream/consumers'</span>;
20311cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> { <span class="hljs-title class_">Readable</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream'</span>;
20321cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> { <span class="hljs-title class_">Buffer</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:buffer'</span>;
20331cb0ef41Sopenharmony_ci
20341cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> dataBuffer = <span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">from</span>(<span class="hljs-string">'hello world from consumers!'</span>);
20351cb0ef41Sopenharmony_ci
20361cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> readable = <span class="hljs-title class_">Readable</span>.<span class="hljs-title function_">from</span>(dataBuffer);
20371cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> <span class="hljs-title function_">buffer</span>(readable);
20381cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`from readable: <span class="hljs-subst">${data.length}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { buffer } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream/consumers'</span>);
20391cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { <span class="hljs-title class_">Readable</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream'</span>);
20401cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { <span class="hljs-title class_">Buffer</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:buffer'</span>);
20411cb0ef41Sopenharmony_ci
20421cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> dataBuffer = <span class="hljs-title class_">Buffer</span>.<span class="hljs-title function_">from</span>(<span class="hljs-string">'hello world from consumers!'</span>);
20431cb0ef41Sopenharmony_ci
20441cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> readable = <span class="hljs-title class_">Readable</span>.<span class="hljs-title function_">from</span>(dataBuffer);
20451cb0ef41Sopenharmony_ci<span class="hljs-title function_">buffer</span>(readable).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">data</span>) =></span> {
20461cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`from readable: <span class="hljs-subst">${data.length}</span>`</span>);
20471cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
20481cb0ef41Sopenharmony_ci<h5><code>streamConsumers.json(stream)</code><span><a class="mark" href="#streamconsumersjsonstream" id="streamconsumersjsonstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_streamconsumers_json_stream"></a></h5>
20491cb0ef41Sopenharmony_ci<div class="api_metadata">
20501cb0ef41Sopenharmony_ci<span>Added in: v16.7.0</span>
20511cb0ef41Sopenharmony_ci</div>
20521cb0ef41Sopenharmony_ci<ul>
20531cb0ef41Sopenharmony_ci<li><code>stream</code> <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> | <a href="stream.html#class-streamreadable" class="type">&#x3C;stream.Readable></a> | <a href="https://tc39.github.io/ecma262/#sec-asynciterator-interface" class="type">&#x3C;AsyncIterator></a></li>
20541cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a> Fulfills with the contents of the stream parsed as a
20551cb0ef41Sopenharmony_ciUTF-8 encoded string that is then passed through <code>JSON.parse()</code>.</li>
20561cb0ef41Sopenharmony_ci</ul>
20571cb0ef41Sopenharmony_ci
20581cb0ef41Sopenharmony_ci<pre class="with-50-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { json } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream/consumers'</span>;
20591cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> { <span class="hljs-title class_">Readable</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream'</span>;
20601cb0ef41Sopenharmony_ci
20611cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> items = <span class="hljs-title class_">Array</span>.<span class="hljs-title function_">from</span>(
20621cb0ef41Sopenharmony_ci  {
20631cb0ef41Sopenharmony_ci    <span class="hljs-attr">length</span>: <span class="hljs-number">100</span>,
20641cb0ef41Sopenharmony_ci  },
20651cb0ef41Sopenharmony_ci  <span class="hljs-function">() =></span> ({
20661cb0ef41Sopenharmony_ci    <span class="hljs-attr">message</span>: <span class="hljs-string">'hello world from consumers!'</span>,
20671cb0ef41Sopenharmony_ci  }),
20681cb0ef41Sopenharmony_ci);
20691cb0ef41Sopenharmony_ci
20701cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> readable = <span class="hljs-title class_">Readable</span>.<span class="hljs-title function_">from</span>(<span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">stringify</span>(items));
20711cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> <span class="hljs-title function_">json</span>(readable);
20721cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`from readable: <span class="hljs-subst">${data.length}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { json } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream/consumers'</span>);
20731cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { <span class="hljs-title class_">Readable</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream'</span>);
20741cb0ef41Sopenharmony_ci
20751cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> items = <span class="hljs-title class_">Array</span>.<span class="hljs-title function_">from</span>(
20761cb0ef41Sopenharmony_ci  {
20771cb0ef41Sopenharmony_ci    <span class="hljs-attr">length</span>: <span class="hljs-number">100</span>,
20781cb0ef41Sopenharmony_ci  },
20791cb0ef41Sopenharmony_ci  <span class="hljs-function">() =></span> ({
20801cb0ef41Sopenharmony_ci    <span class="hljs-attr">message</span>: <span class="hljs-string">'hello world from consumers!'</span>,
20811cb0ef41Sopenharmony_ci  }),
20821cb0ef41Sopenharmony_ci);
20831cb0ef41Sopenharmony_ci
20841cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> readable = <span class="hljs-title class_">Readable</span>.<span class="hljs-title function_">from</span>(<span class="hljs-title class_">JSON</span>.<span class="hljs-title function_">stringify</span>(items));
20851cb0ef41Sopenharmony_ci<span class="hljs-title function_">json</span>(readable).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">data</span>) =></span> {
20861cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`from readable: <span class="hljs-subst">${data.length}</span>`</span>);
20871cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre>
20881cb0ef41Sopenharmony_ci<h5><code>streamConsumers.text(stream)</code><span><a class="mark" href="#streamconsumerstextstream" id="streamconsumerstextstream">#</a></span><a aria-hidden="true" class="legacy" id="webstreams_streamconsumers_text_stream"></a></h5>
20891cb0ef41Sopenharmony_ci<div class="api_metadata">
20901cb0ef41Sopenharmony_ci<span>Added in: v16.7.0</span>
20911cb0ef41Sopenharmony_ci</div>
20921cb0ef41Sopenharmony_ci<ul>
20931cb0ef41Sopenharmony_ci<li><code>stream</code> <a href="webstreams.html#class-readablestream" class="type">&#x3C;ReadableStream></a> | <a href="stream.html#class-streamreadable" class="type">&#x3C;stream.Readable></a> | <a href="https://tc39.github.io/ecma262/#sec-asynciterator-interface" class="type">&#x3C;AsyncIterator></a></li>
20941cb0ef41Sopenharmony_ci<li>Returns: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise" class="type">&#x3C;Promise></a> Fulfills with the contents of the stream parsed as a
20951cb0ef41Sopenharmony_ciUTF-8 encoded string.</li>
20961cb0ef41Sopenharmony_ci</ul>
20971cb0ef41Sopenharmony_ci
20981cb0ef41Sopenharmony_ci<pre class="with-50-chars"><input class="js-flavor-selector" type="checkbox" checked aria-label="Show modern ES modules syntax"><code class="language-js mjs"><span class="hljs-keyword">import</span> { text } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream/consumers'</span>;
20991cb0ef41Sopenharmony_ci<span class="hljs-keyword">import</span> { <span class="hljs-title class_">Readable</span> } <span class="hljs-keyword">from</span> <span class="hljs-string">'node:stream'</span>;
21001cb0ef41Sopenharmony_ci
21011cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> readable = <span class="hljs-title class_">Readable</span>.<span class="hljs-title function_">from</span>(<span class="hljs-string">'Hello world from consumers!'</span>);
21021cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> data = <span class="hljs-keyword">await</span> <span class="hljs-title function_">text</span>(readable);
21031cb0ef41Sopenharmony_ci<span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`from readable: <span class="hljs-subst">${data.length}</span>`</span>);</code><code class="language-js cjs"><span class="hljs-keyword">const</span> { text } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream/consumers'</span>);
21041cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> { <span class="hljs-title class_">Readable</span> } = <span class="hljs-built_in">require</span>(<span class="hljs-string">'node:stream'</span>);
21051cb0ef41Sopenharmony_ci
21061cb0ef41Sopenharmony_ci<span class="hljs-keyword">const</span> readable = <span class="hljs-title class_">Readable</span>.<span class="hljs-title function_">from</span>(<span class="hljs-string">'Hello world from consumers!'</span>);
21071cb0ef41Sopenharmony_ci<span class="hljs-title function_">text</span>(readable).<span class="hljs-title function_">then</span>(<span class="hljs-function">(<span class="hljs-params">data</span>) =></span> {
21081cb0ef41Sopenharmony_ci  <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">`from readable: <span class="hljs-subst">${data.length}</span>`</span>);
21091cb0ef41Sopenharmony_ci});</code><button class="copy-button">copy</button></pre></section>
21101cb0ef41Sopenharmony_ci        <!-- API END -->
21111cb0ef41Sopenharmony_ci      </div>
21121cb0ef41Sopenharmony_ci    </div>
21131cb0ef41Sopenharmony_ci  </div>
21141cb0ef41Sopenharmony_ci</body>
21151cb0ef41Sopenharmony_ci</html>
2116