FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Added documentation for Stream.pipe · tmpvar/node@f11291a · GitHub

Commit f11291a

Browse files
authored andcommitted
Added documentation for Stream.pipe
1 parent 9c29ac6 commit f11291a

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

‎doc/api/streams.markdown‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,32 @@ Resumes the incoming `'data'` events after a `pause()`.
6565

6666
Closes the underlying file descriptor. Stream will not emit any more events.
6767

68+
### stream.pipe(destination, [options])
6869

70+
This is a `Stream.prototype` method available on all `Stream`s.
71+
72+
Connects this read stream to `destination` WriteStream. Incoming
73+
data on this stream gets written to `destination`. The destination and source
74+
streams are kept in sync by pausing and resuming as necessary.
75+
76+
Emulating the Unix `cat` command:
77+
78+
process.openStdin().pipe(process.stdout);
79+
80+
81+
By default `end()` is called on the destination when the source stream emits
82+
`end`, so that `destination` is no longer writable. Pass `{ end: false }` as
83+
`options` to keep the destination stream open.
84+
85+
This keeps `process.stdout` open so that "Goodbye" can be written at the end.
86+
87+
var stdin = process.openStdin();
88+
stdin.pipe(process.stdout, { end: false });
89+
stdin.on("end", function() { process.stdout.write("Goodbye\n"); });
90+
91+
NOTE: If the source stream does not support `pause()` and `resume()`, this function
92+
adds simple definitions which simply emit `'pause'` and `'resume'` events on
93+
the source stream.
6994

7095
## Writable Stream
7196

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL