読者です 読者をやめる 読者になる 読者になる

たれぱんのびぼーろく

わたしの備忘録、生物学とプログラミングが多いかも

Node.js stream

内部バッファ

internal buffer, internal queue

When chunk is not null, the chunk of data will be added to the internal queue for users of the stream to consume.

push it into the internal buffer.

If the internal read buffer is below the highWaterMark, and the stream is not currently reading, then calling stream.read(0) will trigger a low-level stream._read() call.

Buffering# Both Writable and Readable streams will store data in an internal buffer that can be retrieved using writable.writableState.getBuffer() or readable.readableState.buffer, respectively.

Data is buffered in Readable streams when the implementation calls stream.push(chunk). If the consumer of the Stream does not call stream.read(), the data will sit in the internal queue until it is consumed.

Once the total size of the internal read buffer reaches the threshold specified by highWaterMark, the stream will temporarily stop reading data from the underlying resource until the data currently buffered can be consumed (that is, the stream will stop calling the internal readable._read() method that is used to fill the read buffer).

Data is buffered in Writable streams when the writable.write(chunk) method is called repeatedly. While the total size of the internal write buffer is below the threshold set by highWaterMark, calls to writable.write() will return true. Once the size of the internal buffer reaches or exceeds the highWaterMark, false will be returned.