2 var __extends = (this && this.__extends) || (function () {
\r
3 var extendStatics = function (d, b) {
\r
4 extendStatics = Object.setPrototypeOf ||
\r
5 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
\r
6 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
\r
7 return extendStatics(d, b);
\r
9 return function (d, b) {
\r
10 extendStatics(d, b);
\r
11 function __() { this.constructor = d; }
\r
12 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
\r
15 Object.defineProperty(exports, "__esModule", { value: true });
\r
16 var stream = require("stream");
\r
17 var readdir = require("@mrmlnc/readdir-enhanced");
\r
18 var reader_1 = require("./reader");
\r
19 var fs_stream_1 = require("../adapters/fs-stream");
\r
20 var TransformStream = /** @class */ (function (_super) {
\r
21 __extends(TransformStream, _super);
\r
22 function TransformStream(reader) {
\r
23 var _this = _super.call(this, { objectMode: true }) || this;
\r
24 _this.reader = reader;
\r
27 TransformStream.prototype._transform = function (entry, _encoding, callback) {
\r
28 callback(null, this.reader.transform(entry));
\r
30 return TransformStream;
\r
31 }(stream.Transform));
\r
32 var ReaderStream = /** @class */ (function (_super) {
\r
33 __extends(ReaderStream, _super);
\r
34 function ReaderStream() {
\r
35 return _super !== null && _super.apply(this, arguments) || this;
\r
37 Object.defineProperty(ReaderStream.prototype, "fsAdapter", {
\r
39 * Returns FileSystem adapter.
\r
42 return new fs_stream_1.default(this.options);
\r
48 * Use stream API to read entries for Task.
\r
50 ReaderStream.prototype.read = function (task) {
\r
52 var root = this.getRootDirectory(task);
\r
53 var options = this.getReaderOptions(task);
\r
54 var transform = new TransformStream(this);
\r
55 var readable = this.api(root, task, options);
\r
57 .on('error', function (err) { return _this.isEnoentCodeError(err) ? null : transform.emit('error', err); })
\r
61 * Returns founded paths.
\r
63 ReaderStream.prototype.api = function (root, task, options) {
\r
65 return this.dynamicApi(root, options);
\r
67 return this.staticApi(task, options);
\r
70 * Api for dynamic tasks.
\r
72 ReaderStream.prototype.dynamicApi = function (root, options) {
\r
73 return readdir.readdirStreamStat(root, options);
\r
76 * Api for static tasks.
\r
78 ReaderStream.prototype.staticApi = function (task, options) {
\r
79 return this.fsAdapter.read(task.patterns, options.filter);
\r
81 return ReaderStream;
\r
82 }(reader_1.default));
\r
83 exports.default = ReaderStream;
\r