我为了个人用途下载了npm module
个文件
使用request
并使用progress
https://github.com/MaxySpark/maxyspark-download
但是当我测试它时,回调函数首先执行,它应该在完成下载后执行。
我的测试文件
const maxDonwload = require('maxyspark-download');
var filename = "prog.gif";
var url = "http://skillprogramming.com/images/pictuers/how_many_of_you_get_the_same_feeling.gif";
function endFunc() {
console.log("download completed : "+filename);
}
maxDonwload.download(url,filename,endFunc());
这是输出
download completed : prog.gif
File Size : 0.50 MB
downloading [====================] 100% 0.0s
HERE HERE
我在
中的node-modules index.js文件中添加了一行console.log("HERE HRERE");
req.on('end' function() {
console.log("HERE HRERE");
callback;
}
console.log(" HERE HRERE");在下载完成后执行,但回调不是。
答案 0 :(得分:3)
您正在调用该函数,而应将其作为参数传递而不使用():
maxDonwload.download(url,filename,endFunc);
答案 1 :(得分:1)
您正在调用endFunc(),而不是将函数本身作为参数传递。
这应该解决它:
System.setProperty("webdriver.gecko.driver", "path/to/geckodriver.exe");
DesiredCapabilities d = new DesiredCapabilities();
d.setCapability("marionette", false); // to disable marionette, by default true
WebDriver driver = new FirefoxDriver(d);