UNPKG

@tucmc/hazel

Version:
39 lines (38 loc) 1.3 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Files = void 0; const fs_1 = __importDefault(require("fs")); const Debugger_1 = require("../debugger/Debugger"); const Timestamp_1 = require("../time/Timestamp"); class Files { static debug = new Debugger_1.Debugger('IOUnit'); static writeFile(c, dest) { try { const file = { exported: new Date().getTime(), content: c }; fs_1.default.writeFileSync(dest, JSON.stringify(file)); this.debug.info(`exported file saved at ${dest}`); } catch (e) { this.debug.err(e); } } static readFile(path) { try { const data = JSON.parse(fs_1.default.readFileSync(path).toString()); const { t, d } = Timestamp_1.TimestampUtil.currentTime(data.exported); this.debug.info(`read exported record from ${path} \nrecord created ${t.h}:${t.m} ${d.d}/${d.m}/${d.y}`); return data; } catch (e) { this.debug.err(e); return null; } } } exports.Files = Files;