All files / lib/internal/streams state.js

100% Statements 36/36
100% Branches 17/17
100% Functions 3/3
100% Lines 36/36

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3717x 17x 17x 17x 17x 17x 17x 17x 17x 149848x 149848x 149848x 149848x 17x 178631x 178631x 178631x 17x 149848x 149848x 149848x 18963x 14x 14x 14x 18949x 18949x 130885x 130885x 130885x 149848x 17x 17x 17x 17x 17x  
'use strict';
 
const {
  MathFloor,
  NumberIsInteger,
} = primordials;
 
const { ERR_INVALID_ARG_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 (!NumberIsInteger(hwm) || hwm < 0) {
      const name = isDuplex ? `options.${duplexKey}` : 'options.highWaterMark';
      throw new ERR_INVALID_ARG_VALUE(name, hwm);
    }
    return MathFloor(hwm);
  }
 
  // Default value
  return getDefaultHighWaterMark(state.objectMode);
}
 
module.exports = {
  getHighWaterMark,
  getDefaultHighWaterMark
};