readable.unpipe([destination])


新增于: v0.9.4

readable.unpipe() 方法分离先前使用 stream.pipe() 方法附加的 Writable 流。

\The readable.unpipe() method detaches a Writable stream previously attached using the stream.pipe() method.

如果未指定 destination,则分离所有管道。

\If the destination is not specified, then all pipes are detached.

如果指定了 destination,但没有为其设置管道,则该方法不执行任何操作。

\If the destination is specified, but no pipe is set up for it, then the method does nothing.

const fs = require('node: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); 

AltStyle によって変換されたページ (->オリジナル) /