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