diff --git a/lib/path.js b/lib/path.js index 74a998acd0..0316f96614 100644 --- a/lib/path.js +++ b/lib/path.js @@ -79,3 +79,12 @@ exports.exists = function (path, callback) { if (callback) callback(err ? false : true); }); }; + +exports.existsSync = function (path) { + try { + process.binding('fs').stat(path) + return true; + } catch(e){ + return false; + } +}; diff --git a/test/simple/test-path.js b/test/simple/test-path.js index 25cdaa47be..4b0537874b 100644 --- a/test/simple/test-path.js +++ b/test/simple/test-path.js @@ -12,6 +12,8 @@ assert.equal(path.dirname("/a"), "/"); assert.equal(path.dirname("/"), "/"); path.exists(f, function (y) { assert.equal(y, true) }); +assert.equal(path.existsSync(f), true); + assert.equal(path.extname(""), ""); assert.equal(path.extname("/path/to/file"), ""); assert.equal(path.extname("/path/to/file.ext"), ".ext");