@@ -618,6 +618,12 @@ instance, when the `readable.resume()` method is called without a listener
618
618
attached to the ` 'data' ` event, or when a ` 'data' ` event handler is removed
619
619
from the stream.
620
620
621
+ Adding a [ ` 'readable' ` ] [ ] event handler automatically make the stream to
622
+ stop flowing, and the data to be consumed via
623
+ [ ` readable.read() ` ] [ stream-read ] . If the [ ` 'readable' ` ] event handler is
624
+ removed, then the stream will start flowing again if there is a
625
+ [ ` 'data' ` ] [ ] event handler.
626
+
621
627
#### Three States
622
628
623
629
The "two modes" of operation for a ` Readable ` stream are a simplified
@@ -666,12 +672,15 @@ within the streams internal buffer.
666
672
The ` Readable ` stream API evolved across multiple Node.js versions and provides
667
673
multiple methods of consuming stream data. In general, developers should choose
668
674
* one* of the methods of consuming data and * should never* use multiple methods
669
- to consume data from a single stream.
675
+ to consume data from a single stream. Specifically, using a combination
676
+ of ` on('data') ` , ` on('readable') ` , ` pipe() ` or async iterators could
677
+ lead to unintuitive behavior.
670
678
671
679
Use of the ` readable.pipe() ` method is recommended for most users as it has been
672
680
implemented to provide the easiest way of consuming stream data. Developers that
673
681
require more fine-grained control over the transfer and generation of data can
674
- use the [ ` EventEmitter ` ] [ ] and ` readable.pause() ` /` readable.resume() ` APIs.
682
+ use the [ ` EventEmitter ` ] [ ] and ` readable.on('readable') ` /` readable.read() `
683
+ or the ` readable.pause() ` /` readable.resume() ` APIs.
675
684
676
685
#### Class: stream.Readable
677
686
<!-- YAML
@@ -825,7 +834,11 @@ result in increased throughput.
825
834
826
835
If both ` 'readable' ` and [ ` 'data' ` ] [ ] are used at the same time, ` 'readable' `
827
836
takes precedence in controlling the flow, i.e. ` 'data' ` will be emitted
828
- only when [ ` stream.read() ` ] [ stream-read ] is called.
837
+ only when [ ` stream.read() ` ] [ stream-read ] is called. The
838
+ ` readableFlowing ` property would become ` false ` .
839
+ If there are ` 'data' ` listeners when ` 'readable' ` is removed, the stream
840
+ will start flowing, i.e. ` 'data' ` events will be emitted without calling
841
+ ` .resume() ` .
829
842
830
843
##### readable.destroy([ error] )
831
844
<!-- YAML
@@ -887,6 +900,9 @@ readable.on('data', (chunk) => {
887
900
});
888
901
```
889
902
903
+ The ` readable.pause() ` method has no effect if there is a ` 'readable' `
904
+ event listener.
905
+
890
906
##### readable.pipe(destination[ , options] )
891
907
<!-- YAML
892
908
added: v0.9.4
0 commit comments