将文件管道到不同的流

时间:2017-07-17 18:06:03

标签: node.js audio-streaming

我正在使用growing-file读取音频文件并将其传送到可写流,如下所示:

var GrowingFile = require('growing-file')
var audio = GrowingFile.open('test.wav')
audio.pipe(<some writable stream>);

几分钟后,我想改变流传输到的位置。

我试图创建第二个audio.pipe(<new writable stream>)但是现在只写入两个流。我将如何杀死第一个流?

2 个答案:

答案 0 :(得分:0)

不确定这是否是最佳解决方案,但这对我有用:

var GrowingFile = require('growing-file')
var unpipe = require('unpipe');
var audio = GrowingFile.open('test.wav')
audio.pipe(<some writable stream>);

//later in code
unpipe(audio);
audio.pipe(<some new writable stream>);

答案 1 :(得分:0)

请参阅readable.unpipe([destination])

var GrowingFile = require('growing-file')
var audio = GrowingFile.open('test.wav')
var writeableStream = <some writable stream>
audio.pipe(writeableStream);

setTimeout(() => {
  audio.unpipe(writeableStream)
  writeableStream = <some other writable stream>
  audio.pipe(writeableStream)
}, 60000)