access
Check whether the process can access a file with the given mode (F_OK, R_OK, W_OK, X_OK). Rejects if access is denied.
Basic usage
import { access } from '@rush-fs/core'
import { constants } from 'node:fs'
await access('./file.txt') // F_OK default
await access('./file.txt', constants.R_OK)
await access('./script.sh', constants.X_OK)Methods
access(path, mode?)
Async. Returns Promise<void> (rejects on access denied).
| Argument | Type | Description |
|---|---|---|
path | string | File path. |
mode | number | Optional. F_OK, R_OK, W_OK, X_OK (from fs.constants). |
accessSync(path, mode?)
Sync. Same arguments; throws on access denied.
Performance
From repo benchmarks (pnpm build && pnpm bench):
| Scenario | Node.js | Rush-FS | Speedup |
|---|---|---|---|
| access R_OK (directory) | 4.18 µs | 1.55 µs | 2.7x |
| Scenario | Node.js | Rush-FS | Note |
|---|---|---|---|
| accessSync F_OK | 456 ns | 1.46 µs | Node.js fast path |
Rush-FS is faster for typical access checks; for F_OK-only sync checks Node.js can be faster due to internal fast path.
Notes
- Prefer exists: If you only need “file exists”,
exists(path)is simpler;access(path, F_OK)is the lower-level API. - Constants: Use
constants.F_OK,R_OK,W_OK,X_OKfromnode:fs(or the numeric values).
Last updated on