copyFile
Copy a file from src to dest. Does not copy directory trees.
Basic usage
import { copyFile } from '@vooya/fs'
import { constants } from 'node:fs'
await copyFile('./a.txt', './b.txt')
await copyFile('./a.txt', './b.txt', constants.COPYFILE_EXCL) // fail if dest existsMethods
copyFile(src, dest, mode?)
Async. Returns Promise<void>.
| Argument | Type | Description |
|---|---|---|
src | string | Source file path. |
dest | string | Destination file path. |
mode | number | Optional. e.g. COPYFILE_EXCL to fail if dest exists. |
copyFileSync(src, dest, mode?)
Sync. Same arguments; throws on error.
Performance
From repo benchmarks (pnpm build && pnpm bench):
| Scenario | Node.js | Vooya FS | Speedup |
|---|---|---|---|
| copyFile 4 MB | 4.67 ms | 0.09 ms | 50x |
Vooya FS is much faster for single-file copy due to efficient native I/O.
Local scale report
Generated from local performance reports. Do not edit this block by hand.
- Runtime: v22.22.0 on darwin/arm64
- Samples: 2 warmup runs, 10 measured runs
- Aggregation: trimmed mean for wall-clock time; average per-run memory delta for RSS
| Scale | Fixture | Node.js | Vooya FS | Ratio | Node RSS | Vooya FS RSS |
|---|---|---|---|---|---|---|
| small-4kb | - | 0.22 ms | 0.15 ms | 1.47x faster | 19.2 KB | 0 B |
| medium-1mb | - | 0.77 ms | 0.15 ms | 5.18x faster | 0 B | 3.2 KB |
| large-8mb | - | 4.22 ms | 0.13 ms | 32.30x faster | 0 B | 0 B |
Notes
- Directories: Use
cpwithrecursive: truefor directory trees.copyFileonly copies a single file. - COPYFILE_EXCL: Use
constants.COPYFILE_EXCLfromnode:fs(or the numeric value) to avoid overwriting an existing destination. - Known gap: Missing-path and existing-destination errors currently have Node-like messages, but do not expose Node-style
code,path,dest, andsyscallfields yet. - Unsupported Node inputs:
Bufferpaths andURLpaths are not part of the current Vooya FScopyFilesurface. - Unsupported reflink guarantee:
COPYFILE_FICLONE_FORCEcurrently falls back to ordinary copy instead of requiring copy-on-write support.
Competitor measurements
See the full copyFile comparison table for Node 22/24, peer libraries, sync/Promise modes, small and batch workloads, execution routes and measurement limits.
Last updated on