state.js 745 B

12345678910111213141516171819202122
  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. }
  15. // Default value
  16. return state.objectMode ? 16 : 16 * 1024;
  17. }
  18. module.exports = {
  19. getHighWaterMark: getHighWaterMark
  20. };