mirror of
https://github.com/nodejs/node.git
synced 2025-05-10 14:09:34 +00:00

PR-URL: https://github.com/nodejs/node/pull/30686 Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
37 lines
881 B
JavaScript
37 lines
881 B
JavaScript
'use strict';
|
|
|
|
const {
|
|
MathFloor,
|
|
NumberIsInteger,
|
|
} = primordials;
|
|
|
|
const { ERR_INVALID_OPT_VALUE } = require('internal/errors').codes;
|
|
|
|
function highWaterMarkFrom(options, isDuplex, duplexKey) {
|
|
return options.highWaterMark != null ? options.highWaterMark :
|
|
isDuplex ? options[duplexKey] : null;
|
|
}
|
|
|
|
function getDefaultHighWaterMark(objectMode) {
|
|
return objectMode ? 16 : 16 * 1024;
|
|
}
|
|
|
|
function getHighWaterMark(state, options, duplexKey, isDuplex) {
|
|
const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
|
|
if (hwm != null) {
|
|
if (!NumberIsInteger(hwm) || hwm < 0) {
|
|
const name = isDuplex ? duplexKey : 'highWaterMark';
|
|
throw new ERR_INVALID_OPT_VALUE(name, hwm);
|
|
}
|
|
return MathFloor(hwm);
|
|
}
|
|
|
|
// Default value
|
|
return getDefaultHighWaterMark(state.objectMode);
|
|
}
|
|
|
|
module.exports = {
|
|
getHighWaterMark,
|
|
getDefaultHighWaterMark
|
|
};
|