4.0.0 • Published 3 years ago

@cloudcmd/copy-file v4.0.0

Weekly downloads
17,539
License
MIT
Repository
github
Last release
3 years ago

Copy File License NPM version Dependency Status Build Status Coverage Status

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 <string> - source filename to copy
  • dest <string>- destination filename of the copy operation
  • streams <array>- file processing streams (optional)
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:

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:

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

License

MIT

4.0.0

3 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago