diff --git a/src/virtual-machine.js b/src/virtual-machine.js index 07aa159b4..da9849616 100644 --- a/src/virtual-machine.js +++ b/src/virtual-machine.js @@ -189,21 +189,22 @@ class VirtualMachine extends EventEmitter { /** * Load a project from a Scratch 3.0 sb3 file containing a project json * and all of the sound and costume files. - * @param {JSZip} sb3File The sb3 file representing the project to load. + * @param {Buffer} inputBuffer A buffer representing the project to load. * @return {!Promise} Promise that resolves after targets are installed. */ - loadProjectLocal (sb3File) { + loadProjectLocal (inputBuffer) { // TODO need to handle sb2 files as well, and will possibly merge w/ // above function - return sb3File.file('project.json').async('string') - .then(json => { - // TODO look at promise documentation to do this on success, - // but something else on error - - json = JSON.parse(json); // TODO catch errors here (validation) - return sb3.deserialize(json, this.runtime, sb3File) - .then(({targets, extensions}) => - this.installTargets(targets, extensions, true)); + return JSZip.loadAsync(inputBuffer) + .then(sb3File => { + sb3File.file('project.json').async('string') + .then(json => { + // TODO error handling for unpacking zip/not finding project.json + json = JSON.parse(json); // TODO catch errors here (validation) + return sb3.deserialize(json, this.runtime, sb3File) + .then(({targets, extensions}) => + this.installTargets(targets, extensions, true)); + }); }); }