summaryrefslogtreecommitdiff
path: root/lib/_stream_readable.js
diff options
context:
space:
mode:
authorRobert Nagy <ronagy@icloud.com>2019-08-15 13:06:51 +0200
committerzhangyongsheng <zhangyongsheng@youzan.com>2019-09-22 21:46:58 +0800
commitbd02775af8db478c3564d4ca44ec171e403547df (patch)
treefd7f8c583604b3d2039e75d9bb6fbd8185b38977 /lib/_stream_readable.js
parent8235ffd7863305485dbbe27e7ed8bbe9f369d19d (diff)
downloadandroid-node-v8-bd02775af8db478c3564d4ca44ec171e403547df.tar.gz
android-node-v8-bd02775af8db478c3564d4ca44ec171e403547df.tar.bz2
android-node-v8-bd02775af8db478c3564d4ca44ec171e403547df.zip
stream: optimize creation
PR-URL: https://github.com/nodejs/node/pull/29135 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Diffstat (limited to 'lib/_stream_readable.js')
-rw-r--r--lib/_stream_readable.js25
1 files changed, 14 insertions, 11 deletions
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index cfa36731e3..7502a1ac2c 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -33,7 +33,10 @@ const { Buffer } = require('buffer');
const debug = require('internal/util/debuglog').debuglog('stream');
const BufferList = require('internal/streams/buffer_list');
const destroyImpl = require('internal/streams/destroy');
-const { getHighWaterMark } = require('internal/streams/state');
+const {
+ getHighWaterMark,
+ getDefaultHighWaterMark
+} = require('internal/streams/state');
const {
ERR_INVALID_ARG_TYPE,
ERR_STREAM_PUSH_AFTER_EOF,
@@ -70,8 +73,6 @@ function prependListener(emitter, event, fn) {
}
function ReadableState(options, stream, isDuplex) {
- options = options || {};
-
// Duplex streams are both readable and writable, but share
// the same options object.
// However, some cases require setting options to different
@@ -82,15 +83,17 @@ function ReadableState(options, stream, isDuplex) {
// Object stream flag. Used to make read(n) ignore n and to
// make all the buffer merging and length checks go away
- this.objectMode = !!options.objectMode;
+ this.objectMode = !!(options && options.objectMode);
if (isDuplex)
- this.objectMode = this.objectMode || !!options.readableObjectMode;
+ this.objectMode = this.objectMode ||
+ !!(options && options.readableObjectMode);
// The point at which it stops calling _read() to fill the buffer
// Note: 0 is a valid value, means "don't call _read preemptively ever"
- this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark',
- isDuplex);
+ this.highWaterMark = options ?
+ getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex) :
+ getDefaultHighWaterMark(false);
// A linked list is used to store data chunks instead of an array because the
// linked list can remove elements from the beginning faster than
@@ -121,10 +124,10 @@ function ReadableState(options, stream, isDuplex) {
this.errorEmitted = false;
// Should close be emitted on destroy. Defaults to true.
- this.emitClose = options.emitClose !== false;
+ this.emitClose = !options || options.emitClose !== false;
// Should .destroy() be called after 'end' (and potentially 'finish')
- this.autoDestroy = !!options.autoDestroy;
+ this.autoDestroy = !!(options && options.autoDestroy);
// Has it been destroyed
this.destroyed = false;
@@ -132,7 +135,7 @@ function ReadableState(options, stream, isDuplex) {
// Crypto is kind of old and crusty. Historically, its default string
// encoding is 'binary' so we have to make this configurable.
// Everything else in the universe uses 'utf8', though.
- this.defaultEncoding = options.defaultEncoding || 'utf8';
+ this.defaultEncoding = (options && options.defaultEncoding) || 'utf8';
// Ref the piped dest which we need a drain event on it
// type: null | Writable | Set<Writable>
@@ -144,7 +147,7 @@ function ReadableState(options, stream, isDuplex) {
this.decoder = null;
this.encoding = null;
- if (options.encoding) {
+ if (options && options.encoding) {
if (!StringDecoder)
StringDecoder = require('string_decoder').StringDecoder;
this.decoder = new StringDecoder(options.encoding);