Skip to content

Commit d2e54e5

Browse files
vweeverstargos
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 555af5b commit d2e54e5

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
@@ -960,8 +960,9 @@ changes:
960960
-->
961961

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

966967
```js
967968
const readable = getReadableStreamSomehow();
@@ -975,14 +976,10 @@ readable.on('readable', function() {
975976
});
976977
```
977978

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

987984
```js
988985
const fs = require('fs');
@@ -1003,6 +1000,9 @@ readable: null
10031000
end
10041001
```
10051002

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

0 commit comments

Comments
 (0)