Copy a file
fs.copyFileSync()
in the synchronous version.$ npm install cp-file
const cpFile = require('cp-file');
(async () => {
await cpFile('source/unicorn.png', 'destination/unicorn.png');
console.log('File copied');
})();
Returns a Promise
that resolves when the file is copied.
Type: string
The file you want to copy.
Type: string
Where you want the file copied.
Type: object
Type: boolean
Default: true
Overwrite existing destination file.
Progress reporting. Only available when using the async method.
Type: Function
{
sourcePath: string,
destinationPath: string,
size: number,
writtenBytes: number,
percent: number
}
source
and destination
are absolute paths.size
and writtenBytes
are in bytes.percent
is a value between 0
and 1
.progress
event is emitted only once..on()
method is available only right after the initial cpFile()
call. So make sure
you add a handler
before .then()
:const cpFile = require('cp-file');
(async () => {
await cpFile(source, destination).on('progress', data => {
// …
});
})();
Copyright 2013 - present © cnpmjs.org