doc: Updated streams simplified constructor API
authorTom Gallacher <tomgallacher23@gmail.com>
Fri, 30 Oct 2015 10:59:21 +0000 (06:59 -0400)
committerJames M Snell <jasnell@gmail.com>
Wed, 23 Dec 2015 16:38:33 +0000 (08:38 -0800)
The examples for implementing the simplified constructor API
was missing some details on its correct usages.

PR-URL: https://github.com/nodejs/node/pull/3602
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Chris Dickinson <chris@neversaw.us>
doc/api/stream.markdown

index 4dfc36e09e664859842992dbd3431a57d584b0bc..2e9ea45151aecd176da5e60fadba444fb40300e3 100644 (file)
@@ -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);
   }
 });
 ```
@@ -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()
   }
 });
 
@@ -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()
   }
 });
 ```
@@ -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()
   }
 });
 
@@ -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()
   }
 });
 ```
@@ -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();
   }
 });
 ```