node/lib/internal/streams/state.js
Michaël Zasso 1d2fd8b65b lib: port remaining errors to new system
PR-URL: https://github.com/nodejs/node/pull/19137
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-03-07 14:54:38 +01:00

27 lines
675 B
JavaScript

'use strict';
const { ERR_INVALID_OPT_VALUE } = require('internal/errors').codes;
function getHighWaterMark(state, options, duplexKey, isDuplex) {
let hwm = options.highWaterMark;
if (hwm != null) {
if (typeof hwm !== 'number' || !(hwm >= 0))
throw new ERR_INVALID_OPT_VALUE('highWaterMark', hwm);
return Math.floor(hwm);
} else if (isDuplex) {
hwm = options[duplexKey];
if (hwm != null) {
if (typeof hwm !== 'number' || !(hwm >= 0))
throw new ERR_INVALID_OPT_VALUE(duplexKey, hwm);
return Math.floor(hwm);
}
}
// Default value
return state.objectMode ? 16 : 16 * 1024;
}
module.exports = {
getHighWaterMark
};