如何在不丢失数据的情况下中止流中的请求?(node.js)

时间:2017-10-26 03:23:07

标签: node.js stream request pipe

我想录制IP摄像机视频,我有录制和停止录制按钮。 我按下录制按钮时可以录制视频。 但是当我按下停止记录时,我不知道如何停止请求。 我使用request.abort()。它可以停止请求,但也会丢弃我下载的数据。 IP摄像头处于http://192.168.0.55:8080

filename = './video1.ogg';
file = fs.createWriteStream(filename);
if(req.body.record == 1) //recording
{
    theRequest = request('http://192.168.0.55:8080/');
    theRequest.pipe(file);
}
else if(req.body.record == 0) //stop recording
{
    theRequest.abort();
}

谢谢你的帮助

1 个答案:

答案 0 :(得分:0)

else if(req.body.record == 0) //stop recording
{
    theRequest.pause();//add pause will solve this problem
    theRequest.abort();
}