[英]How can I keep node application running while stream is open?
I'm wondering what a good solution would be to keep a Node application running until a readable stream has closed. 我想知道一种好的解决方案是保持Node应用程序运行,直到可读流关闭。 So in a simple example such as this:
因此,在这样的简单示例中:
var tcpVideoStream = new TcpVideoStream(options);
var writeStream = fs.createWriteStream(options.fileName);
tcpVideoStream.pipe(writeStream);
How can keep my application running so that it continues to write the streaming data to file until the readable stream, tcpVideoStream in this case, closes? 如何保持我的应用程序运行,以使其继续将流数据写入文件,直到可读流(在这种情况下为tcpVideoStream)关闭? ie emits 'end' or 'close'.
即发出“结束”或“关闭”。
Thanks! 谢谢!
Your application will not close until the data has been fully piped. 您的应用程序将在数据完全管道化后关闭。 Your application will only close if the readable stream remains is, such as when there is no
data
event listener, or you haven't called resume()
on it (if it is already paused). 只有在可读流保持不变的情况下(例如,当没有
data
事件侦听器时,或者您尚未在其上调用resume()
(如果已暂停)),您的应用程序才会关闭。 Using pipe()
is like adding a data
listener. 使用
pipe()
就像添加一个data
侦听器。
For example, this will exit with no output. 例如,这将退出而没有输出。
var fs = require('fs');
var read = fs.createReadStream('./src');
var write = fs.createWriteStream('./dest');
read.pause();
read.on('data', function(chunk) {
console.log(chunk);
});
You might want to look at this page. 您可能需要查看此页面。 {for WriteStreams}
{适用于WriteStreams}
http://nodejs.org/docs/v0.6.18/api/stream.html#stream_stream_pipe_destination_options http://nodejs.org/docs/v0.6.18/api/stream.html#stream_stream_pipe_destination_options
Basically using {end: false} keeps the write stream open so that you can dispatch another end event. 基本上使用{end:false}可使写流保持打开状态,以便您可以调度另一个end事件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.