Skip to content

Commit

Permalink
fix download of zip files
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Marinacci committed Jun 23, 2014
1 parent fd8c3b5 commit fdcf712
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 17 deletions.
35 changes: 20 additions & 15 deletions libraries.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
var fs = require('fs');
var spawn = require('child_process').spawn;
var http = require('http');
var unzip = require('unzip');
var AdmZip = require('adm-zip');



var settings = require('./settings.js');
var master = null;
var libs = null;


function isInstalled() {
//console.log('checking if',this.id,'is installed');
console.log('checking if',this.id,'is installed');
if(this.source == 'ide') return true;
var path = settings.repos+'/'+this.id;
console.log('checking if path exists',path);
if(fs.existsSync(settings.repos+'/'+this.id)) return true;
return false;
}
Expand Down Expand Up @@ -67,22 +71,23 @@ function install(cb) {
if(this.source == 'http'){
console.log("source is http",this.location);
var outpath = settings.repos;
var outfile = settings.repos+'/'+this.location.substring(this.location.lastIndexOf('/')+1);
console.log("output file = ",outfile);
var req = http.get(this.location)
.on('response',function(res){
//console.log("response");
/*
res.on('error',function(err){
console.log('err');
})
.on('end',function(){
console.log("fisinshed download");
})
*/
res.pipe(unzip.Extract({path:outpath}))
.on('close',function() {
console.log("finished inflating");
console.log("response");
res.pipe(fs.createWriteStream(outfile)).on('close',function(){
console.log('finished downloading');
var zip = new AdmZip(outfile);
var zipEntries = zip.getEntries();
var rootpath = zipEntries[0].entryName;
rootpath = rootpath.substring(0,rootpath.indexOf('/'));
console.log("rootpath of the zip is",rootpath);
zip.extractAllTo(settings.repos,true);
console.log('done extracting from ',outfile, 'to',settings.repos);
fs.renameSync(settings.repos+'/'+rootpath, settings.repos+'/'+rootpath.toLowerCase());
if(cb) cb(null);
})
});
});
req.end();
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"serialport": "^1.4.0",
"unzip": "^0.1.9",
"wrench": "^1.5.8",
"tar": "^0.1.19"
"tar": "^0.1.19",
"adm-zip": "^0.4.4"
}
}
2 changes: 1 addition & 1 deletion platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var tar = require('tar');
var http = require('http');

//var CLOUDPATH = "/Users/josh/projects/ArduinoZips";
var CLOUDPATH = 'http://joshondesign.com/p/apps/electron/platforms/';
var CLOUDPATH = 'http://joshondesign.com/p/apps/electron/platforms';
var VERSION = "1.0.5";


Expand Down
35 changes: 35 additions & 0 deletions test_download.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
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 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) {
res.pipe(fs.createWriteStream(outfile)).on('close',function(){
console.log('its over');
var zip = new AdmZip(outfile);
var zipEntries = zip.getEntries();
var rootpath = zipEntries[0].entryName;
rootpath = rootpath.substring(0,rootpath.indexOf('/'));
/*
zipEntries.forEach(function(zipEntry) {
console.log(zipEntry.toString()); // outputs zip entries information
});
*/
zip.extractAllTo(outdir,true);
console.log("root path = ",rootpath);
console.log('done extracting from ',outfile);

//rename to be lower case
fs.renameSync(outdir+'/'+rootpath, outdir+'/'+rootpath.toLowerCase());

});
});

0 comments on commit fdcf712

Please sign in to comment.