mirror of
https://github.com/nodejs/node.git
synced 2025-05-02 18:26:52 +00:00

Use the "no-restricted-globals" ESLint rule to lint for it. PR-URL: https://github.com/nodejs/node/pull/27027 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
29 lines
733 B
JavaScript
29 lines
733 B
JavaScript
'use strict';
|
|
|
|
const { Math } = 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 getHighWaterMark(state, options, duplexKey, isDuplex) {
|
|
const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
|
|
if (hwm != null) {
|
|
if (!Number.isInteger(hwm) || hwm < 0) {
|
|
const name = isDuplex ? duplexKey : 'highWaterMark';
|
|
throw new ERR_INVALID_OPT_VALUE(name, hwm);
|
|
}
|
|
return Math.floor(hwm);
|
|
}
|
|
|
|
// Default value
|
|
return state.objectMode ? 16 : 16 * 1024;
|
|
}
|
|
|
|
module.exports = {
|
|
getHighWaterMark
|
|
};
|