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

Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
36 lines
863 B
JavaScript
36 lines
863 B
JavaScript
'use strict';
|
|
|
|
const {
|
|
MathFloor,
|
|
} = 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 (!Number.isInteger(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
|
|
};
|