{
  "source": "doc/api/stream.markdown",
  "modules": [
    {
      "textRaw": "Stream",
      "name": "stream",
      "stability": 2,
      "stabilityText": "Unstable",
      "desc": "<p>A stream is an abstract interface implemented by various objects in Node.\nFor example a request to an HTTP server is a stream, as is stdout. Streams\nare readable, writable, or both. All streams are instances of <code>EventEmitter</code>.\n\n</p>\n<p>You can load up the Stream base class by doing <code>require(&apos;stream&apos;)</code>.\n\n</p>\n",
      "classes": [
        {
          "textRaw": "Readable Stream",
          "name": "Readable Stream",
          "type": "class",
          "desc": "<p>A <code>Readable Stream</code> has the following methods, members, and events.\n\n</p>\n",
          "events": [
            {
              "textRaw": "Event: 'data'",
              "type": "event",
              "name": "data",
              "desc": "<p><code>function (data) { }</code>\n\n</p>\n<p>The <code>&apos;data&apos;</code> event emits either a <code>Buffer</code> (by default) or a string if\n<code>setEncoding()</code> was used.\n\n</p>\n<p>Note that the <strong>data will be lost</strong> if there is no listener when a\n<code>Readable Stream</code> emits a <code>&apos;data&apos;</code> event.\n\n</p>\n",
              "params": []
            },
            {
              "textRaw": "Event: 'end'",
              "type": "event",
              "name": "end",
              "desc": "<p><code>function () { }</code>\n\n</p>\n<p>Emitted when the stream has received an EOF (FIN in TCP terminology).\nIndicates that no more <code>&apos;data&apos;</code> events will happen. If the stream is also\nwritable, it may be possible to continue writing.\n\n</p>\n",
              "params": []
            },
            {
              "textRaw": "Event: 'error'",
              "type": "event",
              "name": "error",
              "desc": "<p><code>function (exception) { }</code>\n\n</p>\n<p>Emitted if there was an error receiving data.\n\n</p>\n",
              "params": []
            },
            {
              "textRaw": "Event: 'close'",
              "type": "event",
              "name": "close",
              "desc": "<p><code>function () { }</code>\n\n</p>\n<p>Emitted when the underlying file descriptor has been closed. Not all streams\nwill emit this.  (For example, an incoming HTTP request will not emit\n<code>&apos;close&apos;</code>.)\n\n</p>\n",
              "params": []
            }
          ],
          "properties": [
            {
              "textRaw": "stream.readable",
              "name": "readable",
              "desc": "<p>A boolean that is <code>true</code> by default, but turns <code>false</code> after an <code>&apos;error&apos;</code>\noccurred, the stream came to an <code>&apos;end&apos;</code>, or <code>destroy()</code> was called.\n\n</p>\n"
            }
          ],
          "methods": [
            {
              "textRaw": "stream.setEncoding(encoding)",
              "type": "method",
              "name": "setEncoding",
              "desc": "<p>Makes the data event emit a string instead of a <code>Buffer</code>. <code>encoding</code> can be\n<code>&apos;utf8&apos;</code>, <code>&apos;ascii&apos;</code>, or <code>&apos;base64&apos;</code>.\n\n</p>\n",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "encoding"
                    }
                  ]
                }
              ]
            },
            {
              "textRaw": "stream.pause()",
              "type": "method",
              "name": "pause",
              "desc": "<p>Pauses the incoming <code>&apos;data&apos;</code> events.\n\n</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            },
            {
              "textRaw": "stream.resume()",
              "type": "method",
              "name": "resume",
              "desc": "<p>Resumes the incoming <code>&apos;data&apos;</code> events after a <code>pause()</code>.\n\n</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            },
            {
              "textRaw": "stream.destroy()",
              "type": "method",
              "name": "destroy",
              "desc": "<p>Closes the underlying file descriptor. Stream will not emit any more events.\n\n\n</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            },
            {
              "textRaw": "stream.destroySoon()",
              "type": "method",
              "name": "destroySoon",
              "desc": "<p>After the write queue is drained, close the file descriptor.\n\n</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            },
            {
              "textRaw": "stream.pipe(destination, [options])",
              "type": "method",
              "name": "pipe",
              "desc": "<p>This is a <code>Stream.prototype</code> method available on all <code>Stream</code>s.\n\n</p>\n<p>Connects this read stream to <code>destination</code> WriteStream. Incoming\ndata on this stream gets written to <code>destination</code>. The destination and source\nstreams are kept in sync by pausing and resuming as necessary.\n\n</p>\n<p>This function returns the <code>destination</code> stream.\n\n</p>\n<p>Emulating the Unix <code>cat</code> command:\n\n</p>\n<pre><code>process.stdin.resume();\nprocess.stdin.pipe(process.stdout);</code></pre>\n<p>By default <code>end()</code> is called on the destination when the source stream emits\n<code>end</code>, so that <code>destination</code> is no longer writable. Pass <code>{ end: false }</code> as\n<code>options</code> to keep the destination stream open.\n\n</p>\n<p>This keeps <code>process.stdout</code> open so that &quot;Goodbye&quot; can be written at the end.\n\n</p>\n<pre><code>process.stdin.resume();\n\nprocess.stdin.pipe(process.stdout, { end: false });\n\nprocess.stdin.on(&quot;end&quot;, function() {\n  process.stdout.write(&quot;Goodbye\\n&quot;);\n});</code></pre>\n",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "destination"
                    },
                    {
                      "name": "options",
                      "optional": true
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "textRaw": "Writable Stream",
          "name": "Writable Stream",
          "type": "class",
          "desc": "<p>A <code>Writable Stream</code> has the following methods, members, and events.\n\n</p>\n",
          "events": [
            {
              "textRaw": "Event: 'drain'",
              "type": "event",
              "name": "drain",
              "desc": "<p><code>function () { }</code>\n\n</p>\n<p>After a <code>write()</code> method returned <code>false</code>, this event is emitted to\nindicate that it is safe to write again.\n\n</p>\n",
              "params": []
            },
            {
              "textRaw": "Event: 'error'",
              "type": "event",
              "name": "error",
              "desc": "<p><code>function (exception) { }</code>\n\n</p>\n<p>Emitted on error with the exception <code>exception</code>.\n\n</p>\n",
              "params": []
            },
            {
              "textRaw": "Event: 'close'",
              "type": "event",
              "name": "close",
              "desc": "<p><code>function () { }</code>\n\n</p>\n<p>Emitted when the underlying file descriptor has been closed.\n\n</p>\n",
              "params": []
            },
            {
              "textRaw": "Event: 'pipe'",
              "type": "event",
              "name": "pipe",
              "desc": "<p><code>function (src) { }</code>\n\n</p>\n<p>Emitted when the stream is passed to a readable stream&apos;s pipe method.\n\n</p>\n",
              "params": []
            }
          ],
          "properties": [
            {
              "textRaw": "stream.writable",
              "name": "writable",
              "desc": "<p>A boolean that is <code>true</code> by default, but turns <code>false</code> after an <code>&apos;error&apos;</code>\noccurred or <code>end()</code> / <code>destroy()</code> was called.\n\n</p>\n"
            }
          ],
          "methods": [
            {
              "textRaw": "stream.write(string, [encoding], [fd])",
              "type": "method",
              "name": "write",
              "desc": "<p>Writes <code>string</code> with the given <code>encoding</code> to the stream.  Returns <code>true</code> if\nthe string has been flushed to the kernel buffer.  Returns <code>false</code> to\nindicate that the kernel buffer is full, and the data will be sent out in\nthe future. The <code>&apos;drain&apos;</code> event will indicate when the kernel buffer is\nempty again. The <code>encoding</code> defaults to <code>&apos;utf8&apos;</code>.\n\n</p>\n<p>If the optional <code>fd</code> parameter is specified, it is interpreted as an integral\nfile descriptor to be sent over the stream. This is only supported for UNIX\nstreams, and is silently ignored otherwise. When writing a file descriptor in\nthis manner, closing the descriptor before the stream drains risks sending an\ninvalid (closed) FD.\n\n</p>\n",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "string"
                    },
                    {
                      "name": "encoding",
                      "optional": true
                    },
                    {
                      "name": "fd",
                      "optional": true
                    }
                  ]
                }
              ]
            },
            {
              "textRaw": "stream.write(buffer)",
              "type": "method",
              "name": "write",
              "desc": "<p>Same as the above except with a raw buffer.\n\n</p>\n",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "buffer"
                    }
                  ]
                }
              ]
            },
            {
              "textRaw": "stream.end()",
              "type": "method",
              "name": "end",
              "desc": "<p>Terminates the stream with EOF or FIN.\nThis call will allow queued write data to be sent before closing the stream.\n\n</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            },
            {
              "textRaw": "stream.end(string, encoding)",
              "type": "method",
              "name": "end",
              "desc": "<p>Sends <code>string</code> with the given <code>encoding</code> and terminates the stream with EOF\nor FIN. This is useful to reduce the number of packets sent.\n\n</p>\n",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "string"
                    },
                    {
                      "name": "encoding"
                    }
                  ]
                }
              ]
            },
            {
              "textRaw": "stream.end(buffer)",
              "type": "method",
              "name": "end",
              "desc": "<p>Same as above but with a <code>buffer</code>.\n\n</p>\n",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "buffer"
                    }
                  ]
                }
              ]
            },
            {
              "textRaw": "stream.destroy()",
              "type": "method",
              "name": "destroy",
              "desc": "<p>Closes the underlying file descriptor. Stream will not emit any more events.\nAny queued write data will not be sent.\n\n</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            },
            {
              "textRaw": "stream.destroySoon()",
              "type": "method",
              "name": "destroySoon",
              "desc": "<p>After the write queue is drained, close the file descriptor. <code>destroySoon()</code>\ncan still destroy straight away, as long as there is no data left in the queue\nfor writes.\n</p>\n",
              "signatures": [
                {
                  "params": []
                }
              ]
            }
          ]
        }
      ],
      "type": "module",
      "displayName": "Stream"
    }
  ]
}
