方法說明
fstat() 的同步版本,根據檔案描述符同步取得檔案資訊並直接回傳 stats 物件。欄位如下(以下為範例中讀取到的實際值,並非固定預設值):
{
dev : 0,
mode : 33206,
nlink : 1,
uid : 0,
gid : 0,
rdev : 0,
ino : 0,
size : 378, // 位元組
atime : Tue Jun 10 2014 13:57:13 GMT +0800 <中國標準時間>,
mtime : Tue Jun 13 2014 09:48:31 GMT +0800 <中國標準時間>,
ctime : Tue Jun 10 2014 13:57:13 GMT +0800 <中國標準時間>
}
語法
fs.fstatSync(fd)
此方式屬於 fs 模組,使用前必須先引入:var fs = require("fs")
參數說明
fd:檔案描述符。
範例
var fs = require('fs');
fs.open('content.txt', 'a', function(err, fd){
if (err) {
throw err;
}
console.log('file open');
var statInfo = fs.fstatSync(fd);
console.log(statInfo);
fs.close(fd, function(){
console.log('file close');
});
});
原始碼
fs.fstatSync = function(fd) {
return binding.fstat(fd);
};