Guys I am trying to learn Node.js by reading Node.js documentation.
I began to learn fs module firstly
and while learning I saw this explanation:
mode 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
).
at https://nodejs.org/api/fs.html#fscopyfilesrc-dest-mode-callback
I didn't understand what COPYFILE_FICLONE
and COPYFILE_FICLONE_FORCE
are for, and why we are using these two modes
I researched about "how copy-on-write" works" and found these websites:
- https://www.geeksforgeeks.org/copy-on-write/
- https://www.computerhope.com/jargon/c/copy-on-write.htm
and I still didn't understand
may be I thought you guys can help to me and I can understand why is
//* Module *//
let fs = require('fs');
//* Variables *//
source = 'source.txt';
destination = 'hesyy.txt';
//* call back function for error *//
function callback(err) {
if (!err){
console.log("source.txt copied to destination");
} else throw err;
}
// the copy operation will fail if dest already exists.
const {COPYFILE_EXCL} = fs.constants;
// 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.
const {COPYFILE_FICLONE} = fs.constants;
// 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.
const {COPYFILE_FICLONE_FORCE} = fs.constants;
// fs.copyFile(source,destination,callback);
// fs.copyFile(source,destination,COPYFILE_EXCL,callback);
// fs.copyFile(source,destination,COPYFILE_FICLONE,callback);
fs.copyFile(source,destination,COPYFILE_FICLONE_FORCE,err => {
if (!err) {
console.log("Copied");
}else{
console.log("err yo:",err);
}
});
running :
node copyFile.js
and I got an error by using COPYFILE_FICLONE_FORCE
:
err yo: [Error: ENOSYS: function not implemented, copyfile 'C:\Users\CENSORED\Desktop\nodejss\fs\fs.copyFile\source.txt' -> 'C:\Users\CENSORED\Desktop\nodejss\fs\fs.copyFile\hessyy.txt'] {
errno: -4054,
code: 'ENOSYS',
syscall: 'copyfile',
path: 'C:\\Users\\CENSORED\\Desktop\\nodejss\\fs\\fs.copyFile\\source.txt',
dest: 'C:\\Users\\CENSORED\\Desktop\\nodejss\\fs\\fs.copyFile\\hessyy.txt'
}