diff options
-rw-r--r-- | doc/api/streams.markdown | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/doc/api/streams.markdown b/doc/api/streams.markdown index 8480a34750..6392eec7bb 100644 --- a/doc/api/streams.markdown +++ b/doc/api/streams.markdown @@ -65,7 +65,32 @@ Resumes the incoming `'data'` events after a `pause()`. Closes the underlying file descriptor. Stream will not emit any more events. +### stream.pipe(destination, [options]) +This is a `Stream.prototype` method available on all `Stream`s. + +Connects this read stream to `destination` WriteStream. Incoming +data on this stream gets written to `destination`. The destination and source +streams are kept in sync by pausing and resuming as necessary. + +Emulating the Unix `cat` command: + + process.openStdin().pipe(process.stdout); + + +By default `end()` is called on the destination when the source stream emits +`end`, so that `destination` is no longer writable. Pass `{ end: false }` as +`options` to keep the destination stream open. + +This keeps `process.stdout` open so that "Goodbye" can be written at the end. + + var stdin = process.openStdin(); + stdin.pipe(process.stdout, { end: false }); + stdin.on("end", function() { process.stdout.write("Goodbye\n"); }); + +NOTE: If the source stream does not support `pause()` and `resume()`, this function +adds simple definitions which simply emit `'pause'` and `'resume'` events on +the source stream. ## Writable Stream |