mirror of
https://github.com/nodejs/node.git
synced 2025-05-13 09:12:56 +00:00

PR-URL: https://github.com/nodejs/node/pull/46686 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
37 lines
903 B
JavaScript
37 lines
903 B
JavaScript
'use strict';
|
|
|
|
const {
|
|
MathFloor,
|
|
NumberIsInteger,
|
|
} = primordials;
|
|
|
|
const { ERR_INVALID_ARG_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 ? `options.${duplexKey}` : 'options.highWaterMark';
|
|
throw new ERR_INVALID_ARG_VALUE(name, hwm);
|
|
}
|
|
return MathFloor(hwm);
|
|
}
|
|
|
|
// Default value
|
|
return getDefaultHighWaterMark(state.objectMode);
|
|
}
|
|
|
|
module.exports = {
|
|
getHighWaterMark,
|
|
getDefaultHighWaterMark,
|
|
};
|