readable.read(0)
在某些情况下,需要触发底层可读流机制的刷新,而不实际消耗任何数据。在这种情况下,可以调用 readable.read(0)
,它总是返回 null
。
¥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
.
如果内部读取缓冲区低于 highWaterMark
,并且当前未读取流,则调用 stream.read(0)
将触发底层的 stream._read()
调用。
¥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.
虽然大多数应用几乎不需要这样做,但在 Node.js 中有一些情况需要这样做,特别是在 Readable
流类内部。
¥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.