From db745ca2a29ab15a5a6b12373bd785f504a09c93 Mon Sep 17 00:00:00 2001 From: Daniel Eisenbarger Date: Mon, 20 Feb 2017 18:13:21 -0800 Subject: [PATCH 1/2] end of stream - inform consumer by passing null Implicitly passing undefined as chunk to readable.push does not properly inform consumer that data output is finished. --- listings/streams/node-0.10/express.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listings/streams/node-0.10/express.js b/listings/streams/node-0.10/express.js index 7f360b1..edc1b61 100644 --- a/listings/streams/node-0.10/express.js +++ b/listings/streams/node-0.10/express.js @@ -13,7 +13,7 @@ function StatStream(limit) { StatStream.prototype._read = function(size) { if (this.limit === 0) { // Done - this.push(); + this.push(null); } else { this.push(util.inspect(process.memoryUsage())); // this.push('\n'); From 52343f16fc7a8fe905ed708323364ac7b3582044 Mon Sep 17 00:00:00 2001 From: Daniel Eisenbarger Date: Mon, 20 Feb 2017 18:25:38 -0800 Subject: [PATCH 2/2] update errata: end of readable stream --- ERRATA.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ERRATA.md b/ERRATA.md index 95a3b83..d67bf76 100644 --- a/ERRATA.md +++ b/ERRATA.md @@ -17,3 +17,22 @@ should be ```js lineIndex = this._buffer.indexOf('\n'); ``` + +### End of readable stream + +Implicitly passing undefined as chunk to readable.push does not properly inform consumer that data output is finished. +Pass null instead. + +Page 92, Listing 5.4 + +```js +// Done +this.push(); +``` + +should be + +```js +// Done +this.push(null); +```