diff --git a/lib/start.js b/lib/start.js index 2889903..39ce33a 100644 --- a/lib/start.js +++ b/lib/start.js @@ -8,7 +8,6 @@ var fs = require('fs'), colors = require('colors'), Q = require('q'), open = require('open'), - unzip = require('unzip2'), xml2js = require('xml2js'), ProgressBar = require('progress'), IonicProject = require('./project'), @@ -293,6 +292,8 @@ Start.fetchCreatorApp = function(options) { } function _fetchCreatorApp() { + var AdmZip = require('adm-zip'); + // var self = this; var appId = options.template.split(':')[1]; //var downloadUrl = IONIC_DASH + path.join('/api/v1/creator', appId, 'download/html'); @@ -314,22 +315,8 @@ Start.fetchCreatorApp = function(options) { try { fs.writeFileSync(tempZipFilePath, body); - - var readStream = fs.createReadStream(tempZipFilePath); - readStream.on('error', function(err) { - log.debug('unzipRepo readStream error: ' + err); - q.reject(err); - }); - - var writeStream = unzip.Extract({ path: wwwPath }); - writeStream.on('close', function() { - q.resolve(); - }); - writeStream.on('error', function(err) { - log.debug('unzipRepo writeStream: ' + err); - q.reject(err); - }); - readStream.pipe(writeStream); + var zip = new AdmZip(fileName); + zip.extractAllTo(targetPath); } catch(e) { log.error(e); q.reject(e); diff --git a/lib/utils.js b/lib/utils.js index f7da845..c4224cf 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -86,7 +86,7 @@ Utils.fetchArchive = function fetchArchive(targetPath, archiveUrl, isGui) { var os = require('os'); var fs = require('fs'); var path = require('path'); - var unzip = require('unzip2'); + var AdmZip = require('adm-zip'); var q = Q.defer(); // The folder name the project will be downloaded and extracted to @@ -96,25 +96,6 @@ Utils.fetchArchive = function fetchArchive(targetPath, archiveUrl, isGui) { var tmpFolder = os.tmpdir(); var tempZipFilePath = path.join(tmpFolder, 'ionic-starter-' + new Date().getTime() + '.zip'); - - var unzipRepo = function unzipRepo(fileName) { - var readStream = fs.createReadStream(fileName); - readStream.on('error', function(err) { - log.debug('unzipRepo readStream error: ' + err); - q.reject(err); - }); - - var writeStream = unzip.Extract({ path: targetPath }); - writeStream.on('close', function() { - q.resolve(); - }); - writeStream.on('error', function(err) { - log.debug('unzipRepo writeStream error: ' + err); - q.reject(err); - }); - readStream.pipe(writeStream); - }; - var proxy = process.env.PROXY || process.env.http_proxy || null; var request = require('request'); request({ url: archiveUrl, rejectUnauthorized: false, encoding: null, proxy: proxy }, function(err, res, body) { @@ -140,7 +121,9 @@ Utils.fetchArchive = function fetchArchive(targetPath, archiveUrl, isGui) { } try { fs.writeFileSync(tempZipFilePath, body); - unzipRepo(tempZipFilePath); + var zip = new AdmZip(tempZipFilePath); + zip.extractAllTo(targetPath); + q.resolve(); } catch(e) { log.debug('fetchArchive request write: ', e); q.reject(e); diff --git a/package.json b/package.json index db24515..68cae52 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ ], "license": "MIT", "dependencies": { + "adm-zip": "0.4.7", "archiver": "0.5.2", "cheerio": "0.19.0", "colors": "0.6.2", @@ -64,7 +65,6 @@ "shelljs": "0.2.6", "tiny-lr-fork": "0.0.5", "underscore": "1.7.0", - "unzip2": "0.2.5", "winston": "1.1.2", "xml2js": "0.4.16" },