'end' 事件
当流中没有更多数据可供消费时,则会触发 'end'
事件。
除非数据被完全地消费,否则不会触发 'end'
事件。
这可以通过将流切换到流动模式来实现,或者通过重复调用 stream.read()
直到所有数据都被消费完。
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.');
});
The 'end'
event is emitted when there is no more data to be consumed from
the stream.
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.');
});