source: trip-planner-front/node_modules/fast-glob/out/readers/stream.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[6a3a178]1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const stream_1 = require("stream");
4const fsStat = require("@nodelib/fs.stat");
5const fsWalk = require("@nodelib/fs.walk");
6const reader_1 = require("./reader");
7class ReaderStream extends reader_1.default {
8 constructor() {
9 super(...arguments);
10 this._walkStream = fsWalk.walkStream;
11 this._stat = fsStat.stat;
12 }
13 dynamic(root, options) {
14 return this._walkStream(root, options);
15 }
16 static(patterns, options) {
17 const filepaths = patterns.map(this._getFullEntryPath, this);
18 const stream = new stream_1.PassThrough({ objectMode: true });
19 stream._write = (index, _enc, done) => {
20 return this._getEntry(filepaths[index], patterns[index], options)
21 .then((entry) => {
22 if (entry !== null && options.entryFilter(entry)) {
23 stream.push(entry);
24 }
25 if (index === filepaths.length - 1) {
26 stream.end();
27 }
28 done();
29 })
30 .catch(done);
31 };
32 for (let i = 0; i < filepaths.length; i++) {
33 stream.write(i);
34 }
35 return stream;
36 }
37 _getEntry(filepath, pattern, options) {
38 return this._getStat(filepath)
39 .then((stats) => this._makeEntry(stats, pattern))
40 .catch((error) => {
41 if (options.errorFilter(error)) {
42 return null;
43 }
44 throw error;
45 });
46 }
47 _getStat(filepath) {
48 return new Promise((resolve, reject) => {
49 this._stat(filepath, this._fsStatSettings, (error, stats) => {
50 return error === null ? resolve(stats) : reject(error);
51 });
52 });
53 }
54}
55exports.default = ReaderStream;
Note: See TracBrowser for help on using the repository browser.