2018-03-20 12:59:29 -04:00
|
|
|
var JSZip = require('jszip');
|
|
|
|
|
|
|
|
/**
|
2018-03-24 11:36:17 -04:00
|
|
|
* Unpacks a zip file.
|
|
|
|
* @param {string} input Zip file provided as a string
|
|
|
|
* @param {array} callback Array including both the project and zip archive
|
|
|
|
* @return {void}
|
2018-03-20 12:59:29 -04:00
|
|
|
*/
|
|
|
|
module.exports = function (input, callback) {
|
|
|
|
return JSZip.loadAsync(input)
|
|
|
|
.then(function (zip) {
|
|
|
|
return zip.file('project.json').async('string')
|
|
|
|
.then(function (project) {
|
|
|
|
return callback(null, [project, zip]);
|
|
|
|
});
|
|
|
|
})
|
2018-03-24 11:36:17 -04:00
|
|
|
.catch(function (err) {
|
2018-03-20 12:59:29 -04:00
|
|
|
var msg = 'Failed to unzip and extract project.json, with error: ';
|
|
|
|
return callback(msg + JSON.stringify(err));
|
|
|
|
});
|
|
|
|
};
|