@@ -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 ,
@@ -55,8 +58,6 @@ Object.setPrototypeOf(Writable, Stream);
55
58
function nop ( ) { }
56
59
57
60
function WritableState ( options , stream , isDuplex ) {
58
- options = options || { } ;
59
-
60
61
// Duplex streams are both readable and writable, but share
61
62
// the same options object.
62
63
// However, some cases require setting options to different
@@ -67,16 +68,18 @@ function WritableState(options, stream, isDuplex) {
67
68
68
69
// Object stream flag to indicate whether or not this stream
69
70
// contains buffers or objects.
70
- this . objectMode = ! ! options . objectMode ;
71
+ this . objectMode = ! ! ( options && options . objectMode ) ;
71
72
72
73
if ( isDuplex )
73
- this . objectMode = this . objectMode || ! ! options . writableObjectMode ;
74
+ this . objectMode = this . objectMode ||
75
+ ! ! ( options && options . writableObjectMode ) ;
74
76
75
77
// The point at which write() starts returning false
76
78
// Note: 0 is a valid value, means that we always return false if
77
79
// the entire buffer is not flushed immediately on write()
78
- this . highWaterMark = getHighWaterMark ( this , options , 'writableHighWaterMark' ,
79
- isDuplex ) ;
80
+ this . highWaterMark = options ?
81
+ getHighWaterMark ( this , options , 'writableHighWaterMark' , isDuplex ) :
82
+ getDefaultHighWaterMark ( false ) ;
80
83
81
84
// if _final has been called
82
85
this . finalCalled = false ;
@@ -96,13 +99,13 @@ function WritableState(options, stream, isDuplex) {
96
99
// Should we decode strings into buffers before passing to _write?
97
100
// this is here so that some node-core streams can optimize string
98
101
// handling at a lower level.
99
- const noDecode = options . decodeStrings === false ;
102
+ const noDecode = ! ! ( options && options . decodeStrings === false ) ;
100
103
this . decodeStrings = ! noDecode ;
101
104
102
105
// Crypto is kind of old and crusty. Historically, its default string
103
106
// encoding is 'binary' so we have to make this configurable.
104
107
// Everything else in the universe uses 'utf8', though.
105
- this . defaultEncoding = options . defaultEncoding || 'utf8' ;
108
+ this . defaultEncoding = ( options && options . defaultEncoding ) || 'utf8' ;
106
109
107
110
// Not an actual buffer we keep track of, but a measurement
108
111
// of how much we're waiting to get pushed to some underlying
@@ -150,10 +153,10 @@ function WritableState(options, stream, isDuplex) {
150
153
this . errorEmitted = false ;
151
154
152
155
// Should close be emitted on destroy. Defaults to true.
153
- this . emitClose = options . emitClose !== false ;
156
+ this . emitClose = ! options || options . emitClose !== false ;
154
157
155
158
// Should .destroy() be called after 'finish' (and potentially 'end')
156
- this . autoDestroy = ! ! options . autoDestroy ;
159
+ this . autoDestroy = ! ! ( options && options . autoDestroy ) ;
157
160
158
161
// Count buffered requests
159
162
this . bufferedRequestCount = 0 ;
0 commit comments