Instructions for using the fs.fsync method in node.js

  • 2020-03-30 04:36:47
  • OfStack

Method description:

Synchronize the disk cache.

Grammar:


fs.fsync(fd, [callback(err)])

Since this method belongs to the fs module, the fs module (var fs= require(" fs ")) needs to be introduced before use.

Receiving parameters:

Fd                            File descriptor

Callback        Callback, passing an exception parameter err

Example:


var fs = require('fs');
fs.open('content.txt', 'a', function(err,fd){
 if(err){
  throw err;
 }
 console.log('file open');
 fs.fsync(fd, function(err){
  if(err){
   throw err;
  }
  console.log('done');
  fs.close(fd,function(err){
   if(err){
    throw err;
   }
   console.log('file closed');
  })
 })
})

Source:


fs.fsync(fd, callback)fs.fsync = function(fd, callback) {
  binding.fsync(fd, makeCallback(callback));
};


Related articles: