How to use the fsync function from fs-extra

Find comprehensive JavaScript fs-extra.fsync code examples handpicked from public code repositorys.

252
253
254
255
256
257
258
259
260
261
let stream = zip.generateNodeStream({ compression: "DEFLATE" });
let fd = await fs.open(tempSavePath, "w");
try {
	let pipe = stream.pipe(fs.createWriteStream("", { fd, autoClose: false }));
	await events.once(pipe, "finish");
	await fs.fsync(fd);
} finally {
	await fs.close(fd);
}
await fs.rename(tempSavePath, savePath);
fork icon58
star icon228
watch icon0

719
720
721
722
723
724
725
726
727
728
if (file) {
  patch.file = patch.originalFile
  const filePath = datasetUtils.filePath({ ...dataset, ...patch })
  // Try to prevent weird bug with NFS by forcing syncing file before sampling
  const fd = await fs.open(filePath, 'r')
  await fs.fsync(fd)
  await fs.close(fd)
  const fileSample = await datasetFileSample({ ...dataset, ...patch })
  debugFiles(`Attempt to detect encoding from ${fileSample.length} first bytes of file ${filePath}`)
  patch.file.encoding = chardet.detect(fileSample)
fork icon6
star icon26
watch icon4

294
295
296
297
298
299
300
301
302
303
var flowFile = 'test.json';
var flowFilePath = path.join(userDir,flowFile);
localfilesystem.init({editorTheme:{projects:{enabled:false}},userDir:userDir, flowFile:flowFilePath,getUserSettings: () => {{}}}, mockRuntime).then(function() {
    sinon.spy(fs,"fsync");
    localfilesystem.saveFlows(testFlow).then(function() {
        fs.fsync.callCount.should.be.greaterThan(0);
        fs.fsync.restore();
        done();
    }).catch(function(err) {
        fs.fsync.restore();
fork icon1
star icon4
watch icon0

+ 5 other calls in file

80
81
82
83
84
85
86
87
88
89
writeFile: function(path,content) {
    return when.promise(function(resolve,reject) {
        var stream = fs.createWriteStream(path);
        stream.on('open',function(fd) {
            stream.write(content,'utf8',function() {
                fs.fsync(fd,function(err) {
                    if (err) {
                        log.warn(log._("storage.localfilesystem.fsync-fail",{path: path, message: err.toString()}));
                    }
                    stream.end(resolve);
fork icon0
star icon0
watch icon0

110
111
112
113
114
115
116
117
118
119
function writeFile(path,content) {
    return when.promise(function(resolve,reject) {
        var stream = fs.createWriteStream(path);
        stream.on('open',function(fd) {
            stream.end(content,'utf8',function() {
                fs.fsync(fd,resolve);
            });
        });
        stream.on('error',function(err) {
            reject(err);
fork icon0
star icon0
watch icon0

function icon

fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)