2018-01-09 20:39:29 +01:00
|
|
|
'use strict';
|
|
|
|
|
2019-11-22 18:04:46 +01:00
|
|
|
const {
|
|
|
|
MathFloor,
|
2019-11-27 19:59:29 +01:00
|
|
|
NumberIsInteger,
|
2019-11-22 18:04:46 +01:00
|
|
|
} = primordials;
|
2019-03-31 13:30:12 +02:00
|
|
|
|
2020-08-08 19:01:59 +03:00
|
|
|
const { ERR_INVALID_ARG_VALUE } = require('internal/errors').codes;
|
2018-01-09 20:39:29 +01:00
|
|
|
|
2018-04-30 07:14:00 +02:00
|
|
|
function highWaterMarkFrom(options, isDuplex, duplexKey) {
|
|
|
|
return options.highWaterMark != null ? options.highWaterMark :
|
|
|
|
isDuplex ? options[duplexKey] : null;
|
|
|
|
}
|
|
|
|
|
2019-08-06 15:46:34 +02:00
|
|
|
function getDefaultHighWaterMark(objectMode) {
|
|
|
|
return objectMode ? 16 : 16 * 1024;
|
|
|
|
}
|
|
|
|
|
2018-01-09 20:39:29 +01:00
|
|
|
function getHighWaterMark(state, options, duplexKey, isDuplex) {
|
2018-04-30 07:14:00 +02:00
|
|
|
const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
|
2018-01-09 20:39:29 +01:00
|
|
|
if (hwm != null) {
|
2019-11-27 19:59:29 +01:00
|
|
|
if (!NumberIsInteger(hwm) || hwm < 0) {
|
2020-08-08 19:01:59 +03:00
|
|
|
const name = isDuplex ? `options.${duplexKey}` : 'options.highWaterMark';
|
|
|
|
throw new ERR_INVALID_ARG_VALUE(name, hwm);
|
2018-01-09 20:39:29 +01:00
|
|
|
}
|
2019-11-22 18:04:46 +01:00
|
|
|
return MathFloor(hwm);
|
2018-01-09 20:39:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default value
|
2019-08-06 15:46:34 +02:00
|
|
|
return getDefaultHighWaterMark(state.objectMode);
|
2018-01-09 20:39:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2019-08-06 15:46:34 +02:00
|
|
|
getHighWaterMark,
|
2023-02-18 18:53:57 +01:00
|
|
|
getDefaultHighWaterMark,
|
2018-01-09 20:39:29 +01:00
|
|
|
};
|