Skip to content

Commit 14000b9

Browse files
committed
doc: two minor stream doc improvements
per: nodejs/node-v0.x-archive#14596 1. document that a runtime error will occur if you attempt to unshift after the end event 2. document that calling read after the end event will return null and will not trigger a runtime error Reviewed-By: James M Snell <jasnell@gmail.com> PR-URL: nodejs/node-v0.x-archive#25591
1 parent 8cbf7cb commit 14000b9

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

doc/api/stream.markdown

+7-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ returns it. If there is no data available, then it will return
228228

229229
If you pass in a `size` argument, then it will return that many
230230
bytes. If `size` bytes are not available, then it will return `null`,
231-
unless we've ended, in which case it will return the data remaining
231+
unless we've ended, in which case it will return the data remaining
232232
in the buffer.
233233

234234
If you do not specify a `size` argument, then it will return all the
@@ -251,6 +251,9 @@ readable.on('readable', function() {
251251
If this method returns a data chunk, then it will also trigger the
252252
emission of a [`'data'` event][].
253253

254+
Note that calling `readable.read([size])` after the `end` event has been
255+
triggered will return `null`. No runtime error will be raised.
256+
254257
#### readable.setEncoding(encoding)
255258

256259
* `encoding` {String} The encoding to use.
@@ -422,6 +425,9 @@ parser, which needs to "un-consume" some data that it has
422425
optimistically pulled out of the source, so that the stream can be
423426
passed on to some other party.
424427

428+
Note that `stream.unshift(chunk)` cannot be called after the `end` event
429+
has been triggered; a runtime error will be raised.
430+
425431
If you find that you must often call `stream.unshift(chunk)` in your
426432
programs, consider implementing a [Transform][] stream instead. (See API
427433
for Stream Implementors, below.)

0 commit comments

Comments
 (0)