[minor] Small style updates to the File store

This commit is contained in:
indexzero 2011-06-24 03:31:26 -04:00
parent c43685160d
commit d8b5a80280

View file

@ -62,14 +62,12 @@ File.prototype.save = function (value, callback) {
// using the format specified by `this.format` synchronously.
//
File.prototype.saveSync = function (value) {
try {
fs.writeFileSync(this.file, this.format.stringify(this.store));
}
catch (ex) {
throw(ex);
}
};
//
@ -80,36 +78,36 @@ File.prototype.saveSync = function (value) {
File.prototype.load = function (callback) {
var self = this;
path.exists(self.file, function(exists){
path.exists(self.file, function (exists) {
if (!exists) {
//
// If the path we are attempting to load doesn't exist, create it
self.save({}, function(err){
//
self.save({}, function (err) {
self.store = {};
return callback(err, self.store);
});
}
else {
//
// Else, the path exists, read it from disk
//
fs.readFile(self.file, function (err, data) {
if (err) {
return callback(err);
}
try {
self.store = self.format.parse(data.toString());
}
catch (ex) {
return callback(new Error("Error parsing your JSON configuration file."));
}
callback(null, self.store);
});
}
});
};
//
@ -121,16 +119,17 @@ File.prototype.loadSync = function () {
var data, self = this;
if (!path.existsSync(self.file)) {
//
// If the path we are attempting to load doesn't exist, create it
//
self.saveSync({});
self.store = {};
data = {};
}
else {
//
// Else, the path exists, read it from disk
//
try {
data = fs.readFileSync(this.file, 'utf8');
this.store = this.format.parse(data);
@ -138,7 +137,6 @@ File.prototype.loadSync = function () {
catch (ex) {
throw new Error("Error parsing your JSON configuration file.")
}
}
return data;