--- /dev/null
+"use strict";\r
+var __extends = (this && this.__extends) || (function () {\r
+ var extendStatics = function (d, b) {\r
+ extendStatics = Object.setPrototypeOf ||\r
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\r
+ function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\r
+ return extendStatics(d, b);\r
+ };\r
+ return function (d, b) {\r
+ extendStatics(d, b);\r
+ function __() { this.constructor = d; }\r
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\r
+ };\r
+})();\r
+Object.defineProperty(exports, "__esModule", { value: true });\r
+var stream = require("stream");\r
+var readdir = require("@mrmlnc/readdir-enhanced");\r
+var reader_1 = require("./reader");\r
+var fs_stream_1 = require("../adapters/fs-stream");\r
+var TransformStream = /** @class */ (function (_super) {\r
+ __extends(TransformStream, _super);\r
+ function TransformStream(reader) {\r
+ var _this = _super.call(this, { objectMode: true }) || this;\r
+ _this.reader = reader;\r
+ return _this;\r
+ }\r
+ TransformStream.prototype._transform = function (entry, _encoding, callback) {\r
+ callback(null, this.reader.transform(entry));\r
+ };\r
+ return TransformStream;\r
+}(stream.Transform));\r
+var ReaderStream = /** @class */ (function (_super) {\r
+ __extends(ReaderStream, _super);\r
+ function ReaderStream() {\r
+ return _super !== null && _super.apply(this, arguments) || this;\r
+ }\r
+ Object.defineProperty(ReaderStream.prototype, "fsAdapter", {\r
+ /**\r
+ * Returns FileSystem adapter.\r
+ */\r
+ get: function () {\r
+ return new fs_stream_1.default(this.options);\r
+ },\r
+ enumerable: true,\r
+ configurable: true\r
+ });\r
+ /**\r
+ * Use stream API to read entries for Task.\r
+ */\r
+ ReaderStream.prototype.read = function (task) {\r
+ var _this = this;\r
+ var root = this.getRootDirectory(task);\r
+ var options = this.getReaderOptions(task);\r
+ var transform = new TransformStream(this);\r
+ var readable = this.api(root, task, options);\r
+ return readable\r
+ .on('error', function (err) { return _this.isEnoentCodeError(err) ? null : transform.emit('error', err); })\r
+ .pipe(transform);\r
+ };\r
+ /**\r
+ * Returns founded paths.\r
+ */\r
+ ReaderStream.prototype.api = function (root, task, options) {\r
+ if (task.dynamic) {\r
+ return this.dynamicApi(root, options);\r
+ }\r
+ return this.staticApi(task, options);\r
+ };\r
+ /**\r
+ * Api for dynamic tasks.\r
+ */\r
+ ReaderStream.prototype.dynamicApi = function (root, options) {\r
+ return readdir.readdirStreamStat(root, options);\r
+ };\r
+ /**\r
+ * Api for static tasks.\r
+ */\r
+ ReaderStream.prototype.staticApi = function (task, options) {\r
+ return this.fsAdapter.read(task.patterns, options.filter);\r
+ };\r
+ return ReaderStream;\r
+}(reader_1.default));\r
+exports.default = ReaderStream;\r