Skip to Content
APIcopyFile

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 exists

Methods

copyFile(src, dest, mode?)

Async. Returns Promise<void>.

ArgumentTypeDescription
srcstringSource file path.
deststringDestination file path.
modenumberOptional. 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):

ScenarioNode.jsVooya FSSpeedup
copyFile 4 MB4.67 ms0.09 ms50x

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
ScaleFixtureNode.jsVooya FSRatioNode RSSVooya FS RSS
small-4kb-0.22 ms0.15 ms1.47x faster19.2 KB0 B
medium-1mb-0.77 ms0.15 ms5.18x faster0 B3.2 KB
large-8mb-4.22 ms0.13 ms32.30x faster0 B0 B

Notes

  • Directories: Use cp with recursive: true for directory trees. copyFile only copies a single file.
  • COPYFILE_EXCL: Use constants.COPYFILE_EXCL from node: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, and syscall fields yet.
  • Unsupported Node inputs: Buffer paths and URL paths are not part of the current Vooya FS copyFile surface.
  • Unsupported reflink guarantee: COPYFILE_FICLONE_FORCE currently 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