7
我开始使用我的第一个JavaScript GTK应用程序,我想下载一个文件并使用Gtk.ProgressBar跟踪它的进度。唯一的文档,我可以找到关于HTTP请求是一些示例代码在这里:这里使用gjs,如何使异步http请求以块的形式下载文件?
http://developer.gnome.org/gnome-devel-demos/unstable/weatherGeonames.js.html.en
而且有些混乱汤参考:
http://www.roojs.org/seed/gir-1.2-gtk-3.0/gjs/Soup.SessionAsync.html
据我所知,我能做些什么像这样:
const Soup = imports.gi.Soup;
var _httpSession = new Soup.SessionAsync();
Soup.Session.prototype.add_feature.call(_httpSession, new Soup.ProxyResolverDefault());
var request = Soup.Message.new('GET', url);
_httpSession.queue_message(request, function(_httpSession, message) {
print('download is done');
}
似乎只有一个回调,当下载完成,我不能找到任何方式为任何数据事件设置回调函数。我怎样才能做到这一点?
这是node.js中很容易:
var req = http.request(url, function(res){
console.log('download starting');
res.on('data', function(chunk) {
console.log('got a chunk of '+chunk.length+' bytes');
});
});
req.end();