index.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. (function() {
  2. var nodeEnv = typeof require !== 'undefined' && typeof process !== 'undefined';
  3. var __module = nodeEnv ? module : {exports:{}};
  4. var __filename = 'preview-scripts/__node_modules/stream-browserify/index.js';
  5. var __require = nodeEnv ? function (request) {
  6. return cc.require(request);
  7. } : function (request) {
  8. return __quick_compile_project__.require(request, __filename);
  9. };
  10. function __define (exports, require, module) {
  11. if (!nodeEnv) {__quick_compile_project__.registerModule(__filename, module);}// Copyright Joyent, Inc. and other Node contributors.
  12. //
  13. // Permission is hereby granted, free of charge, to any person obtaining a
  14. // copy of this software and associated documentation files (the
  15. // "Software"), to deal in the Software without restriction, including
  16. // without limitation the rights to use, copy, modify, merge, publish,
  17. // distribute, sublicense, and/or sell copies of the Software, and to permit
  18. // persons to whom the Software is furnished to do so, subject to the
  19. // following conditions:
  20. //
  21. // The above copyright notice and this permission notice shall be included
  22. // in all copies or substantial portions of the Software.
  23. //
  24. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  25. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  26. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  27. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  28. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  29. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  30. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  31. module.exports = Stream;
  32. var EE = require('events').EventEmitter;
  33. var inherits = require('inherits');
  34. inherits(Stream, EE);
  35. Stream.Readable = require('readable-stream/readable.js');
  36. Stream.Writable = require('readable-stream/writable.js');
  37. Stream.Duplex = require('readable-stream/duplex.js');
  38. Stream.Transform = require('readable-stream/transform.js');
  39. Stream.PassThrough = require('readable-stream/passthrough.js');
  40. // Backwards-compat with node 0.4.x
  41. Stream.Stream = Stream;
  42. // old-style streams. Note that the pipe method (the only relevant
  43. // part of this class) is overridden in the Readable class.
  44. function Stream() {
  45. EE.call(this);
  46. }
  47. Stream.prototype.pipe = function(dest, options) {
  48. var source = this;
  49. function ondata(chunk) {
  50. if (dest.writable) {
  51. if (false === dest.write(chunk) && source.pause) {
  52. source.pause();
  53. }
  54. }
  55. }
  56. source.on('data', ondata);
  57. function ondrain() {
  58. if (source.readable && source.resume) {
  59. source.resume();
  60. }
  61. }
  62. dest.on('drain', ondrain);
  63. // If the 'end' option is not supplied, dest.end() will be called when
  64. // source gets the 'end' or 'close' events. Only dest.end() once.
  65. if (!dest._isStdio && (!options || options.end !== false)) {
  66. source.on('end', onend);
  67. source.on('close', onclose);
  68. }
  69. var didOnEnd = false;
  70. function onend() {
  71. if (didOnEnd) return;
  72. didOnEnd = true;
  73. dest.end();
  74. }
  75. function onclose() {
  76. if (didOnEnd) return;
  77. didOnEnd = true;
  78. if (typeof dest.destroy === 'function') dest.destroy();
  79. }
  80. // don't leave dangling pipes when there are errors.
  81. function onerror(er) {
  82. cleanup();
  83. if (EE.listenerCount(this, 'error') === 0) {
  84. throw er; // Unhandled stream error in pipe.
  85. }
  86. }
  87. source.on('error', onerror);
  88. dest.on('error', onerror);
  89. // remove all the event listeners that were added.
  90. function cleanup() {
  91. source.removeListener('data', ondata);
  92. dest.removeListener('drain', ondrain);
  93. source.removeListener('end', onend);
  94. source.removeListener('close', onclose);
  95. source.removeListener('error', onerror);
  96. dest.removeListener('error', onerror);
  97. source.removeListener('end', cleanup);
  98. source.removeListener('close', cleanup);
  99. dest.removeListener('close', cleanup);
  100. }
  101. source.on('end', cleanup);
  102. source.on('close', cleanup);
  103. dest.on('close', cleanup);
  104. dest.emit('pipe', source);
  105. // Allow for unix-like usage: A.pipe(B).pipe(C)
  106. return dest;
  107. };
  108. }
  109. if (nodeEnv) {
  110. __define(__module.exports, __require, __module);
  111. }
  112. else {
  113. __quick_compile_project__.registerModuleFunc(__filename, function () {
  114. __define(__module.exports, __require, __module);
  115. });
  116. }
  117. })();