From ba72570eae938957d10494be28eac28ed75d256f Mon Sep 17 00:00:00 2001 From: Mathias Buus Date: Thu, 22 Aug 2013 19:58:27 +0200 Subject: [PATCH] stream: change default hwm for objectMode to 16 --- doc/api/stream.markdown | 4 ++-- lib/_stream_readable.js | 3 ++- lib/_stream_writable.js | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/doc/api/stream.markdown b/doc/api/stream.markdown index 27c47b9..881b338 100644 --- a/doc/api/stream.markdown +++ b/doc/api/stream.markdown @@ -871,7 +871,7 @@ SimpleProtocol.prototype._read = function(n) { * `options` {Object} * `highWaterMark` {Number} The maximum number of bytes to store in the internal buffer before ceasing to read from the underlying - resource. Default=16kb + resource. Default=16kb, or 16 for `objectMode` streams * `encoding` {String} If specified, then buffers will be decoded to strings using the specified encoding. Default=null * `objectMode` {Boolean} Whether this stream should behave @@ -987,7 +987,7 @@ how to implement Writable streams in your programs. * `options` {Object} * `highWaterMark` {Number} Buffer level when [`write()`][] starts - returning false. Default=16kb + returning false. Default=16kb, or 16 for `objectMode` streams * `decodeStrings` {Boolean} Whether or not to decode strings into Buffers before passing them to [`_write()`][]. Default=true diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 0c3fe3e..95c044a 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -36,7 +36,8 @@ function ReadableState(options, stream) { // the point at which it stops calling _read() to fill the buffer // Note: 0 is a valid value, means "don't call _read preemptively ever" var hwm = options.highWaterMark; - this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024; + var defaultHwm = options.objectMode ? 16 : 16 * 1024; + this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm; // cast to ints. this.highWaterMark = ~~this.highWaterMark; diff --git a/lib/_stream_writable.js b/lib/_stream_writable.js index ba2e920..6404821 100644 --- a/lib/_stream_writable.js +++ b/lib/_stream_writable.js @@ -44,7 +44,8 @@ function WritableState(options, stream) { // Note: 0 is a valid value, means that we always return false if // the entire buffer is not flushed immediately on write() var hwm = options.highWaterMark; - this.highWaterMark = (hwm || hwm === 0) ? hwm : 16 * 1024; + var defaultHwm = options.objectMode ? 16 : 16 * 1024; + this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm; // object stream flag to indicate whether or not this stream // contains buffers or objects. -- 2.7.4