1
0
mirror of https://github.com/keeweb/keeweb.git synced 2024-06-25 07:37:46 +02:00
keeweb/app/scripts/storage/storage-file.js

31 lines
757 B
JavaScript
Raw Normal View History

2015-12-02 21:39:40 +01:00
'use strict';
var Launcher = require('../comp/launcher');
var StorageFile = {
name: 'file',
enabled: !!Launcher,
load: function(path, callback) {
try {
var data = Launcher.readFile(path);
2015-12-07 22:00:44 +01:00
if (callback) { callback(null, data.buffer); }
2015-12-02 21:39:40 +01:00
} catch (e) {
console.error('Error reading local file', path, e);
2015-12-07 22:00:44 +01:00
if (callback) { callback(e, null); }
2015-12-02 21:39:40 +01:00
}
},
save: function(path, data, callback) {
try {
Launcher.writeFile(path, data);
2015-12-07 22:00:44 +01:00
if (callback) { callback(); }
2015-12-02 21:39:40 +01:00
} catch (e) {
console.error('Error writing local file', path, e);
2015-12-07 22:00:44 +01:00
if (callback) { callback(e); }
2015-12-02 21:39:40 +01:00
}
}
};
module.exports = StorageFile;