diff --git a/lib/fs.js b/lib/fs.js index da718f3f334413..6853bc4b1625a5 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -427,14 +427,10 @@ fs.exists = function(path, callback) { } try { - path = getPathFromURL(path); - validatePath(path); + fs.access(path, fs.FS_OK, suppressedCallback); } catch (err) { return callback(false); } - var req = new FSReqWrap(); - req.oncomplete = suppressedCallback; - binding.stat(pathModule.toNamespacedPath(path), req); }; Object.defineProperty(fs.exists, internalUtil.promisify.custom, { @@ -453,13 +449,7 @@ Object.defineProperty(fs.exists, internalUtil.promisify.custom, { // TODO(joyeecheung): deprecate the never-throw-on-invalid-arguments behavior fs.existsSync = function(path) { try { - path = getPathFromURL(path); - validatePath(path); - const ctx = { path }; - binding.stat(pathModule.toNamespacedPath(path), undefined, ctx); - if (ctx.errno !== undefined) { - return false; - } + fs.accessSync(path, fs.FS_OK); return true; } catch (e) { return false;