Skip to content

Commit

Permalink
fs: make exists faster by using access
Browse files Browse the repository at this point in the history
access is faster than stat, because we don't have to return the
actual stat results.
  • Loading branch information
dfabulich committed Aug 16, 2016
1 parent b026c0e commit 19689e4
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,8 @@ fs.accessSync = function(path, mode) {

fs.exists = function(path, callback) {
if (!nullCheck(path, cb)) return;
var req = new FSReqWrap();
req.oncomplete = cb;
binding.stat(pathModule._makeLong(path), req);
function cb(err, stats) {
fs.access(path, fs.F_OK, cb);
function cb(err) {
if (callback) callback(err ? false : true);
}
};
Expand Down

0 comments on commit 19689e4

Please sign in to comment.