No Description

stream.js 1.2KB

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. const stream_1 = require("stream");
  4. const stream_2 = require("../readers/stream");
  5. const provider_1 = require("./provider");
  6. class ProviderStream extends provider_1.default {
  7. constructor() {
  8. super(...arguments);
  9. this._reader = new stream_2.default(this._settings);
  10. }
  11. read(task) {
  12. const root = this._getRootDirectory(task);
  13. const options = this._getReaderOptions(task);
  14. const source = this.api(root, task, options);
  15. const destination = new stream_1.Readable({ objectMode: true, read: () => { } });
  16. source
  17. .once('error', (error) => destination.emit('error', error))
  18. .on('data', (entry) => destination.emit('data', options.transform(entry)))
  19. .once('end', () => destination.emit('end'));
  20. destination
  21. .once('close', () => source.destroy());
  22. return destination;
  23. }
  24. api(root, task, options) {
  25. if (task.dynamic) {
  26. return this._reader.dynamic(root, options);
  27. }
  28. return this._reader.static(task.patterns, options);
  29. }
  30. }
  31. exports.default = ProviderStream;