<p>If <code>false</code> then the stream will automatically end the writable side when the
readable side ends. Set initially by the <code>allowHalfOpen</code> constructor option,
which defaults to <code>false</code>.</p>
</div><div><p>This can be changed manually to change the half-open behavior of an existing<code>Duplex</code> stream instance, but must be changed before the <code>'end'</code> event is
</dd></dl></div></section><sectionclass="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-external"><aid="destroyed"class="tsd-anchor"></a><h3>destroyed</h3><divclass="tsd-signature tsd-kind-icon">destroyed<spanclass="tsd-signature-symbol">:</span><spanclass="tsd-signature-type">boolean</span></div><asideclass="tsd-sources"><p>Implementation of Writable.destroyed</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#destroyed">destroyed</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:115</li></ul></aside><divclass="tsd-comment tsd-typography"><divclass="lead">
<p>Is <code>true</code> after <code>readable.destroy()</code> has been called.</p>
</dd><dt>experimental</dt><dd></dd></dl></div></section><sectionclass="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-class tsd-is-inherited tsd-is-external"><aid="readableEncoding"class="tsd-anchor"></a><h3><spanclass="tsd-flag ts-flagReadonly">Readonly</span> readable<wbr/>Encoding</h3><divclass="tsd-signature tsd-kind-icon">readable<wbr/>Encoding<spanclass="tsd-signature-symbol">:</span><spanclass="tsd-signature-type">null</span><spanclass="tsd-signature-symbol"> | </span><ahref="../modules/_internal_.html#BufferEncoding"class="tsd-signature-type"data-tsd-kind="Type alias">BufferEncoding</a></div><asideclass="tsd-sources"><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#readableEncoding">readableEncoding</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:82</li></ul></aside><divclass="tsd-comment tsd-typography"><divclass="lead">
<p>Getter for the property <code>encoding</code> of a given <code>Readable</code> stream. The <code>encoding</code>property can be set using the <code>readable.setEncoding()</code> method.</p>
</div></div><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"close"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass="tsd-signature tsd-kind-icon"><spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">void</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.addListener</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#addListener">addListener</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:424</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"data"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span>chunk<spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">any</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass="tsd-signature tsd-kind-icon"><spanclass="tsd-signature-symbol">(</span>chunk<spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">any</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">void</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>chunk: <spanclass="tsd-signature-type">any</span></h5></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.addListener</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#addListener">addListener</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:425</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"end"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signaturestsd-ki
<p>Destroy the stream. Optionally emit an <code>'error'</code> event, and emit a <code>'close'</code>event (unless <code>emitClose</code> is set to <code>false</code>). After this call, the readable
stream will release any internal resources and subsequent calls to <code>push()</code>will be ignored.</p>
</div><div><p>Once <code>destroy()</code> has been called any further calls will be a no-op and no
further errors except from <code>_destroy()</code> may be emitted as <code>'error'</code>.</p>
<p>Implementors should not override this method, but instead implement <code>readable._destroy()</code>.</p>
<p>Synchronously calls each of the listeners registered for the event named<code>eventName</code>, in the order they were registered, passing the supplied arguments
to each.</p>
</div><div><p>Returns <code>true</code> if the event had listeners, <code>false</code> otherwise.</p>
<pre><codeclass="language-js"><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">EventEmitter</span><spanclass="hl-0"> = </span><spanclass="hl-7">require</span><spanclass="hl-0">(</span><spanclass="hl-4">'events'</span><spanclass="hl-0">);</span><br/><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">myEmitter</span><spanclass="hl-0"> = </span><spanclass="hl-2">new</span><spanclass="hl-0"></span><spanclass="hl-7">EventEmitter</span><spanclass="hl-0">();</span><br/><br/><spanclass="hl-5">// First listener</span><br/><spanclass="hl-3">myEmitter</span><spanclass="hl-0">.</span><spanclass="hl-7">on</span><spanclass="hl-0">(</span><spanclass="hl-4">'event'</span><spanclass="hl-0">, </span><spanclass="hl-2">function</span><spanclass="hl-0"></span><spanclass="hl-7">firstListener</span><spanclass="hl-0">() {</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'Helloooo! first listener'</span><spanclass="hl-0">);</span><br/><spanclass="hl-0">});</span><br/><spanclass="hl-5">// Second listener</span><br/><spanclass="hl-3">myEmitter</span><spanclass="hl-0">.</span><spanclass="hl-7">on</span><spanclass="hl-0">(</span><spanclass="hl-4">'event'</span><spanclass="hl-0">, </span><spanclass="hl-2">function</span><spanclass="hl-0"></span><spanclass="hl-7">secondListener</span><spanclass="hl-0">(</span><spanclass="hl-3">arg1</span><spanclass="hl-0">, </span><spanclass="hl-3">arg2</span><spanclass="hl-0">) {</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">`event with parameters </span><spanclass="hl-2">${</span><spanclass="hl-3">arg1</span><spanclass="hl-2">}</span><spanclass="hl-4">, </span><spanclass="hl-2">${</span><spanclass="hl-3">arg2</span><spanclass="hl-2">}</span><spanclass="hl-4"> in second listener`</span><spanclass="hl-0">);</span><br/><spanclass="hl-0">});</span><br/><spanclass="hl-5">// Third listener</span><br/><spanclass="hl-3">myEmitter</span><spanclass="hl-0">.</span><spanclass="hl-7">on</span><spanclass="hl-0">(</span><spanclass="hl-4">'event'</span><spanclass="hl-0">, </span><spanclass="hl-2">function</span><spanclass="hl-0"></span><spanclass="hl-7">thirdListener</span><spanclass="hl-0">(...</span><spanclass="hl-3">args</span><spanclass="hl-0">) {</span><br/><spanclass="hl-0"></span><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">parameters</span><spanclass="hl-0"> = </span><spanclass="hl-3">args</span><spanclass="hl-0">.</span><spanclass="hl-7">join</span><spanclass="hl-0">(</span><spanclass="hl-4">', '</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">`event with parameters </span><spanclass="hl-2">${</span><spanclass="hl-3">parameters</span><spanclass="hl-2">}</span><spanclass="hl-4"> in third listener`</span><spanclass="hl-0">);</span><br/><spanclass="hl-0">});</span><br/><br/><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-3">myEmitter</span><spanclass="hl-0">.</span><spanclass="hl-7">listeners</span><spanclass="hl-0">(</span><spanclass="hl-4">'event'</span><spanclass="hl-0">));</span><br/><br/><spanclass="hl-3">myEmitter</span><spanclass="hl-0">.</span><spanclass="hl-7">emit</span><spanclass="hl-0">(</span><spanclass="hl-4">'event'</span><spanclass="hl-0">, </span><spanclass="hl-8">1</span><spanclass="hl-0">, </span><spanclass="hl-8">2</span><spanclass="hl-0">, </span><spanclass="hl-8">3</span><spanclass="hl-0">, </span><spanclass="hl-8">4</span><spanclass="hl-0">, </span><spanclass="hl-8">5</span>
</code></pre>
</div></div><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"close"</span></h5></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">boolean</span></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.emit</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#emit">emit</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:432</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"data"</span></h5></li><li><h5>chunk: <spanclass="tsd-signature-type">any</span></h5></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">boolean</span></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.emit</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#emit">emit</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:433</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"end"</span></h5></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">boolean</span></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.emit</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#emit">emit</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:434</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"error"</span></h5></li><li><h5>err: <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.html#Error-1"class="tsd-signature-type"data-tsd-kind="Variable">Error</a></h5></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">boolean</span></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.emit</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#emit">emit</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:435</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"pause"</span></h5></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">boolean</span></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.emit</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#emit">emit</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:436</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"readable"</span></h5></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">boolean</span></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.emit</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#emit">emit</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:437</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"resume"</span></h5></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">boolean</span></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.emit</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#emit">emit</
<p>Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or <code>Symbol</code>s.</p>
</dd></dl></div><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">number</span></h4></li></ul></section><sectionclass="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><aid="isPaused"class="tsd-anchor"></a><h3>is<wbr/>Paused</h3><ulclass="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><liclass="tsd-signature tsd-kind-icon">is<wbr/>Paused<spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">boolean</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><asideclass="tsd-sources"><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#isPaused">isPaused</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:278</li></ul></aside><divclass="tsd-comment tsd-typography"><divclass="lead">
<p>The <code>readable.isPaused()</code> method returns the current operating state of the<code>Readable</code>. This is used primarily by the mechanism that underlies the<code>readable.pipe()</code> method. In most
<p>Adds the <code>listener</code> function to the end of the listeners array for the
event named <code>eventName</code>. No checks are made to see if the <code>listener</code> has
already been added. Multiple calls passing the same combination of <code>eventName</code>and <code>listener</code> will result in the <code>listener</code> being added, and called, multiple
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
<p>By default, event listeners are invoked in the order they are added. The<code>emitter.prependListener()</code> method can be used as an alternative to add the
event listener to the beginning of the listeners array.</p>
</div></div><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"close"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass="tsd-signature tsd-kind-icon"><spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">void</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.on</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#on">on</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:440</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"data"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span>chunk<spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">any</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass="tsd-signature tsd-kind-icon"><spanclass="tsd-signature-symbol">(</span>chunk<spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">any</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">void</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>chunk: <spanclass="tsd-signature-type">any</span></h5></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.on</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#on">on</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:441</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"end"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass="tsd-signat
<p>Adds a <strong>one-time</strong><code>listener</code> function for the event named <code>eventName</code>. The
next time <code>eventName</code> is triggered, this listener is removed and then invoked.</p>
</div><div><pre><codeclass="language-js"><spanclass="hl-3">server</span><spanclass="hl-0">.</span><spanclass="hl-7">once</span><spanclass="hl-0">(</span><spanclass="hl-4">'connection'</span><spanclass="hl-0">, (</span><spanclass="hl-3">stream</span><spanclass="hl-0">) </span><spanclass="hl-2">=></span><spanclass="hl-0"> {</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'Ah, we have our first user!'</span><spanclass="hl-0">);</span><br/><spanclass="hl-0">});</span>
</code></pre>
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
<p>By default, event listeners are invoked in the order they are added. The<code>emitter.prependOnceListener()</code> method can be used as an alternative to add the
event listener to the beginning of the listeners array.</p>
</div></div><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"close"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass="tsd-signature tsd-kind-icon"><spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">void</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.once</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#once">once</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:448</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"data"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span>chunk<spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">any</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass="tsd-signature tsd-kind-icon"><spanclass="tsd-signature-symbol">(</span>chunk<spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">any</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">void</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>chunk: <spanclass="tsd-signature-type">any</span></h5></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.once</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#once">once</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:449</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"end"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass
<p>The <code>readable.pause()</code> method will cause a stream in flowing mode to stop
emitting <code>'data'</code> events, switching out of flowing mode. Any data that
becomes available will remain in the internal buffer.</p>
</div><div><pre><codeclass="language-js"><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">readable</span><spanclass="hl-0"> = </span><spanclass="hl-7">getReadableStreamSomehow</span><spanclass="hl-0">();</span><br/><spanclass="hl-3">readable</span><spanclass="hl-0">.</span><spanclass="hl-7">on</span><spanclass="hl-0">(</span><spanclass="hl-4">'data'</span><spanclass="hl-0">, (</span><spanclass="hl-3">chunk</span><spanclass="hl-0">) </span><spanclass="hl-2">=></span><spanclass="hl-0"> {</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">`Received </span><spanclass="hl-2">${</span><spanclass="hl-3">chunk</span><spanclass="hl-10">.</span><spanclass="hl-3">length</span><spanclass="hl-2">}</span><spanclass="hl-4"> bytes of data.`</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-3">readable</span><spanclass="hl-0">.</span><spanclass="hl-7">pause</span><spanclass="hl-0">();</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'There will be no additional data for 1 second.'</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-7">setTimeout</span><spanclass="hl-0">(() </span><spanclass="hl-2">=></span><spanclass="hl-0"> {</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'Now data will start flowing again.'</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-3">readable</span><spanclass="hl-0">.</span><spanclass="hl-7">resume</span><spanclass="hl-0">();</span><br/><spanclass="hl-0"> }, </span><spanclass="hl-8">1000</span><spanclass="hl-0">);</span><br/><spanclass="hl-0">});</span>
</code></pre>
<p>The <code>readable.pause()</code> method has no effect if there is a <code>'readable'</code>event listener.</p>
<p>Adds the <code>listener</code> function to the <em>beginning</em> of the listeners array for the
event named <code>eventName</code>. No checks are made to see if the <code>listener</code> has
already been added. Multiple calls passing the same combination of <code>eventName</code>and <code>listener</code> will result in the <code>listener</code> being added, and called, multiple
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
</div></div><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"close"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass="tsd-signature tsd-kind-icon"><spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">void</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.prependListener</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#prependListener">prependListener</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:456</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"data"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span>chunk<spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">any</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass="tsd-signature tsd-kind-icon"><spanclass="tsd-signature-symbol">(</span>chunk<spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">any</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">void</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>chunk: <spanclass="tsd-signature-type">any</span></h5></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.prependListener</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#prependListener">prependListener</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:457</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"end"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclas
<p>Adds a <strong>one-time</strong><code>listener</code> function for the event named <code>eventName</code> to the_beginning_ of the listeners array. The next time <code>eventName</code> is triggered, this
listener is removed, and then invoked.</p>
</div><div><pre><codeclass="language-js"><spanclass="hl-3">server</span><spanclass="hl-0">.</span><spanclass="hl-7">prependOnceListener</span><spanclass="hl-0">(</span><spanclass="hl-4">'connection'</span><spanclass="hl-0">, (</span><spanclass="hl-3">stream</span><spanclass="hl-0">) </span><spanclass="hl-2">=></span><spanclass="hl-0"> {</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'Ah, we have our first user!'</span><spanclass="hl-0">);</span><br/><spanclass="hl-0">});</span>
</code></pre>
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
</div></div><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"close"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass="tsd-signature tsd-kind-icon"><spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">void</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.prependOnceListener</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#prependOnceListener">prependOnceListener</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:464</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"data"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span>chunk<spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">any</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass="tsd-signature tsd-kind-icon"><spanclass="tsd-signature-symbol">(</span>chunk<spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">any</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">void</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>chunk: <spanclass="tsd-signature-type">any</span></h5></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.prependOnceListener</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#prependOnceListener">prependOnceListener</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:465</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"end"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-param
<p>Returns a copy of the array of listeners for the event named <code>eventName</code>,
including any wrappers (such as those created by <code>.once()</code>).</p>
</div><div><pre><codeclass="language-js"><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">emitter</span><spanclass="hl-0"> = </span><spanclass="hl-2">new</span><spanclass="hl-0"></span><spanclass="hl-7">EventEmitter</span><spanclass="hl-0">();</span><br/><spanclass="hl-3">emitter</span><spanclass="hl-0">.</span><spanclass="hl-7">once</span><spanclass="hl-0">(</span><spanclass="hl-4">'log'</span><spanclass="hl-0">, () </span><spanclass="hl-2">=></span><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'log once'</span><spanclass="hl-0">));</span><br/><br/><spanclass="hl-5">// Returns a new Array with a function `onceWrapper` which has a property</span><br/><spanclass="hl-5">// `listener` which contains the original listener bound above</span><br/><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">listeners</span><spanclass="hl-0"> = </span><spanclass="hl-3">emitter</span><spanclass="hl-0">.</span><spanclass="hl-7">rawListeners</span><spanclass="hl-0">(</span><spanclass="hl-4">'log'</span><spanclass="hl-0">);</span><br/><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">logFnWrapper</span><spanclass="hl-0"> = </span><spanclass="hl-3">listeners</span><spanclass="hl-0">[</span><spanclass="hl-8">0</span><spanclass="hl-0">];</span><br/><br/><spanclass="hl-5">// Logs "log once" to the console and does not unbind the `once` event</span><br/><spanclass="hl-3">logFnWrapper</span><spanclass="hl-0">.</span><spanclass="hl-7">listener</span><spanclass="hl-0">();</span><br/><br/><spanclass="hl-5">// Logs "log once" to the console and removes the listener</span><br/><spanclass="hl-7">logFnWrapper</span><spanclass="hl-0">();</span><br/><br/><spanclass="hl-3">emitter</span><spanclass="hl-0">.</span><spanclass="hl-7">on</span><spanclass="hl-0">(</span><spanclass="hl-4">'log'</span><spanclass="hl-0">, () </span><spanclass="hl-2">=></span><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'log persistently'</span><spanclass="hl-0">));</span><br/><spanclass="hl-5">// Will return a new Array with a single function bound by `.on()` above</span><br/><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">newListeners</span><spanclass="hl-0"> = </span><spanclass="hl-3">emitter</span><spanclass="hl-0">.</span><spanclass="hl-7">rawListeners</span><spanclass="hl-0">(</span><spanclass="hl-4">'log'</span><spanclass="hl-0">);</span><br/><br/><spanclass="hl-5">// Logs "log persistently" twice</span><br/><spanclass="hl-3">newListeners</span><spanclass="hl-0">[</span><spanclass="hl-8">0</span><spanclass="hl-0">]();</span><br/><spanclass="hl-3">emitter</span><spanclass="hl-0">.</span><spanclass="hl-7">emit</span><spanclass="hl-0">(</span><spanclass="hl-4">'log'</span><spanclass="hl-0">);</span>
<p>The <code>readable.read()</code> method pulls some data out of the internal buffer and
returns it. If no data available to be read, <code>null</code> is returned. By default,
the data will be returned as a <code>Buffer</code> object unless an encoding has been
specified using the <code>readable.setEncoding()</code> method or the stream is operating
in object mode.</p>
</div><div><p>The optional <code>size</code> argument specifies a specific number of bytes to read. If<code>size</code> bytes are not available to be read, <code>null</code> will be returned _unless_the stream has ended, in which
case all of the data remaining in the internal
buffer will be returned.</p>
<p>If the <code>size</code> argument is not specified, all of the data contained in the
internal buffer will be returned.</p>
<p>The <code>size</code> argument must be less than or equal to 1 GiB.</p>
<p>The <code>readable.read()</code> method should only be called on <code>Readable</code> streams
operating in paused mode. In flowing mode, <code>readable.read()</code> is called
automatically until the internal buffer is fully drained.</p>
<pre><codeclass="language-js"><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">readable</span><spanclass="hl-0"> = </span><spanclass="hl-7">getReadableStreamSomehow</span><spanclass="hl-0">();</span><br/><br/><spanclass="hl-5">// 'readable' may be triggered multiple times as data is buffered in</span><br/><spanclass="hl-3">readable</span><spanclass="hl-0">.</span><spanclass="hl-7">on</span><spanclass="hl-0">(</span><spanclass="hl-4">'readable'</span><spanclass="hl-0">, () </span><spanclass="hl-2">=></span><spanclass="hl-0"> {</span><br/><spanclass="hl-0"></span><spanclass="hl-2">let</span><spanclass="hl-0"></span><spanclass="hl-3">chunk</span><spanclass="hl-0">;</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'Stream is readable (new data received in buffer)'</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-5">// Use a loop to make sure we read all currently available data</span><br/><spanclass="hl-0"></span><spanclass="hl-1">while</span><spanclass="hl-0"> (</span><spanclass="hl-2">null</span><spanclass="hl-0"> !== (</span><spanclass="hl-3">chunk</span><spanclass="hl-0"> = </span><spanclass="hl-3">readable</span><spanclass="hl-0">.</span><spanclass="hl-7">read</span><spanclass="hl-0">())) {</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">`Read </span><spanclass="hl-2">${</span><spanclass="hl-3">chunk</span><spanclass="hl-10">.</span><spanclass="hl-3">length</span><spanclass="hl-2">}</span><spanclass="hl-4"> bytes of data...`</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"> }</span><br/><spanclass="hl-0">});</span><br/><br/><spanclass="hl-5">// 'end' will be triggered once when there is no more data available</span><br/><spanclass="hl-3">readable</span><spanclass="hl-0">.</span><spanclass="hl-7">on</span><spanclass="hl-0">(</span><spanclass="hl-4">'end'</span><spanclass="hl-0">, () </span><spanclass="hl-2">=></span><spanclass="hl-0"> {</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'Reached end of stream.'</span><spanclass="hl-0">);</span><br/><spanclass="hl-0">});</span>
</code></pre>
<p>Each call to <code>readable.read()</code> returns a chunk of data, or <code>null</code>. The chunks
are not concatenated. A <code>while</code> loop is necessary to consume all data
currently in the buffer. When reading a large file <code>.read()</code> may return <code>null</code>,
having consumed all buffered content so far, but there is still more data to
come not yet buffered. In this case a new <code>'readable'</code> event will be emitted
when there is more data in the buffer. Finally the <code>'end'</code> event will be
emitted when there is no more data to come.</p>
<p>Therefore to read a file's whole contents from a <code>readable</code>, it is necessary
to collect chunks across multiple <code>'readable'</code> events:</p>
<p><code>removeListener()</code> will remove, at most, one instance of a listener from the
listener array. If any single listener has been added multiple times to the
listener array for the specified <code>eventName</code>, then <code>removeListener()</code> must be
called multiple times to remove each instance.</p>
<p>Once an event is emitted, all listeners attached to it at the
time of emitting are called in order. This implies that any<code>removeListener()</code> or <code>removeAllListeners()</code> calls <em>after</em> emitting and_before_ the last listener finishes execution will
not remove them from<code>emit()</code> in progress. Subsequent events behave as expected.</p>
<pre><codeclass="language-js"><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">myEmitter</span><spanclass="hl-0"> = </span><spanclass="hl-2">new</span><spanclass="hl-0"></span><spanclass="hl-7">MyEmitter</span><spanclass="hl-0">();</span><br/><br/><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-7">callbackA</span><spanclass="hl-0"> = () </span><spanclass="hl-2">=></span><spanclass="hl-0"> {</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'A'</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-3">myEmitter</span><spanclass="hl-0">.</span><spanclass="hl-7">removeListener</span><spanclass="hl-0">(</span><spanclass="hl-4">'event'</span><spanclass="hl-0">, </span><spanclass="hl-3">callbackB</span><spanclass="hl-0">);</span><br/><spanclass="hl-0">};</span><br/><br/><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-7">callbackB</span><spanclass="hl-0"> = () </span><spanclass="hl-2">=></span><spanclass="hl-0"> {</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'B'</span><spanclass="hl-0">);</span><br/><spanclass="hl-0">};</span><br/><br/><spanclass="hl-3">myEmitter</span><spanclass="hl-0">.</span><spanclass="hl-7">on</span><spanclass="hl-0">(</span><spanclass="hl-4">'event'</span><spanclass="hl-0">, </span><spanclass="hl-3">callbackA</span><spanclass="hl-0">);</span><br/><br/><spanclass="hl-3">myEmitter</span><spanclass="hl-0">.</span><spanclass="hl-7">on</span><spanclass="hl-0">(</span><spanclass="hl-4">'event'</span><spanclass="hl-0">, </span><spanclass="hl-3">callbackB</span><spanclass="hl-0">);</span><br/><br/><spanclass="hl-5">// callbackA removes listener callbackB but it will still be called.</span><br/><spanclass="hl-5">// Internal listener array at time of emit [callbackA, callbackB]</span><br/><spanclass="hl-3">myEmitter</span><spanclass="hl-0">.</span><spanclass="hl-7">emit</span><spanclass="hl-0">(</span><spanclass="hl-4">'event'</span><spanclass="hl-0">);</span><br/><spanclass="hl-5">// Prints:</span><br/><spanclass="hl-5">// A</span><br/><spanclass="hl-5">// B</span><br/><br/><spanclass="hl-5">// callbackB is now removed.</span><br/><spanclass="hl-5">// Internal listener array [callbackA]</span><br/><spanclass="hl-3">myEmitter</span><spanclass="hl-0">.</span><spanclass="hl-7">emit</span><spanclass="hl-0">(</span><spanclass="hl-4">'event'</span><spanclass="hl-0">);</span><br/><spanclass="hl-5">// Prints:</span><br/><spanclass="hl-5">// A</span>
</code></pre>
<p>Because listeners are managed using an internal array, calling this will
change the position indices of any listener registered <em>after</em> the listener
being removed. This will not impact the order in which listeners are called,
but it means that any copies of the listener array as returned by
the <code>emitter.listeners()</code> method will need to be recreated.</p>
<p>When a single function has been added as a handler multiple times for a single
event (as in the example below), <code>removeListener()</code> will remove the most
recently added instance. In the example the <code>once('ping')</code>listener is removed:</p>
<p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
</div></div><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"close"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass="tsd-signature tsd-kind-icon"><spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">void</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.removeListener</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#removeListener">removeListener</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:472</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"data"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span>chunk<spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">any</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd-signatures tsd-kind-type-literal tsd-is-external"><liclass="tsd-signature tsd-kind-icon"><spanclass="tsd-signature-symbol">(</span>chunk<spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">any</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">void</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>chunk: <spanclass="tsd-signature-type">any</span></h5></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.removeListener</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#removeListener">removeListener</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:473</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>event: <spanclass="tsd-signature-type">"end"</span></h5></li><li><h5>listener: <spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol"> =></span><spanclass="tsd-signature-type">void</span></h5><ulclass="tsd-parameters"><liclass="tsd-parameter-signature"><ulclass="tsd
<p>The <code>readable.resume()</code> method causes an explicitly paused <code>Readable</code> stream to
resume emitting <code>'data'</code> events, switching the stream into flowing mode.</p>
</div><div><p>The <code>readable.resume()</code> method can be used to fully consume the data from a
stream without actually processing any of that data:</p>
<pre><codeclass="language-js"><spanclass="hl-7">getReadableStreamSomehow</span><spanclass="hl-0">()</span><br/><spanclass="hl-0"> .</span><spanclass="hl-7">resume</span><spanclass="hl-0">()</span><br/><spanclass="hl-0"> .</span><spanclass="hl-7">on</span><spanclass="hl-0">(</span><spanclass="hl-4">'end'</span><spanclass="hl-0">, () </span><spanclass="hl-2">=></span><spanclass="hl-0"> {</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'Reached the end, but did not read anything.'</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"> });</span>
</code></pre>
<p>The <code>readable.resume()</code> method has no effect if there is a <code>'readable'</code>event listener.</p>
</dd></dl></div><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li></ul></section><sectionclass="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external"><aid="setDefaultEncoding"class="tsd-anchor"></a><h3>set<wbr/>Default<wbr/>Encoding</h3><ulclass="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external"><liclass="tsd-signature tsd-kind-icon">set<wbr/>Default<wbr/>Encoding<spanclass="tsd-signature-symbol">(</span>encoding<spanclass="tsd-signature-symbol">: </span><ahref="../modules/_internal_.html#BufferEncoding"class="tsd-signature-type"data-tsd-kind="Type alias">BufferEncoding</a><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.setDefaultEncoding</p><ul><li>Defined in node_modules/@types/node/stream.d.ts:855</li></ul></aside><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>encoding: <ahref="../modules/_internal_.html#BufferEncoding"class="tsd-signature-type"data-tsd-kind="Type alias">BufferEncoding</a></h5></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li></ul></section><sectionclass="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><aid="setEncoding"class="tsd-anchor"></a><h3>set<wbr/>Encoding</h3><ulclass="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><liclass="tsd-signature tsd-kind-icon">set<wbr/>Encoding<spanclass="tsd-signature-symbol">(</span>encoding<spanclass="tsd-signature-symbol">: </span><ahref="../modules/_internal_.html#BufferEncoding"class="tsd-signature-type"data-tsd-kind="Type alias">BufferEncoding</a><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><asideclass="tsd-sources"><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#setEncoding">setEncoding</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:220</li></ul></aside><divclass="tsd-comment tsd-typography"><divclass="lead">
<p>The <code>readable.setEncoding()</code> method sets the character encoding for
data read from the <code>Readable</code> stream.</p>
</div><div><p>By default, no encoding is assigned and stream data will be returned as<code>Buffer</code> objects. Setting an encoding causes the stream data
to be returned as strings of the specified encoding rather than as <code>Buffer</code>objects. For instance, calling <code>readable.setEncoding('utf8')</code> will cause the
output data to be interpreted as UTF-8 data, and passed as strings. Calling<code>readable.setEncoding('hex')</code> will cause the data to be encoded in hexadecimal
string format.</p>
<p>The <code>Readable</code> stream will properly handle multi-byte characters delivered
through the stream that would otherwise become improperly decoded if simply
pulled from the stream as <code>Buffer</code> objects.</p>
</div></div></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li></ul></section><sectionclass="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><aid="setMaxListeners"class="tsd-anchor"></a><h3>set<wbr/>Max<wbr/>Listeners</h3><ulclass="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><liclass="tsd-signature tsd-kind-icon">set<wbr/>Max<wbr/>Listeners<spanclass="tsd-signature-symbol">(</span>n<spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">number</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.setMaxListeners</p><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#setMaxListeners">setMaxListeners</a></p><ul><li>Defined in node_modules/@types/node/events.d.ts:465</li></ul></aside><divclass="tsd-comment tsd-typography"><divclass="lead">
<p>By default <code>EventEmitter</code>s will print a warning if more than <code>10</code> listeners are
added for a particular event. This is a useful default that helps finding
memory leaks. The <code>emitter.setMaxListeners()</code> method allows the limit to be
modified for this specific <code>EventEmitter</code> instance. The value can be set to<code>Infinity</code> (or <code>0</code>) to indicate an unlimited number of listeners.</p>
</div><div><p>Returns a reference to the <code>EventEmitter</code>, so that calls can be chained.</p>
</dd></dl></div><h4class="tsd-parameters-title">Parameters</h4><ulclass="tsd-parameters"><li><h5>n: <spanclass="tsd-signature-type">number</span></h5></li></ul><h4class="tsd-returns-title">Returns <ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></h4></li></ul></section><sectionclass="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-external"><aid="uncork"class="tsd-anchor"></a><h3>uncork</h3><ulclass="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-external"><liclass="tsd-signature tsd-kind-icon">uncork<spanclass="tsd-signature-symbol">(</span><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><spanclass="tsd-signature-type">void</span></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><asideclass="tsd-sources"><p>Implementation of Writable.uncork</p><ul><li>Defined in node_modules/@types/node/stream.d.ts:860</li></ul></aside><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></section><sectionclass="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><aid="unpipe"class="tsd-anchor"></a><h3>unpipe</h3><ulclass="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><liclass="tsd-signature tsd-kind-icon">unpipe<spanclass="tsd-signature-symbol">(</span>destination<spanclass="tsd-signature-symbol">?: </span><ahref="../interfaces/_internal_.WritableStream.html"class="tsd-signature-type"data-tsd-kind="Interface">WritableStream</a><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><asideclass="tsd-sources"><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#unpipe">unpipe</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:305</li></ul></aside><divclass="tsd-comment tsd-typography"><divclass="lead">
<p>The <code>readable.unpipe()</code> method detaches a <code>Writable</code> stream previously attached
using the <ahref="_internal_.Duplex.html#pipe">pipe</a> method.</p>
</div><div><p>If the <code>destination</code> is not specified, then <em>all</em> pipes are detached.</p>
<p>If the <code>destination</code> is specified, but no pipe is set up for it, then
the method does nothing.</p>
<pre><codeclass="language-js"><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">fs</span><spanclass="hl-0"> = </span><spanclass="hl-7">require</span><spanclass="hl-0">(</span><spanclass="hl-4">'fs'</span><spanclass="hl-0">);</span><br/><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">readable</span><spanclass="hl-0"> = </span><spanclass="hl-7">getReadableStreamSomehow</span><spanclass="hl-0">();</span><br/><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">writable</span><spanclass="hl-0"> = </span><spanclass="hl-3">fs</span><spanclass="hl-0">.</span><spanclass="hl-7">createWriteStream</span><spanclass="hl-0">(</span><spanclass="hl-4">'file.txt'</span><spanclass="hl-0">);</span><br/><spanclass="hl-5">// All the data from readable goes into 'file.txt',</span><br/><spanclass="hl-5">// but only for the first second.</span><br/><spanclass="hl-3">readable</span><spanclass="hl-0">.</span><spanclass="hl-7">pipe</span><spanclass="hl-0">(</span><spanclass="hl-3">writable</span><spanclass="hl-0">);</span><br/><spanclass="hl-7">setTimeout</span><spanclass="hl-0">(() </span><spanclass="hl-2">=></span><spanclass="hl-0"> {</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'Stop writing to file.txt.'</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-3">readable</span><spanclass="hl-0">.</span><spanclass="hl-7">unpipe</span><spanclass="hl-0">(</span><spanclass="hl-3">writable</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-3">console</span><spanclass="hl-0">.</span><spanclass="hl-7">log</span><spanclass="hl-0">(</span><spanclass="hl-4">'Manually close the file stream.'</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-3">writable</span><spanclass="hl-0">.</span><spanclass="hl-7">end</span><spanclass="hl-0">();</span><br/><spanclass="hl-0">}, </span><spanclass="hl-8">1000</span><spanclass="hl-0">);</span>
<p>Passing <code>chunk</code> as <code>null</code> signals the end of the stream (EOF) and behaves the
same as <code>readable.push(null)</code>, after which no more data can be written. The EOF
signal is put at the end of the buffer and any buffered data will still be
flushed.</p>
</div><div><p>The <code>readable.unshift()</code> method pushes a chunk of data back into the internal
buffer. This is useful in certain situations where a stream is being consumed by
code that needs to "un-consume" some amount of data that it has optimistically
pulled out of the source, so that the data can be passed on to some other party.</p>
<p>The <code>stream.unshift(chunk)</code> method cannot be called after the <code>'end'</code> event
has been emitted or a runtime error will be thrown.</p>
<p>Developers using <code>stream.unshift()</code> often should consider switching to
use of a <code>Transform</code> stream instead. See the <code>API for stream implementers</code> section for more information.</p>
<pre><codeclass="language-js"><spanclass="hl-5">// Pull off a header delimited by \n\n.</span><br/><spanclass="hl-5">// Use unshift() if we get too much.</span><br/><spanclass="hl-5">// Call the callback with (error, header, stream).</span><br/><spanclass="hl-2">const</span><spanclass="hl-0"> { </span><spanclass="hl-6">StringDecoder</span><spanclass="hl-0"> } = </span><spanclass="hl-7">require</span><spanclass="hl-0">(</span><spanclass="hl-4">'string_decoder'</span><spanclass="hl-0">);</span><br/><spanclass="hl-2">function</span><spanclass="hl-0"></span><spanclass="hl-7">parseHeader</span><spanclass="hl-0">(</span><spanclass="hl-3">stream</span><spanclass="hl-0">, </span><spanclass="hl-3">callback</span><spanclass="hl-0">) {</span><br/><spanclass="hl-0"></span><spanclass="hl-3">stream</span><spanclass="hl-0">.</span><spanclass="hl-7">on</span><spanclass="hl-0">(</span><spanclass="hl-4">'error'</span><spanclass="hl-0">, </span><spanclass="hl-3">callback</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-3">stream</span><spanclass="hl-0">.</span><spanclass="hl-7">on</span><spanclass="hl-0">(</span><spanclass="hl-4">'readable'</span><spanclass="hl-0">, </span><spanclass="hl-3">onReadable</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">decoder</span><spanclass="hl-0"> = </span><spanclass="hl-2">new</span><spanclass="hl-0"></span><spanclass="hl-7">StringDecoder</span><spanclass="hl-0">(</span><spanclass="hl-4">'utf8'</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-2">let</span><spanclass="hl-0"></span><spanclass="hl-3">header</span><spanclass="hl-0"> = </span><spanclass="hl-4">''</span><spanclass="hl-0">;</span><br/><spanclass="hl-0"></span><spanclass="hl-2">function</span><spanclass="hl-0"></span><spanclass="hl-7">onReadable</span><spanclass="hl-0">() {</span><br/><spanclass="hl-0"></span><spanclass="hl-2">let</span><spanclass="hl-0"></span><spanclass="hl-3">chunk</span><spanclass="hl-0">;</span><br/><spanclass="hl-0"></span><spanclass="hl-1">while</span><spanclass="hl-0"> (</span><spanclass="hl-2">null</span><spanclass="hl-0"> !== (</span><spanclass="hl-3">chunk</span><spanclass="hl-0"> = </span><spanclass="hl-3">stream</span><spanclass="hl-0">.</span><spanclass="hl-7">read</span><spanclass="hl-0">())) {</span><br/><spanclass="hl-0"></span><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">str</span><spanclass="hl-0"> = </span><spanclass="hl-3">decoder</span><spanclass="hl-0">.</span><spanclass="hl-7">write</span><spanclass="hl-0">(</span><spanclass="hl-3">chunk</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-1">if</span><spanclass="hl-0"> (</span><spanclass="hl-3">str</span><spanclass="hl-0">.</span><spanclass="hl-7">match</span><spanclass="hl-0">(</span><spanclass="hl-11">/\n\n/</span><spanclass="hl-0">)) {</span><br/><spanclass="hl-0"></span><spanclass="hl-5">// Found the header boundary.</span><br/><spanclass="hl-0"></span><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">split</span><spanclass="hl-0"> = </span><spanclass="hl-3">str</span><spanclass="hl-0">.</span><spanclass="hl-7">split</span><spanclass="hl-0">(</span><spanclass="hl-11">/\n\n/</span><spanclass="hl-0">);</span><br/><spanclass="hl-0"></span><spanclass="hl-3">header</span><spanclass="hl-0"> += </span><spanclass="hl-3">split</span><spanclass="hl-0">.</span><spanclass="hl-7">shift</span><spanclass="hl-0">();</span><br/><spanclass="hl-0"></span><spanclass="hl-2">const</span><spanclass="hl-0"></span><spanclass="hl-6">remaining</span><spanclass="hl-0"> = </span><spanclass="hl-3">split</span><spanclass="hl-0">.</span><spanclass="hl-7">join</span><spanclass="hl-0">(</span><spanclass="hl-4">'</span><spanclas
</code></pre>
<p>Unlike <ahref="_internal_.Duplex.html#push">push</a>, <code>stream.unshift(chunk)</code> will not
end the reading process by resetting the internal reading state of the stream.
This can cause unexpected results if <code>readable.unshift()</code> is called during a
read (i.e. from within a <ahref="_internal_.Duplex.html#_read">_read</a> implementation on a
custom stream). Following the call to <code>readable.unshift()</code> with an immediate <ahref="_internal_.Duplex.html#push">push</a> will reset the reading state appropriately,
however it is best to simply avoid calling <code>readable.unshift()</code> while in the
<p>Chunk of data to unshift onto the read queue. For streams not operating in object mode, <code>chunk</code> must be a string, <code>Buffer</code>, <code>Uint8Array</code> or <code>null</code>. For object mode
streams, <code>chunk</code> may be any JavaScript value.</p>
<p>Encoding of string chunks. Must be a valid <code>Buffer</code> encoding, such as <code>'utf8'</code> or <code>'ascii'</code>.</p>
</div></div></li></ul><h4class="tsd-returns-title">Returns <spanclass="tsd-signature-type">void</span></h4></li></ul></section><sectionclass="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><aid="wrap"class="tsd-anchor"></a><h3>wrap</h3><ulclass="tsd-signatures tsd-kind-method tsd-parent-kind-class tsd-is-inherited tsd-is-external"><liclass="tsd-signature tsd-kind-icon">wrap<spanclass="tsd-signature-symbol">(</span>stream<spanclass="tsd-signature-symbol">: </span><ahref="../interfaces/_internal_.ReadableStream.html"class="tsd-signature-type"data-tsd-kind="Interface">ReadableStream</a><spanclass="tsd-signature-symbol">)</span><spanclass="tsd-signature-symbol">: </span><ahref="../modules/_internal_.html"class="tsd-signature-type"data-tsd-kind="Namespace"><internal></a><spanclass="tsd-signature-symbol">.</span><ahref="../modules/_internal_.internal.html"class="tsd-signature-type"data-tsd-kind="Namespace">internal</a><spanclass="tsd-signature-symbol">.</span><ahref="_internal_.internal.Duplex.html"class="tsd-signature-type"data-tsd-kind="Class">Duplex</a></li></ul><ulclass="tsd-descriptions"><liclass="tsd-description"><asideclass="tsd-sources"><p>Inherited from <ahref="_internal_.Readable.html">Readable</a>.<ahref="_internal_.Readable.html#wrap">wrap</a></p><ul><li>Defined in node_modules/@types/node/stream.d.ts:397</li></ul></aside><divclass="tsd-comment tsd-typography"><divclass="lead">
<p>Prior to Node.js 0.10, streams did not implement the entire <code>stream</code> module API
as it is currently defined. (See <code>Compatibility</code> for more information.)</p>
</div><div><p>When using an older Node.js library that emits <code>'data'</code> events and has a <ahref="_internal_.Duplex.html#pause">pause</a> method that is advisory only, the<code>readable.wrap()</code> method can be used to create a <code>Readable</code>
stream that uses
the old stream as its data source.</p>
<p>It will rarely be necessary to use <code>readable.wrap()</code> but the method has been
provided as a convenience for interacting with older Node.js applications and
const { on, EventEmitter } = require('events');</p>
</div><div><p>(async () => {
const ee = new EventEmitter();</p>
<p> // Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});</p>
<p> for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();</p>
<pre><code><br/><spanclass="hl-3">Returns</span><spanclass="hl-0"></span><spanclass="hl-3">an</span><spanclass="hl-0"></span><spanclass="hl-4">`AsyncIterator`</span><spanclass="hl-0"></span><spanclass="hl-3">that</span><spanclass="hl-0"></span><spanclass="hl-3">iterates</span><spanclass="hl-0"></span><spanclass="hl-4">`eventName`</span><spanclass="hl-0"></span><spanclass="hl-3">events</span><spanclass="hl-0">. </span><spanclass="hl-3">It</span><spanclass="hl-0"></span><spanclass="hl-3">will</span><spanclass="hl-0"></span><spanclass="hl-1">throw</span><br/><spanclass="hl-1">if</span><spanclass="hl-0"></span><spanclass="hl-3">the</span><spanclass="hl-0"></span><spanclass="hl-4">`EventEmitter`</span><spanclass="hl-0"></span><spanclass="hl-3">emits</span><spanclass="hl-0"></span><spanclass="hl-4">`'error'`</span><spanclass="hl-0">. </span><spanclass="hl-3">It</span><spanclass="hl-0"></span><spanclass="hl-3">removes</span><spanclass="hl-0"></span><spanclass="hl-3">all</span><spanclass="hl-0"></span><spanclass="hl-3">listeners</span><spanclass="hl-0"></span><spanclass="hl-3">when</span><br/><spanclass="hl-3">exiting</span><spanclass="hl-0"></span><spanclass="hl-3">the</span><spanclass="hl-0"></span><spanclass="hl-3">loop</span><spanclass="hl-0">. </span><spanclass="hl-3">The</span><spanclass="hl-0"></span><spanclass="hl-4">`value`</span><spanclass="hl-0"></span><spanclass="hl-3">returned</span><spanclass="hl-0"></span><spanclass="hl-3">by</span><spanclass="hl-0"></span><spanclass="hl-3">each</span><spanclass="hl-0"></span><spanclass="hl-3">iteration</span><spanclass="hl-0"></span><spanclass="hl-3">is</span><spanclass="hl-0"></span><spanclass="hl-3">an</span><spanclass="hl-0"></span><spanclass="hl-3">array</span><br/><spanclass="hl-3">composed</span><spanclass="hl-0"></span><spanclass="hl-2">of</span><spanclass="hl-0"></span><spanclass="hl-3">the</span><spanclass="hl-0"></span><spanclass="hl-3">emitted</span><spanclass="hl-0"></span><spanclass="hl-3">event</span><spanclass="hl-0"></span><spanclass="hl-2">arguments</span><spanclass="hl-0">.</span><br/><br/><spanclass="hl-3">An</span><spanclass="hl-0"></span><spanclass="hl-4">`AbortSignal`</span><spanclass="hl-0"></span><spanclass="hl-3">can</span><spanclass="hl-0"></span><spanclass="hl-3">be</span><spanclass="hl-0"></span><spanclass="hl-3">used</span><spanclass="hl-0"></span><spanclass="hl-3">to</span><spanclass="hl-0"></span><spanclass="hl-3">cancel</span><spanclass="hl-0"></span><spanclass="hl-3">waiting</span><spanclass="hl-0"></span><spanclass="hl-3">on</span><spanclass="hl-0"></span><spanclass="hl-13">events</span><spanclass="hl-0">:</span><br/><br/><spanclass="hl-4">```js</span><br/><spanclass="hl-4">const { on, EventEmitter } = require('events');</span><br/><spanclass="hl-4">const ac = new AbortController();</span><br/><br/><spanclass="hl-4">(async () => {</span><br/><spanclass="hl-4"> const ee = new EventEmitter();</span><br/><br/><spanclass="hl-4"> // Emit later on</span><br/><spanclass="hl-4"> process.nextTick(() => {</span><br/><spanclass="hl-4"> ee.emit('foo', 'bar');</span><br/><spanclass="hl-4"> ee.emit('foo', 42);</span><br/><spanclass="hl-4"> });</span><br/><br/><spanclass="hl-4"> for await (const event of on(ee, 'foo', { signal: ac.signal })) {</span><br/><spanclass="hl-4"> // The execution of this inner block is synchronous and it</span><br/><spanclass="hl-4"> // processes one event at a time (even with await). Do not use</span><br/><spanclass="hl-4"> // if concurrent execution is required.</span><br/><spanclass="hl-4"> console.log(event); // prints ['bar'] [42]</span><br/><spanclass="hl-4"> }</span><br/><spanclass="hl-4"> // Unreachable here</span><br/><spanclass="hl-4">})();</span><br/><br/><spanclass="hl-4">process.nextTick(() => ac.abort());</span>
<p>Creates a <code>Promise</code> that is fulfilled when the <code>EventEmitter</code> emits the given
event or that is rejected if the <code>EventEmitter</code> emits <code>'error'</code> while waiting.
The <code>Promise</code> will resolve with an array of all the arguments emitted to the
given event.</p>
</div><div><p>This method is intentionally generic and works with the web platform <ahref="https://dom.spec.whatwg.org/#interface-eventtarget">EventTarget</a> interface, which has no special<code>'error'</code> event
semantics and does not listen to the <code>'error'</code> event.</p>
<p>The special handling of the <code>'error'</code> event is only used when <code>events.once()</code>is used to wait for another event. If <code>events.once()</code> is used to wait for the
'<code>error'</code> event itself, then it is treated as any other kind of event without