Skip to content

Commit 7c37206

Browse files
committed
Remove extraneous files without trying to read them
1 parent faa770c commit 7c37206

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

src/sb3fix.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -631,21 +631,25 @@ const fixZip = async (data, options = {}) => {
631631
}
632632
});
633633

634-
/** @type {Array<[string, import("@turbowarp/jszip").JSZipObject]>} */
635-
const zipFiles = [];
636-
zip.forEach((relativePath, file) => {
637-
zipFiles.push([relativePath, file]);
638-
});
639-
640634
// Remove any unreadable files from the zip. This can notably happen if the compressed data in the zip was
641635
// corrupted, which would make the uncompressed data size field not match. Scratch/JSZip will refuse to
642636
// keep loading the project if that happens. If we remove the asset, at least there's a chance it can now
643637
// be downloaded from the asset server instead.
644-
for (const [relativePath, file] of zipFiles) {
645-
try {
646-
await file.async('uint8array');
647-
} catch (error) {
648-
log(`zip had unreadable file ${relativePath}: ${error}`);
638+
for (const [relativePath, file] of Object.entries(zip.files)) {
639+
if (file.dir) {
640+
continue;
641+
}
642+
643+
if (/(?:project|sprite)\.json/.test(relativePath) || /[0-9a-f]{32}\./.test(relativePath)) {
644+
try {
645+
// If the file is corrupt, this will throw.
646+
await file.async('uint8array');
647+
} catch (error) {
648+
log(`zip had unreadable file ${relativePath}: ${error}`);
649+
zip.remove(relativePath);
650+
}
651+
} else {
652+
log(`zip had extraneous file ${relativePath}`);
649653
zip.remove(relativePath);
650654
}
651655
}
2.49 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
zip had extraneous file README.md
2+
zip had extraneous file package.json
3+
zip had extraneous file a folder in the zip/package-lock.json
4+
zip had extraneous file a folder in the zip/webpack.config.js
5+
checking target 0
6+
checking target 1

tests/samples/extraneous.sb3

20.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)