Skip to contentpackage
cp-file
v8.0.1Copy a file
node >=104 depscjsopen source
- license
- MIT
- deps
- 4
- unpacked
- 12.7 kB
- files
- 8
- node
- >=10
$npm install cp-file@8.0.1 README
GitHub-flavored package documentation.
downloads
Across all versions.
Download trend unavailable.
compatibility
Runtime metadata.
keywords
Tagged topics.
copycpfileclonefsstreamfile-systemncpfastquickdatacontent
install size
Estimated unpacked size across 6 packages.
124.3 kB
Includes dependencies.
dependencies
4 direct · 2 outdated
versions
Latest published Nov 5, 2023
contents
cp-file
Copy a file
Highlights
- Fast by using streams in the async version and
fs.copyFileSync() in the synchronous version.
- Resilient by using graceful-fs.
Mar 5, 2020
maintainers
Registry package owners.
User-friendly by creating non-existent destination directories for you.User-friendly errors.Install
Usage
import {copyFile} from 'cp-file';
await copyFile('source/unicorn.png', 'destination/unicorn.png');
console.log('File copied');
API
copyFile(source, destination, options?)
Returns a Promise that resolves when the file is copied.
copyFileSync(source, destination, options?)
source
The file you want to copy.
destination
Where you want the file copied.
options
overwrite
Type: boolean
Default: true
Overwrite existing destination file.
cwd
Type: string
Default: process.cwd()
The working directory to find source files.
The source and destination path are relative to this.
directoryMode
Type: number
Default: 0o777
It has no effect on Windows.
onProgress
Type: (progress: ProgressData) => void
The given function is called whenever there is measurable progress.
Only available when using the async method.
ProgressData
{
sourcePath: string,
destinationPath: string,
size: number,
writtenBytes: number,
percent: number
}
sourcePath and destinationPath are absolute paths.
size and writtenBytes are in bytes.
percent is a value between 0 and 1.
Notes
- For empty files, the
onProgress callback function is emitted only once.
import {copyFile} from 'cp-file';
await copyFile(source, destination, {
onProgress: progress => {
// …
}
});
- cpy - Copy files
- cpy-cli - Copy files on the command-line
- move-file - Move a file
- make-dir - Make a directory and its parents if needed