Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

stream.js 958B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const stream_1 = require("stream");
  4. const async_1 = require("../readers/async");
  5. class StreamProvider {
  6. constructor(_root, _settings) {
  7. this._root = _root;
  8. this._settings = _settings;
  9. this._reader = new async_1.default(this._root, this._settings);
  10. this._stream = new stream_1.Readable({
  11. objectMode: true,
  12. read: () => { },
  13. destroy: this._reader.destroy.bind(this._reader)
  14. });
  15. }
  16. read() {
  17. this._reader.onError((error) => {
  18. this._stream.emit('error', error);
  19. });
  20. this._reader.onEntry((entry) => {
  21. this._stream.push(entry);
  22. });
  23. this._reader.onEnd(() => {
  24. this._stream.push(null);
  25. });
  26. this._reader.read();
  27. return this._stream;
  28. }
  29. }
  30. exports.default = StreamProvider;