• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3var ERR_INVALID_OPT_VALUE = require('../../../errors').codes.ERR_INVALID_OPT_VALUE;
4
5function highWaterMarkFrom(options, isDuplex, duplexKey) {
6  return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null;
7}
8
9function getHighWaterMark(state, options, duplexKey, isDuplex) {
10  var hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
11
12  if (hwm != null) {
13    if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) {
14      var name = isDuplex ? duplexKey : 'highWaterMark';
15      throw new ERR_INVALID_OPT_VALUE(name, hwm);
16    }
17
18    return Math.floor(hwm);
19  } // Default value
20
21
22  return state.objectMode ? 16 : 16 * 1024;
23}
24
25module.exports = {
26  getHighWaterMark: getHighWaterMark
27};