简体   繁体   English

流打开时如何保持节点应用程序运行?

[英]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.

相关问题 如何实现需要持续运行的节点应用程序? - How can I implement my node application that needs to be constantly running? 当我的鼠标悬停在工具提示上时,如何保持 d3 鼠标悬停? - How can I keep a d3 mouseover open while my mouse is over the tooltip? 悬停在弹出窗口内容上时如何保持 ngbpopovers 打开? - How can I keep ngbpopovers open while being hovered on popover content? 如何在保留顺序的同时异步处理 Node.js 中的 stream 事件? - How can I asynchronously handle stream events in Node.js while preserving order? KineticJS:当补间浏览器选项卡未激活时,如何使补间运行? - KineticJS: How can I keep a tween running while it's browser tab is not active? 我如何打开Chrome并通过节点/电子应用程序执行Google图片搜索 - How can I open chrome and do a google image search from a node/electron application 如何在给定文件描述符的情况下打开nodejs Duplex流? - How can I open a nodejs Duplex stream given a file descriptor? 在 Windows 中,我们如何保持 electron js 应用程序继续在任务管理器中运行 - In Windows how can we keep an electron js application keep running in task manager 登录失败后如何保持模式窗口打开? - How can I keep the modal window open after login failure? 重新加载页面后,如何保持所选标签页处于打开状态 - How can I keep the selected tabs open when page is reloaded
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM