diff options
author | Calvin Metcalf <cmetcalf@appgeo.com> | 2017-05-16 11:08:49 -0400 |
---|---|---|
committer | Matteo Collina <hello@matteocollina.com> | 2017-12-15 23:05:45 +0100 |
commit | e20af3371bb1f0ee16795528cbcbc674408842cb (patch) | |
tree | 0a0426a7c304adcf9b0bfc9c0e3e7c1a762a8fd3 /doc/api/stream.md | |
parent | 31addac8bbcd3e0a8cefba8327cfcc7fd9bdeb68 (diff) | |
download | android-node-v8-e20af3371bb1f0ee16795528cbcbc674408842cb.tar.gz android-node-v8-e20af3371bb1f0ee16795528cbcbc674408842cb.tar.bz2 android-node-v8-e20af3371bb1f0ee16795528cbcbc674408842cb.zip |
stream: add flow and buffer properties to streams
This adds computed properties to readable and writable streams to
allow access to the readable buffer, the writable buffer, and flow
state without accessing the readable or writable state.
These are the only uses of readable and writable state in the docs
so adding these work arounds allows them to be removed from the docs.
This also updates net, http_client and http_server to use the new
methods instead of manipulating readable and writable state directly.
See: https://github.com/nodejs/node/issues/445
PR-URL: https://github.com/nodejs/node/pull/12855
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'doc/api/stream.md')
-rw-r--r-- | doc/api/stream.md | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/doc/api/stream.md b/doc/api/stream.md index f3780ee4c4..dc74df7720 100644 --- a/doc/api/stream.md +++ b/doc/api/stream.md @@ -63,8 +63,8 @@ object mode is not safe. <!--type=misc--> Both [Writable][] and [Readable][] streams will store data in an internal -buffer that can be retrieved using `writable._writableState.getBuffer()` or -`readable._readableState.buffer`, respectively. +buffer that can be retrieved using `writable.writableBuffer` or +`readable.readableBuffer`, respectively. The amount of data potentially buffered depends on the `highWaterMark` option passed into the streams constructor. For normal streams, the `highWaterMark` @@ -602,22 +602,22 @@ Readable stream implementation. Specifically, at any given point in time, every Readable is in one of three possible states: -* `readable._readableState.flowing = null` -* `readable._readableState.flowing = false` -* `readable._readableState.flowing = true` +* `readable.readableFlowing = null` +* `readable.readableFlowing = false` +* `readable.readableFlowing = true` -When `readable._readableState.flowing` is `null`, no mechanism for consuming the +When `readable.readableFlowing` is `null`, no mechanism for consuming the streams data is provided so the stream will not generate its data. While in this state, attaching a listener for the `'data'` event, calling the `readable.pipe()` method, or calling the `readable.resume()` method will switch -`readable._readableState.flowing` to `true`, causing the Readable to begin +`readable.readableFlowing` to `true`, causing the Readable to begin actively emitting events as data is generated. Calling `readable.pause()`, `readable.unpipe()`, or receiving "back pressure" -will cause the `readable._readableState.flowing` to be set as `false`, +will cause the `readable.readableFlowing` to be set as `false`, temporarily halting the flowing of events but *not* halting the generation of data. While in this state, attaching a listener for the `'data'` event -would not cause `readable._readableState.flowing` to switch to `true`. +would not cause `readable.readableFlowing` to switch to `true`. ```js const { PassThrough, Writable } = require('stream'); @@ -626,14 +626,14 @@ const writable = new Writable(); pass.pipe(writable); pass.unpipe(writable); -// flowing is now false +// readableFlowing is now false pass.on('data', (chunk) => { console.log(chunk.toString()); }); pass.write('ok'); // will not emit 'data' pass.resume(); // must be called to make 'data' being emitted ``` -While `readable._readableState.flowing` is `false`, data may be accumulating +While `readable.readableFlowing` is `false`, data may be accumulating within the streams internal buffer. #### Choose One |