69284449be01d0d2b7b0118694e6b3190539fc533ff3bca5d6205e22e4683c0fc98796cf75a38b16c2b13df01f61ba7fefe7a8639b39b2186ed621554617ef 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. };