readable.read(0)


在某些情况下,需要触发底层可读流的刷新,但实际并不消费任何数据。 在这种情况下,可以调用 readable.read(0),返回 null

如果内部读取缓冲小于 highWaterMark,且流还未被读取,则调用 stream.read(0) 会触发调用底层的 stream._read()

虽然大多数应用程序几乎不需要这样做,但 Node.js 中会出现这种情况,尤其是在可读流类的内部。

There are some cases where it is necessary to trigger a refresh of the underlying readable stream mechanisms, without actually consuming any data. In such cases, it is possible to call readable.read(0), which will always return null.

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.

While most applications will almost never need to do this, there are situations within Node.js where this is done, particularly in the Readable stream class internals.