0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 15:30:56 +01:00
nodejs/lib/internal/streams/state.js
Robert Nagy c065773cc5 http: buffer writes even while no socket assigned
PR-URL: https://github.com/nodejs/node/pull/29019
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2019-08-09 15:55:35 -07:00

34 lines
856 B
JavaScript

'use strict';
const { Math } = primordials;
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 getDefaultHighWaterMark(objectMode) {
return objectMode ? 16 : 16 * 1024;
}
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 getDefaultHighWaterMark(state.objectMode);
}
module.exports = {
getHighWaterMark,
getDefaultHighWaterMark
};