index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
  5. var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1662612701769, function(require, module, exports) {
  8. var Stream = require('stream').Stream;
  9. var util = require('util');
  10. module.exports = DelayedStream;
  11. function DelayedStream() {
  12. this.source = null;
  13. this.dataSize = 0;
  14. this.maxDataSize = 1024 * 1024;
  15. this.pauseStream = true;
  16. this._maxDataSizeExceeded = false;
  17. this._released = false;
  18. this._bufferedEvents = [];
  19. }
  20. util.inherits(DelayedStream, Stream);
  21. DelayedStream.create = function(source, options) {
  22. var delayedStream = new this();
  23. options = options || {};
  24. for (var option in options) {
  25. delayedStream[option] = options[option];
  26. }
  27. delayedStream.source = source;
  28. var realEmit = source.emit;
  29. source.emit = function() {
  30. delayedStream._handleEmit(arguments);
  31. return realEmit.apply(source, arguments);
  32. };
  33. source.on('error', function() {});
  34. if (delayedStream.pauseStream) {
  35. source.pause();
  36. }
  37. return delayedStream;
  38. };
  39. Object.defineProperty(DelayedStream.prototype, 'readable', {
  40. configurable: true,
  41. enumerable: true,
  42. get: function() {
  43. return this.source.readable;
  44. }
  45. });
  46. DelayedStream.prototype.setEncoding = function() {
  47. return this.source.setEncoding.apply(this.source, arguments);
  48. };
  49. DelayedStream.prototype.resume = function() {
  50. if (!this._released) {
  51. this.release();
  52. }
  53. this.source.resume();
  54. };
  55. DelayedStream.prototype.pause = function() {
  56. this.source.pause();
  57. };
  58. DelayedStream.prototype.release = function() {
  59. this._released = true;
  60. this._bufferedEvents.forEach(function(args) {
  61. this.emit.apply(this, args);
  62. }.bind(this));
  63. this._bufferedEvents = [];
  64. };
  65. DelayedStream.prototype.pipe = function() {
  66. var r = Stream.prototype.pipe.apply(this, arguments);
  67. this.resume();
  68. return r;
  69. };
  70. DelayedStream.prototype._handleEmit = function(args) {
  71. if (this._released) {
  72. this.emit.apply(this, args);
  73. return;
  74. }
  75. if (args[0] === 'data') {
  76. this.dataSize += args[1].length;
  77. this._checkIfMaxDataSizeExceeded();
  78. }
  79. this._bufferedEvents.push(args);
  80. };
  81. DelayedStream.prototype._checkIfMaxDataSizeExceeded = function() {
  82. if (this._maxDataSizeExceeded) {
  83. return;
  84. }
  85. if (this.dataSize <= this.maxDataSize) {
  86. return;
  87. }
  88. this._maxDataSizeExceeded = true;
  89. var message =
  90. 'DelayedStream#maxDataSize of ' + this.maxDataSize + ' bytes exceeded.'
  91. this.emit('error', new Error(message));
  92. };
  93. }, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); })
  94. return __REQUIRE__(1662612701769);
  95. })()
  96. //miniprogram-npm-outsideDeps=["stream","util"]
  97. //# sourceMappingURL=index.js.map