Skip to content

Commit

Permalink
Fix jsonpath option.
Browse files Browse the repository at this point in the history
  • Loading branch information
pH200 committed Dec 17, 2012
1 parent 9c00162 commit beb7fcd
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions sabrina/persistence-read-json.js
Expand Up @@ -7,13 +7,18 @@ var waterfall = require("./waterfall");
var jsonParse = require("./json-parse");

module.exports = function (jsonpath, jsondir, callback) {
function onComplete (err, json) {
if (err) {
return callback(err);
}
return jsonParse(json, callback);
}

if (jsonpath) {
return fs.readFile(jsonpath, "utf8", onComplete);
}

return waterfall.escapeWaterfall([
function (value, cb, end) {
if (jsonpath) {
fs.readFile(jsonpath, "utf8", end);
}
return cb("next");
},
function (value, cb, end, escape) {
return fs.readdir(jsondir, escape);
},
Expand Down Expand Up @@ -41,9 +46,6 @@ module.exports = function (jsonpath, jsondir, callback) {
},
function (value, cb, end, escape) {
return fs.readFile(path.join(jsondir, value), "utf8", escape);
},
function (value, cb, end) {
return jsonParse(value, end);
}
], callback);
], onComplete);
};

0 comments on commit beb7fcd

Please sign in to comment.