mirror of
https://github.com/scratchfoundation/scratch-parser.git
synced 2025-08-28 22:18:45 -04:00
test($test): Rename zip to unzip for clarity. Add descriptive error message to
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).
This commit is contained in:
parent
1501c957c7
commit
663d6ee8e6
6 changed files with 138 additions and 22 deletions
22
lib/unzip.js
Normal file
22
lib/unzip.js
Normal file
|
@ -0,0 +1,22 @@
|
|||
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));
|
||||
});
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue