Skip to content

Commit

Permalink
Filter out missing files on load
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielv123 committed Apr 27, 2024
1 parent f0fb471 commit 8831b33
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions packages/host/src/patch.ts
Expand Up @@ -77,16 +77,16 @@ export class SaveModule {

static async fromSave(json: Static<typeof SaveModule.jsonSchema>, root: JSZip) {
const module = new this(lib.ModuleInfo.fromJSON(json));
module.files = new Map(
await Promise.all(json.files.map(async filename => {
const file = root.file(filename);
module.files = new Map(await Promise.all(json.files
.map(filename => ({filename, file: root.file(filename)}))
.filter(({filename, file}) => {
if (file === null) {
lib.logger.warn(`Missing file ${filename} in save`);
return [filename, Buffer.alloc(0)] as const;
}
return [filename, await file.async("nodebuffer")] as const;
}))
);
return file !== null;
})
.map(async ({filename, file}) => [filename, await file!.async("nodebuffer")] as const)
));
return module;
}

Expand Down

0 comments on commit 8831b33

Please sign in to comment.