Skip to content

Commit

Permalink
[minor] Small style updates to the File store
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Jun 24, 2011
1 parent c436851 commit d8b5a80
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions lib/nconf/stores/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

};

//
Expand All @@ -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);
});

}
});

};

//
Expand All @@ -121,24 +119,24 @@ 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);
}
catch (ex) {
throw new Error("Error parsing your JSON configuration file.")
}

}

return data;
Expand Down

0 comments on commit d8b5a80

Please sign in to comment.