Ivan Socolsky
10 years ago
5 changed files with 99 additions and 49 deletions
@ -0,0 +1,30 @@ |
|||
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; |
Loading…
Reference in new issue