@micro-os-plus/hello-world-qemu-template
Version:
A source xPack / npm package with a template to generate semihosted Hello World projects running on QEMU
122 lines (77 loc) • 2.52 kB
Markdown
> Copy a file
- Fast by using streams in the async version and [`fs.copyFileSync()`](https://nodejs.org/api/fs.html#fs_fs_copyfilesync_src_dest_flags) in the synchronous version.
- Resilient by using [graceful-fs](https://github.com/isaacs/node-graceful-fs).
- User-friendly by creating non-existent destination directories for you.
- Can be safe by turning off [overwriting](
- Preserves file mode, [but not ownership](https://github.com/sindresorhus/cp-file/issues/22#issuecomment-502079547).
- User-friendly errors.
```sh
npm install cp-file
```
```js
import {copyFile} from 'cp-file';
await copyFile('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.
Type: `string`\
Default: `process.cwd()`
The working directory to find source files.
The source and destination path are relative to this.
Type: `number`\
Default: `0o777`
[](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) for created directories.
It has no effect on Windows.
Type: `(progress: ProgressData) => void`
The given function is called whenever there is measurable progress.
Only available when using the async method.
```js
{
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`.
- For empty files, the `onProgress` callback function is emitted only once.
```js
import {copyFile} from 'cp-file';
await copyFile(source, destination, {
onProgress: progress => {
// …
}
});
```
- [cpy](https://github.com/sindresorhus/cpy) - Copy files
- [cpy-cli](https://github.com/sindresorhus/cpy-cli) - Copy files on the command-line
- [move-file](https://github.com/sindresorhus/move-file) - Move a file
- [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed