Copy a file
- Fast by using streams in the async version.
- Resilient by using graceful-fs.
- User-friendly by creating non-existent destination directories for you.
- Can be safe by turning off overwriting.
- User-friendly errors.
$ npm install --save cp-file
const cpFile = require('cp-file');
cpFile('src/unicorn.png', 'dist/unicorn.png').then(() => {
console.log('File copied');
});
Returns a Promise
.
Type: string
File you want to copy.
Type: string
Where you want the file copied.
Type: Object
Type: boolean
Default: true
Overwrite existing file.
Progress reporting. Only available when using the async method.
Type: Function
{
src: String,
dest: String,
size: Number,
written: Number,
percent: Number
}
-
src
anddest
are absolute paths. -
size
andwritten
are in bytes. -
percent
is a value between0
and1
.
- For empty files, the
progress
event is emitted only once. - The
.on()
method is available only right after the initialcpFile()
call. So make sure you add ahandler
before.then()
:
cpFile(src, dest).on('progress', data => {
// ...
}).then(() => {
// ...
})
See cpy if you need to copy multiple files or want a CLI.
MIT © Sindre Sorhus