UNPKG

system-secured-storage

Version:

A Node.js project that allows users to store encrypted key-value data locally on their system. This project serves as an alternate storage solution to SQLite but with enhanced security features, leveraging AES encryption to ensure the confidentiality and

69 lines 2.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.retrieveDataLocallySync = exports.retrieveDataLocallyAsync = exports.saveDataLocallySync = exports.saveDataLocallyAsync = void 0; const node_fs_1 = require("node:fs"); const fileName = 'data.encrypted'; /** * Save data locally asynchronously. * * @param {string} directory - The directory to save the file. * @param {string} data - The data to be saved. * @param {void} callback - The callback function * @returns */ const saveDataLocallyAsync = (directory, data, callback) => { const path = directory.concat('/', fileName); return (0, node_fs_1.writeFile)(path, JSON.stringify(data), callback); }; exports.saveDataLocallyAsync = saveDataLocallyAsync; /** * Save data locally synchronously. * * @param {string} directory - The directory to save the file. * @param {string} data - The data to be saved. * @returns */ const saveDataLocallySync = (directory, data) => { const path = directory.concat('/', fileName); return (0, node_fs_1.writeFileSync)(path, JSON.stringify(data)); }; exports.saveDataLocallySync = saveDataLocallySync; /** * Retrieve data locally asynchronously. * * @param {string} directory - The directory the data saved in. * @param {void} callback - Callback function. * @returns */ const retrieveDataLocallyAsync = (directory, callback) => { try { const path = directory.concat('/', fileName); return (0, node_fs_1.readFile)(path, { encoding: 'utf-8' }, (error, data) => { if (error || !data) callback(error, undefined); else callback(error, JSON.parse(data)); }); } catch (error) { callback(error, undefined); } }; exports.retrieveDataLocallyAsync = retrieveDataLocallyAsync; /** * Retrieve data locally synchronously. * * @param {string} directory - The directory the data saved in. * @returns */ const retrieveDataLocallySync = (directory) => { try { const path = directory.concat('/', fileName); return JSON.parse((0, node_fs_1.readFileSync)(path, { encoding: 'utf-8' })); } catch (error) { return undefined; } }; exports.retrieveDataLocallySync = retrieveDataLocallySync; //# sourceMappingURL=save-file.util.js.map