Skip to content

Commit

Permalink
doc: Updated streams simplified constructor API
Browse files Browse the repository at this point in the history
The examples for implementing the simplified constructor API
was missing some details on its correct usages.

PR-URL: #3602
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Chris Dickinson <[email protected]>
  • Loading branch information
tomgco authored and Fishrock123 committed Nov 17, 2015
1 parent d137f0f commit 132297d
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions doc/api/stream.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -1368,9 +1368,16 @@ Examples:
var duplex = new stream.Duplex({
read: function(n) {
// sets this._read under the hood

// push data onto the read queue, passing null
// will signal the end of the stream (EOF)
this.push(chunk);
},
write: function(chunk, encoding, next) {
// sets this._write under the hood

// An optional error can be passed as the first argument
next()
}
});

Expand All @@ -1379,9 +1386,16 @@ var duplex = new stream.Duplex({
var duplex = new stream.Duplex({
read: function(n) {
// sets this._read under the hood

// push data onto the read queue, passing null
// will signal the end of the stream (EOF)
this.push(chunk);
},
writev: function(chunks, next) {
// sets this._writev under the hood

// An optional error can be passed as the first argument
next()
}
});
```
Expand All @@ -1391,6 +1405,10 @@ var duplex = new stream.Duplex({
var readable = new stream.Readable({
read: function(n) {
// sets this._read under the hood

// push data onto the read queue, passing null
// will signal the end of the stream (EOF)
this.push(chunk);
}
});
```
Expand All @@ -1400,9 +1418,20 @@ var readable = new stream.Readable({
var transform = new stream.Transform({
transform: function(chunk, encoding, next) {
// sets this._transform under the hood

// generate output as many times as needed
// this.push(chunk);

// call when the current chunk is consumed
next();
},
flush: function(done) {
// sets this._flush under the hood

// generate output as many times as needed
// this.push(chunk);

done();
}
});
```
Expand All @@ -1412,6 +1441,9 @@ var transform = new stream.Transform({
var writable = new stream.Writable({
write: function(chunk, encoding, next) {
// sets this._write under the hood

// An optional error can be passed as the first argument
next()
}
});

Expand All @@ -1420,6 +1452,9 @@ var writable = new stream.Writable({
var writable = new stream.Writable({
writev: function(chunks, next) {
// sets this._writev under the hood

// An optional error can be passed as the first argument
next()
}
});
```
Expand Down

0 comments on commit 132297d

Please sign in to comment.