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.】