"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Files = void 0; const fs_1 = require("fs"); const RJLog_1 = require("./RJLog"); class Files { static getFiles(filePath) { return __awaiter(this, void 0, void 0, function* () { return yield fs_1.promises.readdir(filePath); }); } static copy(from, to) { return __awaiter(this, void 0, void 0, function* () { return yield fs_1.promises.copyFile(from, to); }); } static getFilesRecursive(filePath) { return __awaiter(this, void 0, void 0, function* () { let files = yield fs_1.promises.readdir(filePath, { recursive: true }); return files; }); } static delete(filePath) { return __awaiter(this, void 0, void 0, function* () { yield fs_1.promises.unlink(filePath); return Promise.resolve(); }); } static isDirectory(filePath) { return __awaiter(this, void 0, void 0, function* () { let stats = yield fs_1.promises.stat(filePath); return stats.isDirectory(); }); } static exists(filePath) { return __awaiter(this, void 0, void 0, function* () { try { let stats = yield fs_1.promises.stat(filePath); let exists = stats !== undefined && stats !== null; return Promise.resolve(exists); } catch (e) { } return Promise.resolve(false); }); } static loadUTF8(filePath) { return __awaiter(this, void 0, void 0, function* () { try { let data = yield fs_1.promises.readFile(filePath); let stringData = data.toString(); return Promise.resolve(stringData); } catch (exception) { RJLog_1.RJLog.warn("loadUTF8: ", filePath); RJLog_1.RJLog.warn(exception); } return Promise.resolve(null); }); } static saveUTF8(filePath, data) { return __awaiter(this, void 0, void 0, function* () { try { yield fs_1.promises.writeFile(filePath, data); return Promise.resolve(true); } catch (exception) { RJLog_1.RJLog.warn("saveUTF8: ", filePath); RJLog_1.RJLog.warn(exception); } return Promise.resolve(false); }); } static loadJSON(filePath) { return __awaiter(this, void 0, void 0, function* () { let text = yield this.loadUTF8(filePath); if (text === null) { return Promise.resolve(null); } try { let jsonObject = JSON.parse(text); return Promise.resolve(jsonObject); } catch (exception) { RJLog_1.RJLog.warn("LoadJSON: ", filePath); RJLog_1.RJLog.warn(exception); } return Promise.resolve(null); }); } } exports.Files = Files; //# sourceMappingURL=Files.js.map