Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Updated streams simplified constructor API #3602

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions doc/api/stream.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,10 @@ Examples:
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 @@ -1384,6 +1388,9 @@ var readable = new stream.Readable({
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 @@ -1392,6 +1399,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 All @@ -1401,9 +1411,16 @@ var writable = new stream.Writable({
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 @@ -1412,9 +1429,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 @@ -1424,9 +1448,20 @@ var duplex = new stream.Duplex({
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 Down