https://github.com/cloudcmd/copy-file
simply copy a file
https://github.com/cloudcmd/copy-file
copy file javascript nodejs
Last synced: 10 months ago
JSON representation
simply copy a file
- Host: GitHub
- URL: https://github.com/cloudcmd/copy-file
- Owner: cloudcmd
- License: mit
- Created: 2018-05-02T13:38:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-02-10T10:32:50.000Z (almost 5 years ago)
- Last Synced: 2025-01-08T11:08:36.025Z (about 1 year ago)
- Topics: copy, file, javascript, nodejs
- Language: JavaScript
- Size: 37.1 KB
- Stars: 2
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog
- License: LICENSE
Awesome Lists containing this project
README
# Copy File [![License][LicenseIMGURL]][LicenseURL] [![NPM version][NPMIMGURL]][NPMURL] [![Dependency Status][DependencyStatusIMGURL]][DependencyStatusURL] [![Build Status][BuildStatusIMGURL]][BuildStatusURL] [![Coverage Status][CoverageIMGURL]][CoverageURL]
Simply copy a file. If an error occurs after the destination file has been opened for writing, `copy-file` will attempt to remove the destination. Correctly copies `symlinks`.
## Install
```
npm i @cloudcmd/copy-file
```
## API
### copyFile(src, dest [, streams])
- `src` `` - source filename to copy
- `dest` ``- destination filename of the copy operation
- `streams` ``- file processing streams (optional)
```js
const copyFile = require('@cloudcmd/copy-file');
const ok = () => 'ok';
const error = (e) => e.message;
copyFile('./package.json', './package2.json')
.then(ok)
.catch(error)
.then(console.log);
```
You can use preprocessing `streams` of copied file:
```js
const copyFile = require('@cloudcmd/copy-file');
const zlib = require('zlib');
const gzip = zlib.createGzip();
const ok = () => 'ok';
const error = (e) => e.message;
copyFile('./package.json', './package2.json', [gzip])
.then(ok)
.catch(error)
.then(console.log);
```
You can use `copyFile` with `async-await`:
```js
const tryToCatch = require('try-to-catch');
const copyFile = require('@cloudcmd/copy-file');
(async () => {
const [e] = await tryToCatch(copyFile, './package.json', './package2.json');
if (!e)
return;
console.error(e.message);
})();
```
## Related
- [fs-copy-file](https://github.com/coderaiser/fs-copy-file "fs-copy-file") - Node.js `v8.5.0` `fs.copyFile` ponyfill
- [fs-copy-file-sync](https://github.com/coderaiser/fs-copy-file-sync "fs-copy-file-sycn") - Node.js `v8.5.0` `fs.copyFile` ponyfill
- [copy-symlink](https://github.com/coderaiser/copy-symlink) - Copy symlink because `fs.copyFile` can't.
## License
MIT
[NPMIMGURL]: https://img.shields.io/npm/v/@cloudcmd/copy-file.svg?style=flat
[BuildStatusIMGURL]: https://img.shields.io/travis/cloudcmd/copy-file/master.svg?style=flat
[DependencyStatusIMGURL]: https://img.shields.io/david/cloudcmd/copy-file.svg?style=flat
[LicenseIMGURL]: https://img.shields.io/badge/license-MIT-317BF9.svg?style=flat
[CoverageIMGURL]: https://coveralls.io/repos/cloudcmd/copy-file/badge.svg?branch=master&service=github
[NPMURL]: https://npmjs.org/package/@cloudcmd/copy-file "npm"
[BuildStatusURL]: https://travis-ci.org/cloudcmd/copy-file "Build Status"
[DependencyStatusURL]: https://david-dm.org/cloudcmd/copy-file "Dependency Status"
[LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License"
[CoverageURL]: https://coveralls.io/github/cloudcmd/copy-file?branch=master