stream-base64.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. "use strict";
  2. const Stream = require('readable-stream');
  3. // =============================================================================
  4. // StreamBase64 - A utility to convert to/from base64 stream
  5. // Note: does not buffer data, must be piped
  6. class StreamBase64 extends Stream.Duplex {
  7. constructor() {
  8. super();
  9. // consuming pipe streams go here
  10. this.pipes = [];
  11. }
  12. // writable
  13. // event drain - if write returns false (which it won't), indicates when safe to write again.
  14. // finish - end() has been called
  15. // pipe(src) - pipe() has been called on readable
  16. // unpipe(src) - unpipe() has been called on readable
  17. // error - duh
  18. write( /* data, encoding */
  19. ) {
  20. return true;
  21. }
  22. cork() {}
  23. uncork() {}
  24. end( /* chunk, encoding, callback */) {}
  25. // readable
  26. // event readable - some data is now available
  27. // event data - switch to flowing mode - feeds chunks to handler
  28. // event end - no more data
  29. // event close - optional, indicates upstream close
  30. // event error - duh
  31. read( /* size */) {}
  32. setEncoding(encoding) {
  33. // causes stream.read or stream.on('data) to return strings of encoding instead of Buffer objects
  34. this.encoding = encoding;
  35. }
  36. pause() {}
  37. resume() {}
  38. isPaused() {}
  39. pipe(destination) {
  40. // add destination to pipe list & write current buffer
  41. this.pipes.push(destination);
  42. }
  43. unpipe(destination) {
  44. // remove destination from pipe list
  45. this.pipes = this.pipes.filter(pipe => pipe !== destination);
  46. }
  47. unshift( /* chunk */
  48. ) {
  49. // some numpty has read some data that's not for them and they want to put it back!
  50. // Might implement this some day
  51. throw new Error('Not Implemented');
  52. }
  53. wrap( /* stream */
  54. ) {
  55. // not implemented
  56. throw new Error('Not Implemented');
  57. }
  58. }
  59. module.exports = StreamBase64;
  60. //# sourceMappingURL=stream-base64.js.map