mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
9b24be1340
This commit aims to reduce some code duplication in state.js PR-URL: https://github.com/nodejs/node/pull/20415 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
27 lines
702 B
JavaScript
27 lines
702 B
JavaScript
'use strict';
|
|
|
|
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
|
|
};
|