@@ -34,7 +34,10 @@ const internalUtil = require('internal/util');
3434const Stream = require ( 'stream' ) ;
3535const { Buffer } = require ( 'buffer' ) ;
3636const destroyImpl = require ( 'internal/streams/destroy' ) ;
37- const { getHighWaterMark } = require ( 'internal/streams/state' ) ;
37+ const {
38+ getHighWaterMark,
39+ getDefaultHighWaterMark
40+ } = require ( 'internal/streams/state' ) ;
3841const {
3942 ERR_INVALID_ARG_TYPE ,
4043 ERR_METHOD_NOT_IMPLEMENTED ,
@@ -54,8 +57,6 @@ Object.setPrototypeOf(Writable, Stream);
5457function nop ( ) { }
5558
5659function WritableState ( options , stream , isDuplex ) {
57- options = options || { } ;
58-
5960 // Duplex streams are both readable and writable, but share
6061 // the same options object.
6162 // However, some cases require setting options to different
@@ -66,16 +67,18 @@ function WritableState(options, stream, isDuplex) {
6667
6768 // Object stream flag to indicate whether or not this stream
6869 // contains buffers or objects.
69- this . objectMode = ! ! options . objectMode ;
70+ this . objectMode = ! ! ( options && options . objectMode ) ;
7071
7172 if ( isDuplex )
72- this . objectMode = this . objectMode || ! ! options . writableObjectMode ;
73+ this . objectMode = this . objectMode ||
74+ ! ! ( options && options . writableObjectMode ) ;
7375
7476 // The point at which write() starts returning false
7577 // Note: 0 is a valid value, means that we always return false if
7678 // 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 ) ;
7982
8083 // if _final has been called
8184 this . finalCalled = false ;
@@ -95,13 +98,13 @@ function WritableState(options, stream, isDuplex) {
9598 // Should we decode strings into buffers before passing to _write?
9699 // this is here so that some node-core streams can optimize string
97100 // handling at a lower level.
98- const noDecode = options . decodeStrings === false ;
101+ const noDecode = ! ! ( options && options . decodeStrings === false ) ;
99102 this . decodeStrings = ! noDecode ;
100103
101104 // Crypto is kind of old and crusty. Historically, its default string
102105 // encoding is 'binary' so we have to make this configurable.
103106 // Everything else in the universe uses 'utf8', though.
104- this . defaultEncoding = options . defaultEncoding || 'utf8' ;
107+ this . defaultEncoding = ( options && options . defaultEncoding ) || 'utf8' ;
105108
106109 // Not an actual buffer we keep track of, but a measurement
107110 // of how much we're waiting to get pushed to some underlying
@@ -149,10 +152,10 @@ function WritableState(options, stream, isDuplex) {
149152 this . errorEmitted = false ;
150153
151154 // Should close be emitted on destroy. Defaults to true.
152- this . emitClose = options . emitClose !== false ;
155+ this . emitClose = ! options || options . emitClose !== false ;
153156
154157 // Should .destroy() be called after 'finish' (and potentially 'end')
155- this . autoDestroy = ! ! options . autoDestroy ;
158+ this . autoDestroy = ! ! ( options && options . autoDestroy ) ;
156159
157160 // Count buffered requests
158161 this . bufferedRequestCount = 0 ;
0 commit comments