Home  >  Article  >  Web Front-end  >  node.js中的fs.fstatSync方法使用说明

node.js中的fs.fstatSync方法使用说明

ringa_lee
ringa_leeOriginal
2018-05-11 13:54:332110browse

方法说明:

同步版的 fstat() 。

方法返回一个stat数组对象,包含以下信息:(以下信息为案例中读取的文件信息,非默认值)

复制代码 代码如下:

{
 
 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

语法:

复制代码 代码如下:

fs.fstatSync(fd)

由于该方法属于fs模块,使用前需要引入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);
};


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn