Skip to content

Commit 1e89238

Browse files
vweeversnodejs-github-bot
authored andcommitted
doc: reorder stream 'readable' paragraphs
Fixes: #40136 PR-URL: #40212 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Anto Aravinth <[email protected]>
1 parent 140b25a commit 1e89238

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

doc/api/stream.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -962,8 +962,9 @@ changes:
962962
-->
963963

964964
The `'readable'` event is emitted when there is data available to be read from
965-
the stream. In some cases, attaching a listener for the `'readable'` event will
966-
cause some amount of data to be read into an internal buffer.
965+
the stream or when the end of the stream has been reached. Effectively, the
966+
`'readable'` event indicates that the stream has new information. If data is
967+
available, [`stream.read()`][stream-read] will return that data.
967968

968969
```js
969970
const readable = getReadableStreamSomehow();
@@ -977,14 +978,10 @@ readable.on('readable', function() {
977978
});
978979
```
979980

980-
The `'readable'` event will also be emitted once the end of the stream data
981-
has been reached but before the `'end'` event is emitted.
982-
983-
Effectively, the `'readable'` event indicates that the stream has new
984-
information: either new data is available or the end of the stream has been
985-
reached. In the former case, [`stream.read()`][stream-read] will return the
986-
available data. In the latter case, [`stream.read()`][stream-read] will return
987-
`null`. For instance, in the following example, `foo.txt` is an empty file:
981+
If the end of the stream has been reached, calling
982+
[`stream.read()`][stream-read] will return `null` and trigger the `'end'`
983+
event. This is also true if there never was any data to be read. For instance,
984+
in the following example, `foo.txt` is an empty file:
988985

989986
```js
990987
const fs = require('fs');
@@ -1005,6 +1002,9 @@ readable: null
10051002
end
10061003
```
10071004

1005+
In some cases, attaching a listener for the `'readable'` event will cause some
1006+
amount of data to be read into an internal buffer.
1007+
10081008
In general, the `readable.pipe()` and `'data'` event mechanisms are easier to
10091009
understand than the `'readable'` event. However, handling `'readable'` might
10101010
result in increased throughput.

0 commit comments

Comments
 (0)