Adding path.existsSync (with tests.)

pull/22966/head
Micheil Smith 2010-06-16 23:51:19 +10:00 committed by Ryan Dahl
parent 73f207fe59
commit b05daaaf69
2 changed files with 11 additions and 0 deletions

View File

@ -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;
}
};

View File

@ -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");