1. fs-copy-file-sync
fs.copyFileSync ponyfill
fs-copy-file-sync
Package: fs-copy-file-sync
Created by: coderaiser
Last modified: Mon, 02 May 2022 23:23:28 GMT
Version: 1.1.1
License: MIT
Downloads: 274,574
Repository: https://github.com/coderaiser/fs-copy-file-sync

Install

npm install fs-copy-file-sync
yarn add fs-copy-file-sync

fs-copy-file-sync License NPM version Dependency Status Build Status Coverage Status

Node.js v8.5.0 fs.copyFileSync ponyfill.

Synchronously copies src to dest. By default, dest is overwritten if it already exists. Returns undefined. Node.js makes no guarantees about the atomicity of the copy operation. If an error occurs after the destination file has been opened for writing, Node.js will attempt to remove the destination.

Install

npm i fs-copy-file-sync-sync

API

flags is an optional integer that specifies the behavior of the copy operation. It is possible to create a mask consisting of the bitwise OR of two or more values (e.g. fs.constants.COPYFILE_EXCL | fs.constants.COPYFILE_FICLONE).

  • fs.constants.COPYFILE_EXCL - The copy operation will fail if dest already exists.
  • fs.constants.COPYFILE_FICLONE - The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then a fallback copy mechanism is used.
  • fs.constants.COPYFILE_FICLONE_FORCE - The copy operation will attempt to create a copy-on-write reflink. If the platform does not support copy-on-write, then the operation will fail.

Example:

 const copyFileSync = require('fs-copy-file-sync');

// destination.txt will be created or overwritten by default.
copyFileSync('source.txt', 'destination.txt');
console.log('source.txt was copied to destination.txt');

If the third argument is a number, then it specifies flags, as shown in the following example.

 const copyFileSync = require('fs-copy-file-sync');
const { COPYFILE_EXCL } = copyFileSync.constants;

// By using COPYFILE_EXCL, the operation will fail if destination.txt exists.
fs.copyFileSync('source.txt', 'destination.txt', COPYFILE_EXCL);

License

MIT

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin