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

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

WBOY
WBOYOriginal
2016-05-16 16:27:041550browse

方法说明:

同步版的 fsync() 。同步磁盘缓存。

语法:

复制代码 代码如下:

fs.fsyncSync(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');
 
 fs.fsyncSync(fd);
 
 fs.close(fd,function(err){
  if(err){
   throw err;
  }
  console.log('file closed');
 })
})

源码:

复制代码 代码如下:

fs.fsyncSync = function(fd) {
  return binding.fsync(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