node.js - windows只读属性中的nodejs fs模式操作

标签 node.js ntfs fs file-attributes

我是 NodeJS 的新手,我很难解密模式值并弄清楚如何更改模式以删除只读等属性。以下是我发现此文件夹的模式为 16822 的方式。如何确定 16822 在 Windows 中的含义,然后如何更改模式以使其不具有只读属性?

fs.mkdir('./build');
fs.stat('./build', function(err, stats){
   if(stats.isDirectory()){
       console.log('Its a dir');

       for(var i in stats){
           if('function' !== typeof stats[i]){
               console.log(i + '\t= ' + stats[i]);
           }
       }
   }
});

最佳答案

我找到了解决方案。基本上,只读文件和不只读文件之间的位差值为 146。检查位后,我发现此差值与模式值(128、16 和 2)相匹配。这是我的解决方案:github issue with readonly

还进行了改进,我将流传递给一个允许我转换文件然后使用事件流传递它的函数:

function removeReadonly(){
  function transform(file, cb){
    if((file.stat.mode & 146) == 0){
      file.stat.mode = file.stat.mode | 146;
    }
    cb(null,file);
  };

  return require('event-stream').map(transform);
};

关于node.js - windows只读属性中的nodejs fs模式操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29130242/

相关文章:

c++ - 使用 WinApi 可靠地知道卷是否可移动

Node.js fs 模块和 windows 路径

javascript - Fabric.JS 与 Node.JS - 导出为 PNG/JPEG

mysql - Node-JS 将 Mysql DB 作为 Rest 服务公开

macos - mac有什么好的node.js IDE吗?

javascript - 使用 module.exports 上面的函数可以吗?

c++ - DeviceIoControl GetLastError 87 (ERROR_INVALID_PARAMETER)

javascript - 类型错误 : fs. createReadStream 不是函数

python - 使用 python 检查文件夹/文件 ntfs 权限

angularjs - 在 gulp 构建期间将 git commit hash 添加到 javascript 变量