我是 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/