| 24957 | function nop() {} |
| 24958 | |
| 24959 | function WritableState(options, stream) { |
| 24960 | Duplex = Duplex || require('./_stream_duplex'); |
| 24961 | |
| 24962 | options = options || {}; |
| 24963 | |
| 24964 | // Duplex streams are both readable and writable, but share |
| 24965 | // the same options object. |
| 24966 | // However, some cases require setting options to different |
| 24967 | // values for the readable and the writable sides of the duplex stream. |
| 24968 | // These options can be provided separately as readableXXX and writableXXX. |
| 24969 | var isDuplex = stream instanceof Duplex; |
| 24970 | |
| 24971 | // object stream flag to indicate whether or not this stream |
| 24972 | // contains buffers or objects. |
| 24973 | this.objectMode = !!options.objectMode; |
| 24974 | |
| 24975 | if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; |
| 24976 | |
| 24977 | // the point at which write() starts returning false |
| 24978 | // Note: 0 is a valid value, means that we always return false if |
| 24979 | // the entire buffer is not flushed immediately on write() |
| 24980 | var hwm = options.highWaterMark; |
| 24981 | var writableHwm = options.writableHighWaterMark; |
| 24982 | var defaultHwm = this.objectMode ? 16 : 16 * 1024; |
| 24983 | |
| 24984 | if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm; |
| 24985 | |
| 24986 | // cast to ints. |
| 24987 | this.highWaterMark = Math.floor(this.highWaterMark); |
| 24988 | |
| 24989 | // if _final has been called |
| 24990 | this.finalCalled = false; |
| 24991 | |
| 24992 | // drain event flag. |
| 24993 | this.needDrain = false; |
| 24994 | // at the start of calling end() |
| 24995 | this.ending = false; |
| 24996 | // when end() has been called, and returned |
| 24997 | this.ended = false; |
| 24998 | // when 'finish' is emitted |
| 24999 | this.finished = false; |
| 25000 | |
| 25001 | // has it been destroyed |
| 25002 | this.destroyed = false; |
| 25003 | |
| 25004 | // should we decode strings into buffers before passing to _write? |
| 25005 | // this is here so that some node-core streams can optimize string |
| 25006 | // handling at a lower level. |
| 25007 | var noDecode = options.decodeStrings === false; |
| 25008 | this.decodeStrings = !noDecode; |
| 25009 | |
| 25010 | // Crypto is kind of old and crusty. Historically, its default string |
| 25011 | // encoding is 'binary' so we have to make this configurable. |
| 25012 | // Everything else in the universe uses 'utf8', though. |
| 25013 | this.defaultEncoding = options.defaultEncoding || 'utf8'; |
| 25014 | |
| 25015 | // not an actual buffer we keep track of, but a measurement |
| 25016 | // of how much we're waiting to get pushed to some underlying |