readable.unpipe([destination])
destination
<stream.Writable> 可选的要取消管道的特定流- 返回: <this>
readable.unpipe()
方法分离先前使用 stream.pipe()
方法绑定的 Writable
流。
如果未指定 destination
,则所有管道都将分离。
如果指定了 destination
,但没有为其设置管道,则该方法不执行任何操作。
const fs = require('fs');
const readable = getReadableStreamSomehow();
const writable = fs.createWriteStream('file.txt');
// 可读流的所有数据进入 'file.txt',
// 但只有第一秒。
readable.pipe(writable);
setTimeout(() => {
console.log('Stop writing to file.txt.');
readable.unpipe(writable);
console.log('Manually close the file stream.');
writable.end();
}, 1000);
destination
<stream.Writable> Optional specific stream to unpipe- Returns: <this>
The readable.unpipe()
method detaches a Writable
stream previously attached
using the stream.pipe()
method.
If the destination
is not specified, then all pipes are detached.
If the destination
is specified, but no pipe is set up for it, then
the method does nothing.
const fs = require('fs');
const readable = getReadableStreamSomehow();
const writable = fs.createWriteStream('file.txt');
// All the data from readable goes into 'file.txt',
// but only for the first second.
readable.pipe(writable);
setTimeout(() => {
console.log('Stop writing to file.txt.');
readable.unpipe(writable);
console.log('Manually close the file stream.');
writable.end();
}, 1000);