readable._read(size)
此函数不得由应用代码直接调用。它应该由子类实现,并且只能由内部 Readable
类方法调用。
¥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.
所有 Readable
流实现都必须提供 readable._read()
方法的实现以从底层资源中获取数据。
¥All Readable
stream implementations must provide an implementation of the
readable._read()
method to fetch data from the underlying resource.
调用 readable._read()
时,如果资源中有可用数据,则实现应开始使用 this.push(dataChunk)
方法将该数据推入读取队列。一旦流准备好接受更多数据,则 _read()
将在每次调用 this.push(dataChunk)
后再次调用。_read()
可能会继续从资源中读取并推送数据,直到 readable.push()
返回 false
。只有在停止后再次调用 _read()
时,它才会继续将额外的数据推入队列。
¥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()
will be called again
after each call to this.push(dataChunk)
once the stream is
ready to accept more data. _read()
may 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 into
the queue.
一旦调用了 readable._read()
方法,将不会再次调用它,直到通过 readable.push()
方法推送更多数据。空缓冲区和字符串等空数据不会导致调用 readable._read()
。
¥Once the readable._read()
method has been called, it will not be called
again until more data is pushed through the readable.push()
method. Empty data such as empty buffers and strings will not cause
readable._read()
to be called.
size
参数是建议性的。对于 "read" 是返回数据的单个操作的实现,可以使用 size
参数来确定要获取多少数据。其他实现可能会忽略此参数,并在数据可用时简单地提供数据。在调用 stream.push(chunk)
之前 size
字节可用之前,不需要 "wait"。
¥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)
.
readable._read()
方法带有下划线前缀,因为它是定义它的类的内部方法,不应由用户程序直接调用。
¥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.