index.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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__(1682324647468, function(require, module, exports) {
  8. var stream = require('readable-stream')
  9. var eos = require('end-of-stream')
  10. var inherits = require('inherits')
  11. var shift = require('stream-shift')
  12. var SIGNAL_FLUSH = (Buffer.from && Buffer.from !== Uint8Array.from)
  13. ? Buffer.from([0])
  14. : new Buffer([0])
  15. var onuncork = function(self, fn) {
  16. if (self._corked) self.once('uncork', fn)
  17. else fn()
  18. }
  19. var autoDestroy = function (self, err) {
  20. if (self._autoDestroy) self.destroy(err)
  21. }
  22. var destroyer = function(self, end) {
  23. return function(err) {
  24. if (err) autoDestroy(self, err.message === 'premature close' ? null : err)
  25. else if (end && !self._ended) self.end()
  26. }
  27. }
  28. var end = function(ws, fn) {
  29. if (!ws) return fn()
  30. if (ws._writableState && ws._writableState.finished) return fn()
  31. if (ws._writableState) return ws.end(fn)
  32. ws.end()
  33. fn()
  34. }
  35. var noop = function() {}
  36. var toStreams2 = function(rs) {
  37. return new (stream.Readable)({objectMode:true, highWaterMark:16}).wrap(rs)
  38. }
  39. var Duplexify = function(writable, readable, opts) {
  40. if (!(this instanceof Duplexify)) return new Duplexify(writable, readable, opts)
  41. stream.Duplex.call(this, opts)
  42. this._writable = null
  43. this._readable = null
  44. this._readable2 = null
  45. this._autoDestroy = !opts || opts.autoDestroy !== false
  46. this._forwardDestroy = !opts || opts.destroy !== false
  47. this._forwardEnd = !opts || opts.end !== false
  48. this._corked = 1 // start corked
  49. this._ondrain = null
  50. this._drained = false
  51. this._forwarding = false
  52. this._unwrite = null
  53. this._unread = null
  54. this._ended = false
  55. this.destroyed = false
  56. if (writable) this.setWritable(writable)
  57. if (readable) this.setReadable(readable)
  58. }
  59. inherits(Duplexify, stream.Duplex)
  60. Duplexify.obj = function(writable, readable, opts) {
  61. if (!opts) opts = {}
  62. opts.objectMode = true
  63. opts.highWaterMark = 16
  64. return new Duplexify(writable, readable, opts)
  65. }
  66. Duplexify.prototype.cork = function() {
  67. if (++this._corked === 1) this.emit('cork')
  68. }
  69. Duplexify.prototype.uncork = function() {
  70. if (this._corked && --this._corked === 0) this.emit('uncork')
  71. }
  72. Duplexify.prototype.setWritable = function(writable) {
  73. if (this._unwrite) this._unwrite()
  74. if (this.destroyed) {
  75. if (writable && writable.destroy) writable.destroy()
  76. return
  77. }
  78. if (writable === null || writable === false) {
  79. this.end()
  80. return
  81. }
  82. var self = this
  83. var unend = eos(writable, {writable:true, readable:false}, destroyer(this, this._forwardEnd))
  84. var ondrain = function() {
  85. var ondrain = self._ondrain
  86. self._ondrain = null
  87. if (ondrain) ondrain()
  88. }
  89. var clear = function() {
  90. self._writable.removeListener('drain', ondrain)
  91. unend()
  92. }
  93. if (this._unwrite) process.nextTick(ondrain) // force a drain on stream reset to avoid livelocks
  94. this._writable = writable
  95. this._writable.on('drain', ondrain)
  96. this._unwrite = clear
  97. this.uncork() // always uncork setWritable
  98. }
  99. Duplexify.prototype.setReadable = function(readable) {
  100. if (this._unread) this._unread()
  101. if (this.destroyed) {
  102. if (readable && readable.destroy) readable.destroy()
  103. return
  104. }
  105. if (readable === null || readable === false) {
  106. this.push(null)
  107. this.resume()
  108. return
  109. }
  110. var self = this
  111. var unend = eos(readable, {writable:false, readable:true}, destroyer(this))
  112. var onreadable = function() {
  113. self._forward()
  114. }
  115. var onend = function() {
  116. self.push(null)
  117. }
  118. var clear = function() {
  119. self._readable2.removeListener('readable', onreadable)
  120. self._readable2.removeListener('end', onend)
  121. unend()
  122. }
  123. this._drained = true
  124. this._readable = readable
  125. this._readable2 = readable._readableState ? readable : toStreams2(readable)
  126. this._readable2.on('readable', onreadable)
  127. this._readable2.on('end', onend)
  128. this._unread = clear
  129. this._forward()
  130. }
  131. Duplexify.prototype._read = function() {
  132. this._drained = true
  133. this._forward()
  134. }
  135. Duplexify.prototype._forward = function() {
  136. if (this._forwarding || !this._readable2 || !this._drained) return
  137. this._forwarding = true
  138. var data
  139. while (this._drained && (data = shift(this._readable2)) !== null) {
  140. if (this.destroyed) continue
  141. this._drained = this.push(data)
  142. }
  143. this._forwarding = false
  144. }
  145. Duplexify.prototype.destroy = function(err, cb) {
  146. if (!cb) cb = noop
  147. if (this.destroyed) return cb(null)
  148. this.destroyed = true
  149. var self = this
  150. process.nextTick(function() {
  151. self._destroy(err)
  152. cb(null)
  153. })
  154. }
  155. Duplexify.prototype._destroy = function(err) {
  156. if (err) {
  157. var ondrain = this._ondrain
  158. this._ondrain = null
  159. if (ondrain) ondrain(err)
  160. else this.emit('error', err)
  161. }
  162. if (this._forwardDestroy) {
  163. if (this._readable && this._readable.destroy) this._readable.destroy()
  164. if (this._writable && this._writable.destroy) this._writable.destroy()
  165. }
  166. this.emit('close')
  167. }
  168. Duplexify.prototype._write = function(data, enc, cb) {
  169. if (this.destroyed) return
  170. if (this._corked) return onuncork(this, this._write.bind(this, data, enc, cb))
  171. if (data === SIGNAL_FLUSH) return this._finish(cb)
  172. if (!this._writable) return cb()
  173. if (this._writable.write(data) === false) this._ondrain = cb
  174. else if (!this.destroyed) cb()
  175. }
  176. Duplexify.prototype._finish = function(cb) {
  177. var self = this
  178. this.emit('preend')
  179. onuncork(this, function() {
  180. end(self._forwardEnd && self._writable, function() {
  181. // haxx to not emit prefinish twice
  182. if (self._writableState.prefinished === false) self._writableState.prefinished = true
  183. self.emit('prefinish')
  184. onuncork(self, cb)
  185. })
  186. })
  187. }
  188. Duplexify.prototype.end = function(data, enc, cb) {
  189. if (typeof data === 'function') return this.end(null, null, data)
  190. if (typeof enc === 'function') return this.end(data, null, enc)
  191. this._ended = true
  192. if (data) this.write(data)
  193. if (!this._writableState.ending && !this._writableState.destroyed) this.write(SIGNAL_FLUSH)
  194. return stream.Writable.prototype.end.call(this, cb)
  195. }
  196. module.exports = Duplexify
  197. }, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); })
  198. return __REQUIRE__(1682324647468);
  199. })()
  200. //miniprogram-npm-outsideDeps=["readable-stream","end-of-stream","inherits","stream-shift"]
  201. //# sourceMappingURL=index.js.map