From d8b5a80280a39cbaa330f96aa4fe520f9193405d Mon Sep 17 00:00:00 2001 From: indexzero Date: Fri, 24 Jun 2011 03:31:26 -0400 Subject: [PATCH] [minor] Small style updates to the File store --- lib/nconf/stores/file.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/lib/nconf/stores/file.js b/lib/nconf/stores/file.js index 09b2449..fae5d96 100644 --- a/lib/nconf/stores/file.js +++ b/lib/nconf/stores/file.js @@ -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;