@@ -960,8 +960,9 @@ changes:
960
960
-->
961
961
962
962
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.
965
966
966
967
``` js
967
968
const readable = getReadableStreamSomehow ();
@@ -975,14 +976,10 @@ readable.on('readable', function() {
975
976
});
976
977
```
977
978
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:
986
983
987
984
``` js
988
985
const fs = require (' fs' );
@@ -1003,6 +1000,9 @@ readable: null
1003
1000
end
1004
1001
```
1005
1002
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
+
1006
1006
In general, the ` readable.pipe() ` and ` 'data' ` event mechanisms are easier to
1007
1007
understand than the ` 'readable' ` event. However, handling ` 'readable' ` might
1008
1008
result in increased throughput.
0 commit comments