Instructions for the fs.fstatSync method in node.js

  • 2020-05-05 10:54:58
  • OfStack

method description:

Synchronous version of fstat().

Method returns an stat array object with the following information :(the following information is the file information read in the case, not the default)


{
 
 dev : 0 ,
 
 mode : 33206 ,
 
 nlink : 1 ,
 
 uid : 0 ,
 
 gid : 0 ,
 
 rdev : 0 ,
 
 ino : 0 ,
 
 size : 378( byte ) ,
 
 atime : Tue Jun 10 2014 13:57:13 GMT +0800 < Chinese standard time > ,
 
 mtime : Tue Jun 13 2014 09:48:31 GMT +0800 < Chinese standard time > ,
 
 ctime : Tue Jun 10 2014 13:57:13 GMT +0800 < Chinese standard time >
 
}

syntax:


fs.fstatSync(fd)

Since this method belongs to the fs module, the fs module (var fs= require(" fs "))

needs to be introduced before use

Receive parameter:

fd                             file descriptor

Example of :


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');
 })
})

source code:


fs.fstatSync = function(fd) {
  return binding.fstat(fd);
};


Related articles: