mirror of
https://github.com/scratchfoundation/scratch-parser.git
synced 2025-08-28 22:18:45 -04:00
Added unit tests for unzip and added a user-friendly error message for unzip being unable to perform its duties of extracting a project.json from the given input (zip).
22 lines
593 B
JavaScript
22 lines
593 B
JavaScript
var JSZip = require('jszip');
|
|
|
|
/**
|
|
* Unpacks a zip
|
|
*
|
|
* @param {String} Input
|
|
*
|
|
* @return {Object}
|
|
*/
|
|
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]);
|
|
});
|
|
})
|
|
.catch(function(err) {
|
|
var msg = 'Failed to unzip and extract project.json, with error: ';
|
|
return callback(msg + JSON.stringify(err));
|
|
});
|
|
};
|