11.0.0 • Published 5 months ago

cp-file v11.0.0

Weekly downloads
2,016,927
License
MIT
Repository
github
Last release
5 months ago

cp-file

Copy a file

Highlights

  • Fast by using streams in the async version and fs.copyFileSync() in the synchronous version.
  • Resilient by using 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.
  • User-friendly errors.

Install

npm install cp-file

Usage

import {copyFile} from 'cp-file';

await copyFile('source/unicorn.png', 'destination/unicorn.png');
console.log('File copied');

API

copyFile(source, destination, options?)

Returns a Promise that resolves when the file is copied.

copyFileSync(source, destination, options?)

source

Type: string

The file you want to copy.

destination

Type: string

Where you want the file copied.

options

Type: object

overwrite

Type: boolean\ Default: true

Overwrite existing destination file.

cwd

Type: string\ Default: process.cwd()

The working directory to find source files.

The source and destination path are relative to this.

directoryMode

Type: number\ Default: 0o777

Permissions for created directories.

It has no effect on Windows.

onProgress

Type: (progress: ProgressData) => void

The given function is called whenever there is measurable progress.

Only available when using the async method.

ProgressData
{
	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.
Notes
  • For empty files, the onProgress callback function is emitted only once.
import {copyFile} from 'cp-file';

await copyFile(source, destination, {
	onProgress: progress => {
		// …
	}
});

Related

reactifirecreate-geosecma-librarytypescriptifire@robmayer/create-react-library@bent10/codepthrift-models-generatorcodepdex-react-package-creation-1bch-js-joeyvfs-create-react-libraryvfs-create-widget@nebulars/neptune@nebular.js/neptune@infinitebrahmanuniverse/nolb-cp@saaspe/components@everything-registry/sub-chunk-1394ey-template-vue3libton-scriptkubithip-nest-testhtml-webpack-inject-externals-pluginibiz-vue2-templateibiz-vue3-gateway-templateibiz-vue3-templatekpyguildergrunt-build-atom-shellgulp-files-synckrulkrul-cliimage-testdataimg-resize-cliitbjolt-frameworklntmonkeysmonodicnode-editorconfignano_spanirvana-jsngrx-undo-v2mstorage-restoreinsales-uploadernehemiahmake-preact-appmesh-desktoplq-server-clinodejinmcfeeasystaticepub-gen-funstoryelmoglob-cpglass-app-managergrunt-stkgritenvgrm-cligrm-commandgunzip-then-rsynchanyuguangzhengfast-adminfeltflatten-dirnamefilename-to-dirfe-1thgen-cli-for-docsifyexpo-screenshot-tooley-template-vue3-hookeumadipiscifn-lib-exampleey-tax-template-vue3ey-tax-vue3offlinkpush2cloud-compilerpush2cloud-compiler-rfraku2-cprabbiqcloud-test-cliqcloud-test-cli1pkg-packager-appimagepostcss-url-foldersreact-library-clireact-modern-library-clireact-form-component-libraryparvan_componentsparvan_reactjs_componentsreact-sitephoenix-app-creatorpipen-report-svxrt-vue3-templatervnbox-sdksequelcomponent@erickmerchant/copy-files@hdsydsvenskan/asset-versions@heph-tech/build-package@ikrong/poty@ibiz-template/cli-core@ibiz-template/vue3@hyperlink/garage-door-monitor@ibizstudio/core
11.0.0

5 months ago

10.0.0

2 years ago

9.1.0

3 years ago

9.0.0

4 years ago

8.0.1

4 years ago

8.0.0

4 years ago

7.0.0

5 years ago

6.2.0

5 years ago

6.1.0

5 years ago

6.0.0

6 years ago

5.0.0

7 years ago

4.2.0

7 years ago

4.1.1

7 years ago

4.1.0

7 years ago

4.0.1

7 years ago

4.0.0

7 years ago

3.2.0

8 years ago

3.1.0

8 years ago

3.0.1

8 years ago

3.0.0

8 years ago

2.3.0

8 years ago

2.2.1

9 years ago

2.2.0

9 years ago

2.1.0

9 years ago

2.0.2

9 years ago

2.0.1

9 years ago

2.0.0

9 years ago

1.0.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago