stream-base64.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. "use strict";
  2. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  5. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  6. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  7. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  8. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  9. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  10. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  11. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  12. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  13. var Stream = require('readable-stream'); // =============================================================================
  14. // StreamBase64 - A utility to convert to/from base64 stream
  15. // Note: does not buffer data, must be piped
  16. var StreamBase64 = /*#__PURE__*/function (_Stream$Duplex) {
  17. _inherits(StreamBase64, _Stream$Duplex);
  18. var _super = _createSuper(StreamBase64);
  19. function StreamBase64() {
  20. var _this;
  21. _classCallCheck(this, StreamBase64);
  22. _this = _super.call(this); // consuming pipe streams go here
  23. _this.pipes = [];
  24. return _this;
  25. } // writable
  26. // event drain - if write returns false (which it won't), indicates when safe to write again.
  27. // finish - end() has been called
  28. // pipe(src) - pipe() has been called on readable
  29. // unpipe(src) - unpipe() has been called on readable
  30. // error - duh
  31. _createClass(StreamBase64, [{
  32. key: "write",
  33. value: function write()
  34. /* data, encoding */
  35. {
  36. return true;
  37. }
  38. }, {
  39. key: "cork",
  40. value: function cork() {}
  41. }, {
  42. key: "uncork",
  43. value: function uncork() {}
  44. }, {
  45. key: "end",
  46. value: function end()
  47. /* chunk, encoding, callback */
  48. {} // readable
  49. // event readable - some data is now available
  50. // event data - switch to flowing mode - feeds chunks to handler
  51. // event end - no more data
  52. // event close - optional, indicates upstream close
  53. // event error - duh
  54. }, {
  55. key: "read",
  56. value: function read()
  57. /* size */
  58. {}
  59. }, {
  60. key: "setEncoding",
  61. value: function setEncoding(encoding) {
  62. // causes stream.read or stream.on('data) to return strings of encoding instead of Buffer objects
  63. this.encoding = encoding;
  64. }
  65. }, {
  66. key: "pause",
  67. value: function pause() {}
  68. }, {
  69. key: "resume",
  70. value: function resume() {}
  71. }, {
  72. key: "isPaused",
  73. value: function isPaused() {}
  74. }, {
  75. key: "pipe",
  76. value: function pipe(destination) {
  77. // add destination to pipe list & write current buffer
  78. this.pipes.push(destination);
  79. }
  80. }, {
  81. key: "unpipe",
  82. value: function unpipe(destination) {
  83. // remove destination from pipe list
  84. this.pipes = this.pipes.filter(function (pipe) {
  85. return pipe !== destination;
  86. });
  87. }
  88. }, {
  89. key: "unshift",
  90. value: function unshift()
  91. /* chunk */
  92. {
  93. // some numpty has read some data that's not for them and they want to put it back!
  94. // Might implement this some day
  95. throw new Error('Not Implemented');
  96. }
  97. }, {
  98. key: "wrap",
  99. value: function wrap()
  100. /* stream */
  101. {
  102. // not implemented
  103. throw new Error('Not Implemented');
  104. }
  105. }]);
  106. return StreamBase64;
  107. }(Stream.Duplex);
  108. module.exports = StreamBase64;
  109. //# sourceMappingURL=stream-base64.js.map