Node.js像功能一样流

时间:2015-01-28 20:57:30

标签: javascript node.js

我正在制作一个非常简单的应用程序,允许用户(朋友和家人,没有公开)从YouTube等网站下载视频。我现在正在编写包含youtube-dl程序的模块。

我正在尝试做什么:一旦我请求模块开始下载视频,模块就会生成一个新进程并启动下载。 youtube-dl程序将经常返回下载百分比以及其他一些细节。我能够检索这些数据,但现在我想将这些数据传递给请求下载的用户。有没有办法以类似流的方式做到这一点?

我的意思是:

var video = downloader( 'https://www.youtube.com/watch?v=XXX' );

// Will be called when the video starts downloading
video.on( 'start, function( info ) { ... } );

// Will be called when new data has been downloaded, contains the percentage etc.
video.on( 'update', function( info ) { ... } );

下载视频并检索百分比的部分大部分都已完成,我只是不知道如何以流的方式将数据发送到调用模块下载视频的应用程序。

不确定我是否正确解释并理解,如果您有任何疑问,请询问。

编辑:也许我应该使用这样的东西?:http://code.tutsplus.com/tutorials/using-nodes-event-module--net-35941

0 个答案:

没有答案
相关问题