Skip to content

Commit

Permalink
Merge pull request #344 from fmtvp/making_read_async
Browse files Browse the repository at this point in the history
updating antie.js
  • Loading branch information
subsidel committed Feb 22, 2016
2 parents eefb693 + 430d1a6 commit 610d828
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions node/antie.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
var fs = require('fs')

function fileExistsSync(path) {
try {
fs.lstatSync(path);
return true;
} catch (e) {
return false;
}
}

module.exports = {
getPageStrategyElement: function(pageStrategy, element) {
getPageStrategyElementSync: function(pageStrategy, element) {
var pageStrategyPath = __dirname + '/../config/pagestrategy/' + pageStrategy + '/' + element;
if (!fs.existsSync(pageStrategyPath)) {
if (!fileExistsSync(pageStrategyPath)) {
return {
noSuchStrategy: "file does not exist: " + pageStrategyPath
}
}
return {
data: fs.readFileSync(pageStrategyPath).toString()
}
},
getPageStrategyElement: function(pageStrategy, element, callback) {
var pageStrategyPath = __dirname + '/../config/pagestrategy/' + pageStrategy + '/' + element;

fs.readFile(pageStrategyPath, function(err, data) {
if (err !== null) {
callback({
noSuchStrategy: "file does not exist: " + pageStrategyPath
})
} else {
callback({
data: data.toString()
})
}
})
}
}

0 comments on commit 610d828

Please sign in to comment.