mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2025-08-14 03:35:36 +00:00
Async read and write keys
This commit is contained in:
@@ -6,14 +6,24 @@ module.exports = (pathToFile) => {
|
||||
const path = pathToFile;
|
||||
|
||||
return {
|
||||
read() {
|
||||
if (!fs.existsSync(path))
|
||||
return null;
|
||||
return fs.readFileSync(path, { encoding: 'utf8' });
|
||||
write(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.writeFile(path, data, { encoding: 'utf8' }, (error) => {
|
||||
if (error) throw error;
|
||||
|
||||
return resolve();
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
write(data) {
|
||||
fs.writeFileSync(path, data, { encoding: 'utf8' });
|
||||
read() {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile(path, { encoding: 'utf8' }, (error, data) => {
|
||||
if (error) reject(error);
|
||||
|
||||
return resolve(data);
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user