Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix jsonpath option.

  • Loading branch information...
commit beb7fcd9bc6cd7de572a7008b07bf8279ef16de2 1 parent 9c00162
@pH200 authored
Showing with 12 additions and 10 deletions.
  1. +12 −10 sabrina/persistence-read-json.js
View
22 sabrina/persistence-read-json.js
@@ -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);
},
@@ -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);
};
Please sign in to comment.
Something went wrong with that request. Please try again.