* Tests whether or not the given path exists. * @param {string | Buffer | URL} path * @param {(exists?: boolean) => any} callback * @returns {void}
(path, callback)
| 280 | * @returns {void} |
| 281 | */ |
| 282 | function exists(path, callback) { |
| 283 | validateFunction(callback, 'cb'); |
| 284 | |
| 285 | const h = vfsState.handlers; |
| 286 | if (h !== null) { |
| 287 | const result = h.existsSync(path); |
| 288 | if (result !== undefined) { |
| 289 | process.nextTick(callback, result); |
| 290 | return; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | function suppressedCallback(err) { |
| 295 | callback(!err); |
| 296 | } |
| 297 | |
| 298 | try { |
| 299 | fs.access(path, F_OK, suppressedCallback); |
| 300 | } catch { |
| 301 | return callback(false); |
| 302 | } |
| 303 | } |
| 304 | |
| 305 | ObjectDefineProperty(exists, kCustomPromisifiedSymbol, { |
| 306 | __proto__: null, |
searching dependent graphs…