事件:'end'


【Event: 'end'

当流中没有更多数据可供消费时,会触发 'end' 事件。

【The 'end' event is emitted when there is no more data to be consumed from the stream.】

除非数据被完全消耗,否则不会触发 'end' 事件。这可以通过将流切换到流动模式,或重复调用 stream.read(),直到所有数据被消耗完来实现。

【The 'end' event will not be emitted unless the data is completely consumed. This can be accomplished by switching the stream into flowing mode, or by calling stream.read() repeatedly until all data has been consumed.】

const readable = getReadableStreamSomehow();
readable.on('data', (chunk) => {
  console.log(`Received ${chunk.length} bytes of data.`);
});
readable.on('end', () => {
  console.log('There will be no more data.');
});