From f45f279f6d92b6c181f75768822e84effdf8e7aa Mon Sep 17 00:00:00 2001 From: huqi Date: Fri, 17 Apr 2020 17:00:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9gulpfile=EF=BC=8C=E4=BB=8Egit?= =?UTF-8?q?lab=E4=B8=8B=E8=BD=BDcommons=E5=92=8Cjvm?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gulpfile.js | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index e2e97ea7df..d2ac296535 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -99,7 +99,7 @@ function ProgressBar(description, bar_length){ }; } -function downloadFile(path, filename, headcb, progresscb, cb){ +function downloadFile_progress(path, filename, headcb, progresscb, cb){ var dest = `o2server/${filename}`; // fs.exists(dest, function(exists) { @@ -144,7 +144,7 @@ function downloadFile(path, filename, headcb, progresscb, cb){ }); request.get(options).pipe(str).pipe(stream); } else { - gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+response.statusCode); + gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+res.statusCode); } }) req.on('error', (e) => { @@ -154,6 +154,61 @@ function downloadFile(path, filename, headcb, progresscb, cb){ // } //}); } +function downloadFile(path, filename, headcb, progresscb, cb){ + var dest = `o2server/${filename}`; + + // fs.exists(dest, function(exists) { + // if (exists){ + // headcb(1); + // progresscb({transferred:1}); + // cb(); + // }else{ + let stream = fs.createWriteStream(dest); + var options = { url:protocol+"://"+downloadHost+path }; + var fileHost = downloadHost; + var filePath = path; + stream.on('finish', () => { + //gutil.log("download", ":", gutil.colors.green(filename), " completed!"); + cb(); + }); + stream.on('error', (err) => { + gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), err); + }); + + // var req = http.request({ + // host:fileHost, + // path:filePath, + // method:'HEAD' + // },function (res){ + // if (res.statusCode == 200) { + // res.setEncoding(null); + // var time = 0; + // var l = res.headers['content-length']; + // var str = progress({ + // length: l, + // time: 100 /* ms */ + // }); + // headcb(l); + // + // str.on('progress', function(progress) { + // if (pb){ + // progresscb(progress); + // pb.render({ completed: currentLength, total: totalLength, time: time+=100 }); + // } + // + // }); + request.get(options).pipe(stream); + // } else { + // gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), "statusCode:"+res.statusCode); + // } + // }) + // req.on('error', (e) => { + // gutil.log(gutil.colors.red("download error"), ":", gutil.colors.red(filename), e); + // }); + // req.end(); + // } + //}); +} var commonsLength = 0; var jvmLenght = 0; -- GitLab