UNPKG

@softwaredevelopment/node-red-contrib-bodhi-device-occupancy-sensor

Version:

Occupancy Sensor device for bodhi node red

38 lines 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.fileStorageManager = void 0; const fs = require("fs"); const path_1 = require("path"); class FileStorageManager { constructor(defaultPath) { this._storagePath = defaultPath || (0, path_1.join)('config', 'device'); } set storagePath(value) { this._storagePath = (0, path_1.join)((0, path_1.dirname)(value), 'config', 'device'); } get storagePath() { return this._storagePath; } sendStringToStorage(key, value) { if (!fs.existsSync(this._storagePath)) { fs.mkdirSync(this._storagePath, { recursive: true }); } fs.writeFileSync((0, path_1.join)(this._storagePath, key), value); } retrieveStringFromStorage(key) { if (!fs.existsSync((0, path_1.join)(this._storagePath, key))) return undefined; const result = fs.readFileSync((0, path_1.join)(this._storagePath, key)); return result.toString('utf-8'); } ifKeyExists(key) { return fs.existsSync((0, path_1.join)(this._storagePath, key)); } clearStorage(key) { if (!fs.existsSync((0, path_1.join)(this._storagePath, key))) { fs.unlinkSync((0, path_1.join)(this._storagePath, key)); } } } exports.fileStorageManager = new FileStorageManager(); //# sourceMappingURL=file-storage.js.map