Description of the fs. fstat method in node. js, node. jsfs. fstat
Method description:
Obtain the file information based on the file descriptor.
Syntax:
Copy codeThe Code is as follows:
Fs. fstat (fd, [callback (err, stats)])
Because this method belongs to the fs module, we need to introduce the fs module (var fs = require ("fs") before use "))
Receiving parameters:
Fd file descriptor
Callback. Two parameters are passed, namely the error parameter err and the file information parameter stats.
Stats contains the following information: (The following information is the file information read in the case, not the default value)
Copy codeThe Code is as follows:
{
Dev: 0,
Mode: 33206,
Nlink: 1,
Uid: 0,
Gid: 0,
Rdev: 0,
Ino: 0,
Size: 378 (bytes ),
Atime: Tue Jun 10 2014 13:57:13 GMT + 0800 <China Standard Time>,
Mtime: Tue Jun 13 2014 09:48:31 GMT + 0800 <China Standard Time>,
Ctime: Tue Jun 10 2014 13:57:13 GMT + 0800 <China Standard Time>
}
Example:
Copy codeThe Code is as follows:
Var fs = require ('fs ');
Fs.open('content.txt ', 'A', function (err, fd ){
If (err ){
Throw err;
}
Console. log ('file open ');
Fs. fstat (fd, function (err, stats ){
If (err ){
Throw err;
}
Console. log (stats );
Fs. close (fd, function (){
Console. log ('file close ');
})
})
})
Source code:
Copy codeThe Code is as follows:
Fs. lstat = function (path, callback ){
Callback = makeCallback (callback );
If (! NullCheck (path, callback) return;
Binding. lstat (pathModule. _ makeLong (path), callback );
};