You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
2.5 KiB

4 years ago
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var stream = require("stream");
  17. var fsStat = require("@nodelib/fs.stat");
  18. var fs_1 = require("./fs");
  19. var FileSystemStream = /** @class */ (function (_super) {
  20. __extends(FileSystemStream, _super);
  21. function FileSystemStream() {
  22. return _super !== null && _super.apply(this, arguments) || this;
  23. }
  24. /**
  25. * Use stream API to read entries for Task.
  26. */
  27. FileSystemStream.prototype.read = function (patterns, filter) {
  28. var _this = this;
  29. var filepaths = patterns.map(this.getFullEntryPath, this);
  30. var transform = new stream.Transform({ objectMode: true });
  31. transform._transform = function (index, _enc, done) {
  32. return _this.getEntry(filepaths[index], patterns[index]).then(function (entry) {
  33. if (entry !== null && filter(entry)) {
  34. transform.push(entry);
  35. }
  36. if (index === filepaths.length - 1) {
  37. transform.end();
  38. }
  39. done();
  40. });
  41. };
  42. for (var i = 0; i < filepaths.length; i++) {
  43. transform.write(i);
  44. }
  45. return transform;
  46. };
  47. /**
  48. * Return entry for the provided path.
  49. */
  50. FileSystemStream.prototype.getEntry = function (filepath, pattern) {
  51. var _this = this;
  52. return this.getStat(filepath)
  53. .then(function (stat) { return _this.makeEntry(stat, pattern); })
  54. .catch(function () { return null; });
  55. };
  56. /**
  57. * Return fs.Stats for the provided path.
  58. */
  59. FileSystemStream.prototype.getStat = function (filepath) {
  60. return fsStat.stat(filepath, { throwErrorOnBrokenSymlinks: false });
  61. };
  62. return FileSystemStream;
  63. }(fs_1.default));
  64. exports.default = FileSystemStream;