readable.read(0)


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

如果内部读取缓冲区在 highWaterMark 之下,并且当前没有读取流,那么调用 stream.read(0) 将触发低级 stream._read() 调用。

虽然大多数应用程序几乎不需要这样做,但在 Node.js 中也有这样做的情况,特别是在 Readable 流类内部。

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.