I have the code:
const readStream = fs.createReadStream(readFilename, {
highWaterMark: 10 * 1024
});
const writeStream = fs.createWriteStream(writeFilename, {
highWaterMark: 1 * 1024
});
readStream.pipe(writeStream);
As you can see, the buffer (highWaterMark) size is different for both. The read has a higher buffer, when read pipes to write it is indeed too much for the write buffer to handle. It reserves 9 * 1014 in memory and after it has handled the entire load it calls drain. This is fine.
However. When writing to write manually via writable.write, false is returned so you may alter the read stream to have a lower buffer (if that's what you wish).
My question is, since I'm piping directly, is there anyway to listen to the write event on the writable? The only thing that I can seem to listen to is the drain event after it has already taken in too much.