@@ -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 ;
0 commit comments