• size <number> 要异步读取的字节数。

该函数不能被应用程序代码直接调用。 它应该由子类实现,且只能被内部的 Readable 类的方法调用。

所有可读流的实现必须提供 readable._read() 方法从底层资源获取数据。

readable._read() 被调用时,如果从资源读取到数据,则需要开始使用 this.push(dataChunk) 推送数据到读取队列。 _read() 应该持续从资源读取数据并推送数据,直到 readable.push() 返回 false。 若想再次调用 _read() 方法,则需要恢复推送数据到队列。

一旦 readable._read() 被调用,它不会被再次调用,除非调用了 readable.push()。 这是为了确保 readable._read() 在同步执行时只会被调用一次。

size 是可选的参数。 对于读取是一个单一操作的实现,可以使用 size 参数来决定要读取多少数据。 对于其他的实现,可以忽略这个参数,只要有数据就提供数据。 不需要等待指定 size 字节的数据在调用 stream.push(chunk)

readable._read() 方法有下划线前缀,因为它是在定义在类的内部,不应该被用户程序直接调用。

  • size <number> Number of bytes to read asynchronously

This function MUST NOT be called by application code directly. It should be implemented by child classes, and called by the internal Readable class methods only.

All Readable stream implementations must provide an implementation of the readable._read() method to fetch data from the underlying resource.

When readable._read() is called, if data is available from the resource, the implementation should begin pushing that data into the read queue using the this.push(dataChunk) method. _read() should continue reading from the resource and pushing data until readable.push() returns false. Only when _read() is called again after it has stopped should it resume pushing additional data onto the queue.

Once the readable._read() method has been called, it will not be called again until the readable.push() method is called. readable._read() is guaranteed to be called only once within a synchronous execution, i.e. a microtick.

The size argument is advisory. For implementations where a "read" is a single operation that returns data can use the size argument to determine how much data to fetch. Other implementations may ignore this argument and simply provide data whenever it becomes available. There is no need to "wait" until size bytes are available before calling stream.push(chunk).

The readable._read() method is prefixed with an underscore because it is internal to the class that defines it, and should never be called directly by user programs.