伙计们,我正在通过阅读NODE.JS文档来学习node.js。
我首先开始学习fs模块。
在学习的同时,我看到了这个解释:
“
”模式是一个可选的整数,它指定复制操作的行为。可以创建一个掩码,该掩码由两个或多个值的按位OR组成(例如,fs.constants.COPYFILE_EXCL two fs.constants.COPYFILE_FICLONE)。
在https://nodejs.org/api/fs.html#fscopyfilesrc-dest-mode-callback
我不明白COPYFILE_FICLONE和COPYFILE_FICLONE_FORCE为什么要使用这两种模式
我研究了“如何复制写”的工作,我发现这些网站:https://www.geeksforgeeks.org/copy-on-write/ https://www.computerhope.com/jargon/c/copy-on-write.htm和我仍然不明白
也许我以为你们能帮我,我能理解为什么
//* 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;
}
const {COPYFILE_EXCL} = fs.constants; // the copy operation will fail if dest already exists.
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 a fallback copy mechanism is used.
const {COPYFILE_FICLONE_FORCE} = 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.
// 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);
}
});运行:节点copyFile.js和我通过使用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'
}发布于 2022-03-26 21:20:20
根据医生的说法:
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).
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.所以您使用的是WINDOWS,有些标志/函数是不可用的。
https://stackoverflow.com/questions/71629903
复制相似问题