sindresorhus / cp-file
- вторник, 4 октября 2016 г. в 03:13:41
JavaScript
Copy a file
Copy a file
$ 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 and dest are absolute paths.size and written 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():cpFile(src, dest).on('progress', data => {
// ...
}).then(() => {
// ...
})See cpy if you need to copy multiple files or want a CLI.
MIT © Sindre Sorhus