In the Node.js website API, questions about readable._read(size)?

  node.js, question

When learning Node.js, check the official website documentation. Regarding the API readable._read(size), the official website has the following passage:
When _read is called, if data is available from the resource, _read should start pushing that data into the read queue by calling this.push(dataChunk) . _read should continue reading from the resource and pushing data until push returns false, at which point it should stop reading from the resource. Only when _read is called again after it has stopped should it start reading more data from the resource and pushing that data onto the queue.

Note:once the _read() method is called, it will not be called again until the push method is called.

The questions are as follows:

  1. Why does _read trigger the push operation?

  2. _read why is it designed to correlate push operations?

1)_read method is implemented when you implement the readable interface as the underlying excuse, and cannot be called directly.
2)_read method reads the data content from the underlying data stream, and then puts it into the user’s data consumption queue through push method until the user’s data consumption queue is full. At this time, the reading of data is stopped.
3) when the data in the user consumption queue is acquired by the user through monitoring the data event, the _read method will be called again to fill the user data consumption queue
4) This process continues until the end of the data is reached

_read method needs to be implemented when implementing its readable stream object, which is triggered by the underlying system call. You can’t call directly ~ ~ ~