Right now it's pretty complicated to intermix fs.fsync() calls with ws.write() calls, to the point that you lose most of the benefits of using fs.WriteStream. Example:
constfs=require('fs');constws=fs.createWriteStream('test.txt');ws.write('important data',()=>{fs.fsync(ws.fd,()=>{// only now is it safe again to call ws.write()ws.write('more important data',()=>{fs.fsync(ws.fd,()=>{/* etc. */});});});});It would be exceedingly helpful if fs.WriteStream grew a .fsync() method that preserves order with respect to writes so that the following example works like I would expect it to:
constws=require('fs').createWriteStream('test.txt');ws.write('important data');ws.fsync();ws.write('more important data');ws.fsync();
It's not quite impossible to accomplish the above today but it's not very ergonomic. Here is an async/await example:
constutil=require('util');constfs=require('fs');constws=fs.createWriteStream('test.txt');ws.once('open',(fd)=>go(fd));asyncfunctiongo(fd){constwrite=util.promisify(ws.write.bind(ws));constfsync=util.promisify(fs.fsync.bind(null,fd));awaitwrite('important data');awaitfsync();awaitwrite('more important data');awaitfsync();}I don't know, the fact that you need to know about the 'open' event doesn't give me warm fuzzies. Proper synchronization is important enough that I feel it merits a place in core.
Right now it's pretty complicated to intermix
fs.fsync()calls withws.write()calls, to the point that you lose most of the benefits of usingfs.WriteStream. Example:It would be exceedingly helpful if
fs.WriteStreamgrew a.fsync()method that preserves order with respect to writes so that the following example works like I would expect it to:It's not quite impossible to accomplish the above today but it's not very ergonomic. Here is an async/await example:
I don't know, the fact that you need to know about the
'open'event doesn't give me warm fuzzies. Proper synchronization is important enough that I feel it merits a place in core.