我正在尝试从某个URL下载视频,它正在下载视频,但也会返回Parse Error,因此回调会发生两次。
http.get(url, function(response) {
console.log("url "+url)
console.log("Got response: " + response.statusCode);
if(response && response.statusCode == 200){//OK
mkdirp(dest,function(err){
if(err){
console.log("err "+err);
}else{ //create path dynamically
console.log("else SUCCESS")
var file = fs.createWriteStream("/mydrive/test.flv");
response.pipe(file);
file.on('finish', function() {
//console.log("finish file creation....")
file.close();
});
}
});
}else{
console.log("No video "+response.statusCode);
}
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
输出我得到的是回调发生两次。
我想要回复或失败回调:
Got response: 200
Got error: Parse Error