2018-01-09 20:39:29 +01:00
|
|
|
'use strict';
|
|
|
|
|
2019-03-31 13:30:12 +02:00
|
|
|
const { Math } = primordials;
|
|
|
|
|
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
|
|
|
|
2018-04-30 07:14:00 +02:00
|
|
|
function highWaterMarkFrom(options, isDuplex, duplexKey) {
|
|
|
|
return options.highWaterMark != null ? options.highWaterMark :
|
|
|
|
isDuplex ? options[duplexKey] : null;
|
|
|
|
}
|
|
|
|
|
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) {
|
2018-04-30 07:14:00 +02:00
|
|
|
if (!Number.isInteger(hwm) || hwm < 0) {
|
|
|
|
const name = isDuplex ? duplexKey : 'highWaterMark';
|
|
|
|
throw new ERR_INVALID_OPT_VALUE(name, hwm);
|
2018-01-09 20:39:29 +01:00
|
|
|
}
|
2018-04-30 07:14:00 +02:00
|
|
|
return Math.floor(hwm);
|
2018-01-09 20:39:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Default value
|
|
|
|
return state.objectMode ? 16 : 16 * 1024;
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
getHighWaterMark
|
|
|
|
};
|