Stream highWaterMark misunderstanding

Viewed 20167

After reading some code on Github, it seems like i misandurstood how the highWaterMark concept works.

On a case of a writable stream which would write a big amount of data as fast as possible, here is the idea i had of the lifecycle:

1) While the highWaterMark limit is not reached, the stream is able to buffer and write data.

2) If the highWaterMark limit is reached, the stream cannot buffer anymore, so the #write method returns false to let you know that what you tried to write won't be write (never).

3) Once the stream emits a drain event, it means that the buffer has been cleaned up, and you can write again from where you got "rejected".

It was clear and simple in my mind, but it looks like this is not exactly true (on the step 2), is the data you try to write really "rejected" when the #write method returns false ? Or is it buffered (or something else) ?

Sorry for the basic question but i need to be sure !

3 Answers
Related