godking.http下载文件演示(带速度和进度)

光庆 4月前 692

Code AardioLine:32复制
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
    • import console;
    • import fsys;
    • import godking.http;
    • var url = "https://pc-package.wpscdn.cn/wps/download/W.P.S.60.1955.exe";
    • var startinfo = {};
    • var data,header,result = godking.http({
    • url = url;
    • file = "C:\Users\Administrator\Desktop\W.P.S.60.1955.exe";
    • packageSize = 1024*1024;
    • callback = function(callbackID,已下载大小,总大小,网址,本地文件名){
    • if !startinfo.time {
    • startinfo.time = time.tick();
    • startinfo.size = 已下载大小;
    • }
    • if 已下载大小===-1 and 总大小===-1 console.log("下载完毕!");
    • else {
    • var time = (time.tick()-startinfo.time)/1000;
    • var size = 已下载大小-startinfo.size;
    • if time>0 {
    • console.dump("下载时间:" ++ time ++ "秒");
    • console.dump("下载大小:" ++ fsys.formatSize(size));
    • console.dump("下载速度:" ++ fsys.formatSize(math.round(size/time,0)) ++ "/秒");
    • }
    • console.dump("下载进度:" ++ math.round(已下载大小*100/总大小,2) ++ "%",'\n');
    • }
    • }
    • })
    • if (result.success) {
    • console.logPause("文件已下载完成,请自行验证文件完整性!");
    • } else {
    • console.logPause("下载错误:"++result.info);
    • }


    最新回复 (4)
    • shzhbook 4月前
      0 2

    • breezee 4月前
      0 3
      光庆大佬高产啊!
    • 沉默的斗鱼 4月前
      0 4
      主要是光庆大佬的笨徒弟太能学习提问了
    • netfox 4月前
      0 5

      大佬的http,好用,耐用

    返回