1'use strict'; 2 3const { 4 MathFloor, 5 NumberIsInteger, 6} = primordials; 7 8const { ERR_INVALID_OPT_VALUE } = require('internal/errors').codes; 9 10function highWaterMarkFrom(options, isDuplex, duplexKey) { 11 return options.highWaterMark != null ? options.highWaterMark : 12 isDuplex ? options[duplexKey] : null; 13} 14 15function getDefaultHighWaterMark(objectMode) { 16 return objectMode ? 16 : 16 * 1024; 17} 18 19function getHighWaterMark(state, options, duplexKey, isDuplex) { 20 const hwm = highWaterMarkFrom(options, isDuplex, duplexKey); 21 if (hwm != null) { 22 if (!NumberIsInteger(hwm) || hwm < 0) { 23 const name = isDuplex ? duplexKey : 'highWaterMark'; 24 throw new ERR_INVALID_OPT_VALUE(name, hwm); 25 } 26 return MathFloor(hwm); 27 } 28 29 // Default value 30 return getDefaultHighWaterMark(state.objectMode); 31} 32 33module.exports = { 34 getHighWaterMark, 35 getDefaultHighWaterMark 36}; 37