Socket
Socket
Sign inDemoInstall

cp-file

Package Overview
Dependencies
4
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    cp-file

Copy a file


Version published
Weekly downloads
2.5M
increased by3.96%
Maintainers
1
Install size
84.0 kB
Created
Weekly downloads
 

Readme

Source

cp-file

Copy a file

Highlights

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 => {
		// …
	}
});

Keywords

FAQs

Last updated on 05 Nov 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc