VM receives input buffer representing project to load and unpacks it as zip. This functionality will eventually move to storage.

This commit is contained in:
kchadha 2018-03-08 10:25:58 -05:00
parent d6e248aab8
commit d59a4ffd55

View file

@ -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));
});
});
}