-
Notifications
You must be signed in to change notification settings - Fork 29.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stream: check type and range of highWaterMark #13065
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,11 +51,20 @@ 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; | ||
var defaultHwm = this.objectMode ? 16 : 16 * 1024; | ||
this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm; | ||
if (hwm == null) { | ||
this.highWaterMark = this.objectMode ? 16 : 16 * 1024; | ||
} else { | ||
if (typeof hwm !== 'number') { | ||
throw new TypeError('"highWaterMark" must be a number'); | ||
} | ||
|
||
// cast to ints. | ||
this.highWaterMark = Math.floor(this.highWaterMark); | ||
if (hwm < 0) { | ||
throw new RangeError('"highWaterMark" must not be negative'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be nice if the internal error types would be used for all new errors. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not actually the case for streams. It's a way bigger chunk of work that we need to do, as we would have to support them in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see, thanks for the update 👍 |
||
} | ||
|
||
// cast to ints. | ||
this.highWaterMark = Math.floor(hwm); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend to move this part into a generic function that can be called by readable and writable stream to prevent code duplication. This also keeps it always in line as the limits stay the same in both cases. |
||
|
||
// drain event flag. | ||
this.needDrain = false; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I think it's better to start a comment with upper case. The same in the other file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is a remainder from the old code.