You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

33 lines
656 B

var fs = require('fs')
function FileStorage(opts) {
if (!opts.filename) {
throw new Error('Please set wallet filename');
}
this.filename = opts.filename;
this.fs = opts.fs || fs;
};
FileStorage.prototype.getName = function() {
return this.filename;
};
FileStorage.prototype.save = function(data, cb) {
this.fs.writeFile(this.filename, JSON.stringify(data), cb);
};
FileStorage.prototype.load = function(cb) {
this.fs.readFile(this.filename, 'utf8', function(err,data) {
if (err) return cb(err);
try {
data = JSON.parse(data);
} catch (e) {
}
return cb(null, data);
});
};
module.exports = FileStorage;