Permalink
Browse files

stream: change default hwm for objectMode to 16

  • Loading branch information...
1 parent ee695e9 commit ba72570eae938957d10494be28eac28ed75d256f @mafintosh mafintosh committed with isaacs Aug 22, 2013
Showing with 6 additions and 4 deletions.
  1. +2 −2 doc/api/stream.markdown
  2. +2 −1 lib/_stream_readable.js
  3. +2 −1 lib/_stream_writable.js
View
4 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
View
3 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;
View
3 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.

0 comments on commit ba72570

Please sign in to comment.