stream: use readableObjectMode public api for js stream by antsmartian · Pull Request #27655 · nodejs/node · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/api/stream.md
7 changes: 7 additions & 0 deletions lib/_stream_readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,13 @@ Object.defineProperty(Readable.prototype, 'readableLength', {
}
});

Object.defineProperty(Readable.prototype, 'readableObjectMode', {
enumerable: false,
get() {
return this._readableState ? this._readableState.objectMode : false;
}
});

// Pluck off n bytes from an array of buffers.
// Length is the combined lengths of all the buffers in the list.
// This function is designed to be inlinable, so please take care when making
Expand Down
7 changes: 7 additions & 0 deletions lib/_stream_writable.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,13 @@ Object.defineProperty(Writable.prototype, 'destroyed', {
}
});

Object.defineProperty(Writable.prototype, 'writableObjectMode', {
enumerable: false,
get() {
return this._writableState ? this._writableState.objectMode : false;
}
});

Writable.prototype.destroy = destroyImpl.destroy;
Writable.prototype._undestroy = destroyImpl.undestroy;
Writable.prototype._destroy = function(err, cb) {
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/js_stream_socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class JSStreamSocket extends Socket {
stream.on('error', (err) => this.emit('error', err));
const ondata = (chunk) => {
if (typeof chunk === 'string' ||
stream._readableState.objectMode === true) {
stream.readableObjectMode === true) {
// Make sure that no further `data` events will happen.
stream.pause();
stream.removeListener('data', ondata);
Expand Down
13 changes: 13 additions & 0 deletions test/parallel/test-stream2-basic.js