forked from joshmarinacci/ElectronIDE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_download.js
37 lines (33 loc) · 1.29 KB
/
test_download.js
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
33
34
35
36
37
var fs = require('fs');
var http = require('http');
var AdmZip = require('adm-zip');
//var src = 'http://www.airspayce.com/mikem/arduino/AccelStepper/AccelStepper-1.41.zip';
var src = 'http://joshondesign.com/p/apps/electron/platforms/1.0.5/arduino-1.0.5-darwin-trimmed.tar.gz';
var outfile = './'+src.substring(src.lastIndexOf('/')+1);
var outdir = 'blah';
console.log('downloading ', src);
console.log("output file = ",outfile);
console.log("outdir = ",outdir);
var req = http.get(src);
req.on('response', function(res) {
var total = res.headers['content-length']; //total byte length
var count = 0;
res
.on('data', function(data) {
count+=data.length; // add byte length from this chunk
console.log( (100*count/total).toFixed(1) + "%");
})
.pipe(fs.createWriteStream(outfile))
.on('close',function(){
console.log('Success!');
/*
var zip = new AdmZip(outfile);
var zipEntries = zip.getEntries();
var rootpath = zipEntries[0].entryName;
rootpath = rootpath.substring(0,rootpath.indexOf('/'));
zip.extractAllTo(outdir,true);
console.log("root path = ",rootpath);
console.log('done extracting from ',outfile);
*/
});
});