411
return fs.writeFile(path, data, { mode: options.mode, flag: options.flag }, callback);
412
}
414
>
// Open the file with same flags and mode as fs.writeFile()
415
>
fs.open(path, options.flag, options.mode, (openError, fd) => {
416
>
if (openError) {
417
return callback(openError);
418
}
420
>
// It is valid to pass a fd handle to fs.writeFile() and this will keep the handle open!
421
>
fs.writeFile(fd, data, writeError => {
422
>
if (writeError) {
423
return fs.close(fd, () => callback(writeError)); // still need to close the handle on error!
424
}
426
>
// Flush contents (not metadata) of the file to disk
427
>
// https://github.com/microsoft/vscode/issues/9589
428
>
fs.fdatasync(fd, (syncError: Error | null) => {
429
>
430
>
// In some exotic setups it is well possible that node fails to sync
431
>
// In that case we disable flushing and warn to the console
432
>
if (syncError) {
433
console.warn('[node.js fs] fdatasync is now disabled for this session because it failed: ', syncError);
434
configureFlushOnWrite(false);
435
}
437
>
return fs.close(fd, closeError => callback(closeError));
438
>
});
439
>
});
440
>
});
441
>
}
442
443
/**