{"_id":"copy-file","_rev":"3513109","name":"copy-file","description":"Copy a file","dist-tags":{"latest":"11.0.0"},"maintainers":[{"name":"sindresorhus","email":""}],"time":{"modified":"2024-08-27T20:32:05.000Z","created":"2012-06-01T12:16:11.448Z","11.0.0":"2023-11-05T07:46:44.904Z","0.0.1":"2012-06-01T12:16:11.448Z"},"users":{},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"repository":{"type":"git","url":"git+https://github.com/sindresorhus/copy-file.git"},"versions":{"11.0.0":{"name":"copy-file","version":"11.0.0","description":"Copy a file","license":"MIT","repository":{"type":"git","url":"git+https://github.com/sindresorhus/copy-file.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"types":"./index.d.ts","default":"./index.js"},"engines":{"node":">=18"},"scripts":{"test":"xo && nyc ava && tsd"},"keywords":["copy","copying","cp","file","clone","fs","stream","file-system","filesystem","ncp","fast","quick","data","content","contents","read","write","io"],"dependencies":{"graceful-fs":"^4.2.11","p-event":"^6.0.0"},"devDependencies":{"ava":"^5.3.1","clear-module":"^4.1.2","coveralls":"^3.1.1","del":"^7.1.0","import-fresh":"^3.3.0","nyc":"^15.1.0","sinon":"^17.0.1","tsd":"^0.29.0","xo":"^0.56.0"},"xo":{"rules":{"ava/assertion-arguments":"off"}},"ava":{"workerThreads":false,"serial":true},"types":"./index.d.ts","gitHead":"0ce680c9bd10960b20ae9f6abac71cd85c576dae","bugs":{"url":"https://github.com/sindresorhus/copy-file/issues"},"homepage":"https://github.com/sindresorhus/copy-file#readme","_id":"copy-file@11.0.0","_nodeVersion":"18.18.2","_npmVersion":"9.2.0","dist":{"shasum":"903f0a5a34e5534eaf775352ac9381359c13f258","size":4463,"noattachment":false,"key":"/copy-file/-/copy-file-11.0.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/copy-file/download/copy-file-11.0.0.tgz"},"_npmUser":{"name":"sindresorhus","email":"sindresorhus@gmail.com"},"directories":{},"maintainers":[{"name":"sindresorhus","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/copy-file_11.0.0_1699170404674_0.6300803525517711"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2023-11-05T07:46:44.904Z","publish_time":1699170404904,"_source_registry_name":"default","_cnpm_publish_time":1699170404904},"0.0.1":{"name":"copy-file","description":"Copies a file","author":{"name":"Chris Khoo"},"version":"0.0.1","main":"src/index.js","licenses":[{"type":"MIT","url":"http://opensource.org/licenses/mit-license.php"}],"engines":{"node":">=0.6.18"},"_npmUser":{"name":"khoomeister","email":"chris.khoo@gmail.com"},"_id":"copy-file@0.0.1","dependencies":{},"devDependencies":{},"optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.21","_nodeVersion":"v0.6.18","_defaultsLoaded":true,"dist":{"shasum":"a772f8d7eb36c8371513ff80bbaade314129dd59","size":643,"noattachment":false,"key":"/copy-file/-/copy-file-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/copy-file/download/copy-file-0.0.1.tgz"},"maintainers":[{"name":"sindresorhus","email":""}],"directories":{},"_cnpmcore_publish_time":"2021-12-23T08:23:38.394Z","publish_time":1338552971448,"_cnpm_publish_time":1338552971448}},"readme":"# copy-file\n\n> Copy a file\n\n## Highlights\n\n- It's super fast by [cloning](https://stackoverflow.com/questions/71629903/node-js-why-we-should-use-copyfile-ficlone-and-copyfile-ficlone-force-what-is) the file whenever possible.\n- Resilient by using [graceful-fs](https://github.com/isaacs/node-graceful-fs).\n- User-friendly by creating non-existent destination directories for you.\n- Can be safe by turning off [overwriting](#overwrite).\n- Preserves file mode [but not ownership](https://github.com/sindresorhus/copy-file/issues/22#issuecomment-502079547).\n- User-friendly errors.\n\n## Install\n\n```sh\nnpm install copy-file\n```\n\n## Usage\n\n```js\nimport {copyFile} from 'copy-file';\n\nawait copyFile('source/unicorn.png', 'destination/unicorn.png');\nconsole.log('File copied');\n```\n\n## API\n\n### copyFile(source, destination, options?)\n\nReturns a `Promise` that resolves when the file is copied.\n\nThe file is cloned if the `onProgress` option is not passed and the [file system supports it](https://stackoverflow.com/a/76496347/64949).\n\n### copyFileSync(source, destination, options?)\n\n#### source\n\nType: `string`\n\nThe file you want to copy.\n\nThe file is cloned if the [file system supports it](https://stackoverflow.com/a/76496347/64949).\n\n#### destination\n\nType: `string`\n\nWhere you want the file copied.\n\n#### options\n\nType: `object`\n\n##### overwrite\n\nType: `boolean`\\\nDefault: `true`\n\nOverwrite existing destination file.\n\n##### cwd\n\nType: `string`\\\nDefault: `process.cwd()`\n\nThe working directory to find source files.\n\nThe source and destination path are relative to this.\n\n##### directoryMode\n\nType: `number`\\\nDefault: `0o777`\n\n[Permissions](https://en.wikipedia.org/wiki/File-system_permissions#Numeric_notation) for created directories.\n\nIt has no effect on Windows.\n\n##### onProgress\n\nType: `(progress: ProgressData) => void`\n\nThe given function is called whenever there is measurable progress.\n\nOnly available when using the async method.\n\n###### `ProgressData`\n\n```js\n{\n\tsourcePath: string,\n\tdestinationPath: string,\n\tsize: number,\n\twrittenBytes: number,\n\tpercent: number\n}\n```\n\n- `sourcePath` and `destinationPath` are absolute paths.\n- `size` and `writtenBytes` are in bytes.\n- `percent` is a value between `0` and `1`.\n\n###### Notes\n\n- For empty files, the `onProgress` callback function is emitted only once.\n\n```js\nimport {copyFile} from 'copy-file';\n\nawait copyFile(source, destination, {\n\tonProgress: progress => {\n\t\t// …\n\t}\n});\n```\n\n## Related\n\n- [cpy](https://github.com/sindresorhus/cpy) - Copy files\n- [cpy-cli](https://github.com/sindresorhus/cpy-cli) - Copy files on the command-line\n- [move-file](https://github.com/sindresorhus/move-file) - Move a file\n- [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed\n","_attachments":{},"homepage":"https://github.com/sindresorhus/copy-file#readme","bugs":{"url":"https://github.com/sindresorhus/copy-file/issues"},"license":"MIT"}