| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,7 +33,10 @@ const { Buffer } = require('buffer'); | |||
| 33 | 33 | const debug = require('internal/util/debuglog').debuglog('stream'); | |
| 34 | 34 | const BufferList = require('internal/streams/buffer_list'); | |
| 35 | 35 | const destroyImpl = require('internal/streams/destroy'); | |
| 36 | - const { getHighWaterMark } = require('internal/streams/state'); | ||
| 36 | + const { | ||
| 37 | + getHighWaterMark, | ||
| 38 | + getDefaultHighWaterMark | ||
| 39 | + } = require('internal/streams/state'); | ||
| 37 | 40 | const { | |
| 38 | 41 | ERR_INVALID_ARG_TYPE, | |
| 39 | 42 | ERR_STREAM_PUSH_AFTER_EOF, | |
@@ -70,8 +73,6 @@ function prependListener(emitter, event, fn) { | |||
| 70 | 73 | } | |
| 71 | 74 | ||
| 72 | 75 | function ReadableState(options, stream, isDuplex) { | |
| 73 | - options = options || {}; | ||
| 74 | - | ||
| 75 | 76 | // Duplex streams are both readable and writable, but share | |
| 76 | 77 | // the same options object. | |
| 77 | 78 | // However, some cases require setting options to different | |
@@ -82,15 +83,17 @@ function ReadableState(options, stream, isDuplex) { | |||
| 82 | 83 | ||
| 83 | 84 | // Object stream flag. Used to make read(n) ignore n and to | |
| 84 | 85 | // make all the buffer merging and length checks go away | |
| 85 | - this.objectMode = !!options.objectMode; | ||
| 86 | + this.objectMode = !!(options && options.objectMode); | ||
| 86 | 87 | ||
| 87 | 88 | if (isDuplex) | |
| 88 | - this.objectMode = this.objectMode || !!options.readableObjectMode; | ||
| 89 | + this.objectMode = this.objectMode || | ||
| 90 | + !!(options && options.readableObjectMode); | ||
| 89 | 91 | ||
| 90 | 92 | // The point at which it stops calling _read() to fill the buffer | |
| 91 | 93 | // Note: 0 is a valid value, means "don't call _read preemptively ever" | |
| 92 | - this.highWaterMark = getHighWaterMark(this, options, 'readableHighWaterMark', | ||
| 93 | - isDuplex); | ||
| 94 | + this.highWaterMark = options ? | ||
| 95 | + getHighWaterMark(this, options, 'readableHighWaterMark', isDuplex) : | ||
| 96 | + getDefaultHighWaterMark(false); | ||
| 94 | 97 | ||
| 95 | 98 | // A linked list is used to store data chunks instead of an array because the | |
| 96 | 99 | // linked list can remove elements from the beginning faster than | |
@@ -119,18 +122,18 @@ function ReadableState(options, stream, isDuplex) { | |||
| 119 | 122 | this.paused = true; | |
| 120 | 123 | ||
| 121 | 124 | // Should close be emitted on destroy. Defaults to true. | |
| 122 | - this.emitClose = options.emitClose !== false; | ||
| 125 | + this.emitClose = !options || options.emitClose !== false; | ||
| 123 | 126 | ||
| 124 | 127 | // Should .destroy() be called after 'end' (and potentially 'finish') | |
| 125 | - this.autoDestroy = !!options.autoDestroy; | ||
| 128 | + this.autoDestroy = !!(options && options.autoDestroy); | ||
| 126 | 129 | ||
| 127 | 130 | // Has it been destroyed | |
| 128 | 131 | this.destroyed = false; | |
| 129 | 132 | ||
| 130 | 133 | // Crypto is kind of old and crusty. Historically, its default string | |
| 131 | 134 | // encoding is 'binary' so we have to make this configurable. | |
| 132 | 135 | // Everything else in the universe uses 'utf8', though. | |
| 133 | - this.defaultEncoding = options.defaultEncoding || 'utf8'; | ||
| 136 | + this.defaultEncoding = (options && options.defaultEncoding) || 'utf8'; | ||
| 134 | 137 | ||
| 135 | 138 | // The number of writers that are awaiting a drain event in .pipe()s | |
| 136 | 139 | this.awaitDrain = 0; | |
@@ -140,7 +143,7 @@ function ReadableState(options, stream, isDuplex) { | |||
| 140 | 143 | ||
| 141 | 144 | this.decoder = null; | |
| 142 | 145 | this.encoding = null; | |
| 143 | - if (options.encoding) { | ||
| 146 | + if (options && options.encoding) { | ||
| 144 | 147 | if (!StringDecoder) | |
| 145 | 148 | StringDecoder = require('string_decoder').StringDecoder; | |
| 146 | 149 | this.decoder = new StringDecoder(options.encoding); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,7 +34,10 @@ const internalUtil = require('internal/util'); | |||
| 34 | 34 | const Stream = require('stream'); | |
| 35 | 35 | const { Buffer } = require('buffer'); | |
| 36 | 36 | const destroyImpl = require('internal/streams/destroy'); | |
| 37 | - const { getHighWaterMark } = require('internal/streams/state'); | ||
| 37 | + const { | ||
| 38 | + getHighWaterMark, | ||
| 39 | + getDefaultHighWaterMark | ||
| 40 | + } = require('internal/streams/state'); | ||
| 38 | 41 | const { | |
| 39 | 42 | ERR_INVALID_ARG_TYPE, | |
| 40 | 43 | ERR_METHOD_NOT_IMPLEMENTED, | |
@@ -54,8 +57,6 @@ Object.setPrototypeOf(Writable, Stream); | |||
| 54 | 57 | function nop() {} | |
| 55 | 58 | ||
| 56 | 59 | function WritableState(options, stream, isDuplex) { | |
| 57 | - options = options || {}; | ||
| 58 | - | ||
| 59 | 60 | // Duplex streams are both readable and writable, but share | |
| 60 | 61 | // the same options object. | |
| 61 | 62 | // However, some cases require setting options to different | |
@@ -66,16 +67,18 @@ function WritableState(options, stream, isDuplex) { | |||
| 66 | 67 | ||
| 67 | 68 | // Object stream flag to indicate whether or not this stream | |
| 68 | 69 | // contains buffers or objects. | |
| 69 | - this.objectMode = !!options.objectMode; | ||
| 70 | + this.objectMode = !!(options && options.objectMode); | ||
| 70 | 71 | ||
| 71 | 72 | if (isDuplex) | |
| 72 | - this.objectMode = this.objectMode || !!options.writableObjectMode; | ||
| 73 | + this.objectMode = this.objectMode || | ||
| 74 | + !!(options && options.writableObjectMode); | ||
| 73 | 75 | ||
| 74 | 76 | // The point at which write() starts returning false | |
| 75 | 77 | // Note: 0 is a valid value, means that we always return false if | |
| 76 | 78 | // the entire buffer is not flushed immediately on write() | |
| 77 | - this.highWaterMark = getHighWaterMark(this, options, 'writableHighWaterMark', | ||
| 78 | - isDuplex); | ||
| 79 | + this.highWaterMark = options ? | ||
| 80 | + getHighWaterMark(this, options, 'writableHighWaterMark', isDuplex) : | ||
| 81 | + getDefaultHighWaterMark(false); | ||
| 79 | 82 | ||
| 80 | 83 | // if _final has been called | |
| 81 | 84 | this.finalCalled = false; | |
@@ -95,13 +98,13 @@ function WritableState(options, stream, isDuplex) { | |||
| 95 | 98 | // Should we decode strings into buffers before passing to _write? | |
| 96 | 99 | // this is here so that some node-core streams can optimize string | |
| 97 | 100 | // handling at a lower level. | |
| 98 | - const noDecode = options.decodeStrings === false; | ||
| 101 | + const noDecode = !!(options && options.decodeStrings === false); | ||
| 99 | 102 | this.decodeStrings = !noDecode; | |
| 100 | 103 | ||
| 101 | 104 | // Crypto is kind of old and crusty. Historically, its default string | |
| 102 | 105 | // encoding is 'binary' so we have to make this configurable. | |
| 103 | 106 | // Everything else in the universe uses 'utf8', though. | |
| 104 | - this.defaultEncoding = options.defaultEncoding || 'utf8'; | ||
| 107 | + this.defaultEncoding = (options && options.defaultEncoding) || 'utf8'; | ||
| 105 | 108 | ||
| 106 | 109 | // Not an actual buffer we keep track of, but a measurement | |
| 107 | 110 | // of how much we're waiting to get pushed to some underlying | |
@@ -149,10 +152,10 @@ function WritableState(options, stream, isDuplex) { | |||
| 149 | 152 | this.errorEmitted = false; | |
| 150 | 153 | ||
| 151 | 154 | // Should close be emitted on destroy. Defaults to true. | |
| 152 | - this.emitClose = options.emitClose !== false; | ||
| 155 | + this.emitClose = !options || options.emitClose !== false; | ||
| 153 | 156 | ||
| 154 | 157 | // Should .destroy() be called after 'finish' (and potentially 'end') | |
| 155 | - this.autoDestroy = !!options.autoDestroy; | ||
| 158 | + this.autoDestroy = !!(options && options.autoDestroy); | ||
| 156 | 159 | ||
| 157 | 160 | // Count buffered requests | |
| 158 | 161 | this.bufferedRequestCount = 0; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments