事件:'unpipe'


【Event: 'unpipe'

当在 Readable 流上调用 stream.unpipe() 方法时,会触发 'unpipe' 事件,从其目标集合中移除该 Writable

【The 'unpipe' event is emitted when the stream.unpipe() method is called on a Readable stream, removing this Writable from its set of destinations.】

如果当一个 Readable 流管道进入 Writable 流时出现错误,也会发出这个。

【This is also emitted in case this Writable stream emits an error when a Readable stream pipes into it.】

const writer = getWritableStreamSomehow();
const reader = getReadableStreamSomehow();
writer.on('unpipe', (src) => {
  console.log('Something has stopped piping into the writer.');
  assert.equal(src, reader);
});
reader.pipe(writer);
reader.unpipe(writer);