@@ -962,8 +962,9 @@ changes:
962
962
-->
963
963
964
964
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.
967
968
968
969
``` js
969
970
const readable = getReadableStreamSomehow ();
@@ -977,14 +978,10 @@ readable.on('readable', function() {
977
978
});
978
979
```
979
980
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:
988
985
989
986
``` js
990
987
const fs = require (' fs' );
@@ -1005,6 +1002,9 @@ readable: null
1005
1002
end
1006
1003
```
1007
1004
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
+
1008
1008
In general, the ` readable.pipe() ` and ` 'data' ` event mechanisms are easier to
1009
1009
understand than the ` 'readable' ` event. However, handling ` 'readable' ` might
1010
1010
result in increased throughput.
0 commit comments