Closed Nokel81 closed 2 years ago
How does https://nodejs.org/api/fs.html#fspromisesopenpath-flags-mode work here?
It works quite well because (I assume) it uses the syscalls immediately, which is why it is async
.
If that works, why not just use that?
I am, I was wondering if something like it should be lifted up into this package or easier reuse by others.
The reason why it is more than just a call to open
is because there also needs the following (or something like it if this is wrong):
new Writable({
write(chunk, encoding, cb) {
fileHandle.write(chunk)
.then(() => cb())
.catch(cb);
},
});
Ah I see, that was added in node 16 and I am on node 14. Sorry for the noise.
I just ran into this problem with the
fs
and was wondering if this package should have a good solution to this.I have just discovered that in some cases
createWriteStream
doesn't immediately throw errors if you pass in flags"wx"
for instance.I found that it possible to get around this by calling
await open(path, ...)
and then wrapping the file handle in astream.Writable
.I am wondering if some a function would be useful here?