首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NODE.JS --为什么我们要使用: COPYFILE_FICLONE和COPYFILE_FICLONE_FORCE --它是干什么用的?

NODE.JS --为什么我们要使用: COPYFILE_FICLONE和COPYFILE_FICLONE_FORCE --它是干什么用的?
EN

Stack Overflow用户
提问于 2022-03-26 16:32:39
回答 1查看 262关注 0票数 -1

伙计们,我正在通过阅读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_FICLONECOPYFILE_FICLONE_FORCE为什么要使用这两种模式

我研究了“如何复制写”的工作,我发现这些网站:https://www.geeksforgeeks.org/copy-on-write/ https://www.computerhope.com/jargon/c/copy-on-write.htm和我仍然不明白

也许我以为你们能帮我,我能理解为什么

代码语言:javascript
复制
    //*  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结果获得了错误:

代码语言:javascript
复制
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'
}
EN

回答 1

Stack Overflow用户

发布于 2022-03-26 21:20:20

根据医生的说法:

代码语言:javascript
复制
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,有些标志/函数是不可用的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71629903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档