-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: add type and range check for highWaterMark
The (h|readableH|writableH)ighWaterMark options should only permit positive numbers and zero. PR-URL: #18098 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
- Loading branch information
Showing
6 changed files
with
70 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
const errors = require('internal/errors'); | ||
|
||
function getHighWaterMark(state, options, duplexKey, isDuplex) { | ||
let hwm = options.highWaterMark; | ||
if (hwm != null) { | ||
if (typeof hwm !== 'number' || !(hwm >= 0)) | ||
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', 'highWaterMark', hwm); | ||
return Math.floor(hwm); | ||
} else if (isDuplex) { | ||
hwm = options[duplexKey]; | ||
if (hwm != null) { | ||
if (typeof hwm !== 'number' || !(hwm >= 0)) | ||
throw new errors.TypeError('ERR_INVALID_OPT_VALUE', duplexKey, hwm); | ||
return Math.floor(hwm); | ||
} | ||
} | ||
|
||
// Default value | ||
return state.objectMode ? 16 : 16 * 1024; | ||
} | ||
|
||
module.exports = { | ||
getHighWaterMark | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters