source: trip-planner-front/node_modules/@nodelib/fs.walk/out/readers/sync.js@ 8d391a1

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

initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const fsScandir = require("@nodelib/fs.scandir");
4const common = require("./common");
5const reader_1 = require("./reader");
6class SyncReader extends reader_1.default {
7 constructor() {
8 super(...arguments);
9 this._scandir = fsScandir.scandirSync;
10 this._storage = [];
11 this._queue = new Set();
12 }
13 read() {
14 this._pushToQueue(this._root, this._settings.basePath);
15 this._handleQueue();
16 return this._storage;
17 }
18 _pushToQueue(directory, base) {
19 this._queue.add({ directory, base });
20 }
21 _handleQueue() {
22 for (const item of this._queue.values()) {
23 this._handleDirectory(item.directory, item.base);
24 }
25 }
26 _handleDirectory(directory, base) {
27 try {
28 const entries = this._scandir(directory, this._settings.fsScandirSettings);
29 for (const entry of entries) {
30 this._handleEntry(entry, base);
31 }
32 }
33 catch (error) {
34 this._handleError(error);
35 }
36 }
37 _handleError(error) {
38 if (!common.isFatalError(this._settings, error)) {
39 return;
40 }
41 throw error;
42 }
43 _handleEntry(entry, base) {
44 const fullpath = entry.path;
45 if (base !== undefined) {
46 entry.path = common.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator);
47 }
48 if (common.isAppliedFilter(this._settings.entryFilter, entry)) {
49 this._pushToStorage(entry);
50 }
51 if (entry.dirent.isDirectory() && common.isAppliedFilter(this._settings.deepFilter, entry)) {
52 this._pushToQueue(fullpath, base === undefined ? undefined : entry.path);
53 }
54 }
55 _pushToStorage(entry) {
56 this._storage.push(entry);
57 }
58}
59exports.default = SyncReader;
Note: See TracBrowser for help on using the repository browser.