Cleanup `_writableState` and `_readableState` access across codebase
This is a meta-issue to keep to track of all usages of _writableState and _readableState outside of streams source. These properties are considered private and should not be used unless absolutely necessary. Usage of them can indicate a few things:
- the code can be rewritten using existing documented API to achieve the same result;
- streams lack some consumer functionality and new public API should be introduced;
- streams lack some implementor functionality and new protected API should be introduced;
- documentation needs to be added for some parts of private state for implementors;
- it is an optimization that is and always be possible only in core.
The list of all _writableState and _readableState usages:
src/node.js
- L564
stdin._readableState.reading = false. Added in commit: bb56dcc by @isaacs; (src: nix stdin _readableState.reading manipulation #454) - L573
stdin._readableState.reading = false. Added in commit: bb56dcc by @isaacs; (src: nix stdin _readableState.reading manipulation #454)
lib/_debug_agent.js
- L87
this._readableState.objectMode = true(_debug_agent: usereadableObjectModeoption for client stream #270);
lib/_http_server.js
- L348
socket._readableState.flowing = null(TODO(isaacs): Need a way to reset a stream to fresh state IE, not flowing, and not explicitly paused.). Added in 967b5db by @isaacs; - L408
var needPause = socket._writableState.needDrain. Added in 085dd30 by @isaacs ; - L445
req._readableState.resumeScheduled. Not sure where this originated, but in 2efe4ab @indutny addedoldModecheck here;
lib/_tls_legacy.js
- L421
this._writableState.finished; - L508
self._readableState.length > 0;
lib/_tls_wrap.js
- L311
self._writableState.errorEmitted(Cleanup stream state in net #465); - L313
self._writableState.errorEmitted = true(Cleanup stream state in net #465); - L350
socket._readableState.length;
lib/child_process.js
- L1061
stream._readableState.flowing(child_process: remove redundant condition #511);
lib/crypto.js
- whole
LazyTransformthing. Is it really necessary? Maybe it should go tostream? Maybe it should be public? Maybe transforms should be lazy by default?; - L56
this._writableState.decodeStrings = false; - L57
this._writableState.defaultEncoding = 'binary'; - L90
var encoding = this._readableState.encoding || 'buffer'(crypto: remove use of this._readableState #610);
lib/fs.js
- L1624
allocNewPool(this._readableState.highWaterMark);
lib/net.js
- L162
this._writableState.decodeStrings = false(Cleanup stream state in net #465); - L174
this._readableState.flowing = false(Cleanup stream state in net #465); - L196
this._readableState.ended(Cleanup stream state in net #465); - L226
self._readableState.ended; - L242
this._readableState.ended = true(comment: ended should already be true, since this is called after the EOF errno and onread has eof'ed) (Cleanup stream state in net #465); - L243
this._readableState.endEmitted; - L362
this._writableState.length; - L392
this._readableState.endEmitted; - L405
socket._writableState.length; - L415
if (this._writableState.finished); - L429
self._writableState.errorEmitted(Cleanup stream state in net #465); - L433
self._writableState.errorEmitted = true(Cleanup stream state in net #465); - L535
self._readableState.length === 0; - L715
state.getBuffer(); - L842
this._readableState.reading = false; - L843
this._readableState.ended = false; - L844
this._readableState.endEmitted = false; - L845
this._writableState.ended = false; - L846
this._writableState.ending = false; - L847
this._writableState.finished = false; - L848
this._writableState.errorEmitted = false(Cleanup stream state in net #465);
lib/zlib.js
- L423
ws.ended; - L426
ws.ending; - L429
ws.needDrain; - L460
ws.ending || ws.ended; - L461
ws.length; - L479
ws.length.
List of used properties:
_readableState
reading;objectMode;flowing(boolean?) is used to determine which mode readable stream is in; can betrue,falseornull; `null is the initial state which means that is implicitly paused;resumeScheduled;length;encoding;highWaterMark;ended;endEmitted;
_writableState
needDrain;ended;ending;finished;errorEmitted;decodeStrings;defaultEncoding;length;getBuffer();
/cc @chrisdickinson