方法說明
透過檔案描述符來變更檔案權限,適合已經用 fs.open 開啟檔案的情境。
語法
fs.fchmod(fd, mode, [callback(err)])
此方式屬於 fs 模組,使用前必須先引入:var fs = require("fs")
參數說明
fd:檔案描述符。
mode:要設定的檔案權限。
callback:回調函式,接收 err 異常參數。
範例
fs.open('content.txt', 'a', function (err, fd) {
if (err) {
throw err;
}
fs.fchmod(fd, 0777, function(err){
if (err) {
throw err;
}
console.log('fchmod complete');
fs.close(fd, function () {
console.log('Done');
});
});
});
原始碼
fs.fchmod = function(fd, mode, callback) {
binding.fchmod(fd, modeNum(mode), makeCallback(callback));
};