// cast to an int
this.bufferSize = ~~this.bufferSize;
- this.lowWaterMark = options.lowWaterMark || 1024;
+ this.lowWaterMark = options.hasOwnProperty('lowWaterMark') ?
+ options.lowWaterMark : 1024;
this.buffer = [];
this.length = 0;
this.pipes = [];
// but then it won't ever cause _read to be called, so in that case,
// we just return what we have, and let the programmer deal with it.
if (n > state.length) {
- if (!state.ended && state.length < state.lowWaterMark) {
+ if (!state.ended && state.length <= state.lowWaterMark) {
state.needReadable = true;
n = 0;
} else
state.length -= n;
if (!state.ended &&
- state.length < state.lowWaterMark &&
+ state.length <= state.lowWaterMark &&
!state.reading) {
state.reading = true;
// call internal read method
// that it's time to read more data. Otherwise, that'll
// probably kick off another stream.read(), which can trigger
// another _read(n,cb) before this one returns!
- if (state.length < state.lowWaterMark) {
+ if (state.length <= state.lowWaterMark) {
state.reading = true;
this._read(state.bufferSize, onread.bind(this));
return;
var ret = fromList(n, state.buffer, state.length, !!state.decoder);
state.length -= n;
- if (state.length < state.lowWaterMark && paused) {
+ if (state.length <= state.lowWaterMark && paused) {
stream.resume();
paused = false;
}
function WritableState(options) {
options = options || {};
this.highWaterMark = options.highWaterMark || 16 * 1024;
- this.lowWaterMark = options.lowWaterMark || 1024;
+ this.highWaterMark = options.hasOwnProperty('highWaterMark') ?
+ options.highWaterMark : 16 * 1024;
+ this.lowWaterMark = options.hasOwnProperty('lowWaterMark') ?
+ options.lowWaterMark : 1024;
this.needDrain = false;
this.ended = false;
this.ending = false;
this._write(chunk, writecb.bind(this));
}
- if (state.length < state.lowWaterMark && state.needDrain) {
+ if (state.length <= state.lowWaterMark && state.needDrain) {
// Must force callback to be called on nextTick, so that we don't
// emit 'drain' before the write() consumer gets the 'false' return
// value, and has a chance to attach a 'drain' listener.