diff --git a/lib/fs.js b/lib/fs.js index 0b17885329ab92..0287d81c942cda 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -234,14 +234,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, { @@ -260,13 +256,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;