Skip to content

Commit

Permalink
Replace tar.gz
Browse files Browse the repository at this point in the history
  • Loading branch information
vladikoff committed Nov 7, 2017
1 parent e79bf22 commit e4715ed
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
39 changes: 24 additions & 15 deletions index.js
Expand Up @@ -4,7 +4,7 @@ var path = require('path');
var url = require('url');

var got = require('got');
var targz = require('tar.gz');
var tar = require('tar');
var AdmZip = require('adm-zip');

var Promise = require('bluebird');
Expand Down Expand Up @@ -54,19 +54,28 @@ got.stream(url.parse(downloadUrl))
});

function extract(archivePath, targetDirectoryPath) {
if (outFile.indexOf('.tar.gz') >= 0) {
return targz().extract(archivePath, targetDirectoryPath);
}

else if (outFile.indexOf('.zip') >= 0) {
return Promise.resolve()
.then(function () {
new AdmZip(archivePath)
.extractAllTo(targetDirectoryPath);
return new Promise(function(resolve, reject) {
if (outFile.indexOf('.tar.gz') >= 0) {
tar.extract({
file: archivePath,
cwd: targetDirectoryPath
}).then(function (err) {
if (err) {
reject(err);
} else {
resolve();
}
});
}

else {
return Promise.reject('This archive extension is not supported: ' + archivePath);
}
} else if (outFile.indexOf('.zip') >= 0) {
new AdmZip(archivePath).extractAllToAsync(targetDirectoryPath, true, function (err) {
if (err) {
reject(err);
} else {
resolve();
}
});
} else {
reject('This archive extension is not supported: ' + archivePath);
}
});
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -28,7 +28,7 @@
"adm-zip": "0.4.7",
"bluebird": "3.4.6",
"got": "5.6.0",
"tar.gz": "1.0.5"
"tar": "4.0.2"
},
"devDependencies": {
"ava": "0.15.2"
Expand Down

0 comments on commit e4715ed

Please sign in to comment.