state.js 749 B

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