Skip to content

Commit 132297d

Browse files
tomgcoFishrock123
authored andcommitted
doc: Updated streams simplified constructor API
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]>
1 parent d137f0f commit 132297d

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

doc/api/stream.markdown

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,9 +1368,16 @@ Examples:
13681368
var duplex = new stream.Duplex({
13691369
read: function(n) {
13701370
// sets this._read under the hood
1371+
1372+
// push data onto the read queue, passing null
1373+
// will signal the end of the stream (EOF)
1374+
this.push(chunk);
13711375
},
13721376
write: function(chunk, encoding, next) {
13731377
// sets this._write under the hood
1378+
1379+
// An optional error can be passed as the first argument
1380+
next()
13741381
}
13751382
});
13761383

@@ -1379,9 +1386,16 @@ var duplex = new stream.Duplex({
13791386
var duplex = new stream.Duplex({
13801387
read: function(n) {
13811388
// sets this._read under the hood
1389+
1390+
// push data onto the read queue, passing null
1391+
// will signal the end of the stream (EOF)
1392+
this.push(chunk);
13821393
},
13831394
writev: function(chunks, next) {
13841395
// sets this._writev under the hood
1396+
1397+
// An optional error can be passed as the first argument
1398+
next()
13851399
}
13861400
});
13871401
```
@@ -1391,6 +1405,10 @@ var duplex = new stream.Duplex({
13911405
var readable = new stream.Readable({
13921406
read: function(n) {
13931407
// sets this._read under the hood
1408+
1409+
// push data onto the read queue, passing null
1410+
// will signal the end of the stream (EOF)
1411+
this.push(chunk);
13941412
}
13951413
});
13961414
```
@@ -1400,9 +1418,20 @@ var readable = new stream.Readable({
14001418
var transform = new stream.Transform({
14011419
transform: function(chunk, encoding, next) {
14021420
// sets this._transform under the hood
1421+
1422+
// generate output as many times as needed
1423+
// this.push(chunk);
1424+
1425+
// call when the current chunk is consumed
1426+
next();
14031427
},
14041428
flush: function(done) {
14051429
// sets this._flush under the hood
1430+
1431+
// generate output as many times as needed
1432+
// this.push(chunk);
1433+
1434+
done();
14061435
}
14071436
});
14081437
```
@@ -1412,6 +1441,9 @@ var transform = new stream.Transform({
14121441
var writable = new stream.Writable({
14131442
write: function(chunk, encoding, next) {
14141443
// sets this._write under the hood
1444+
1445+
// An optional error can be passed as the first argument
1446+
next()
14151447
}
14161448
});
14171449

@@ -1420,6 +1452,9 @@ var writable = new stream.Writable({
14201452
var writable = new stream.Writable({
14211453
writev: function(chunks, next) {
14221454
// sets this._writev under the hood
1455+
1456+
// An optional error can be passed as the first argument
1457+
next()
14231458
}
14241459
});
14251460
```

0 commit comments

Comments
 (0)