1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2025-06-13 13:04:03 +00:00

Removed unnecessary compression step

The logic for returning default data is now in
the `catch` part of the `readFileAsync` promise, so that
new games don't trigger unnecessary compression and then
decompression of the default data.
This commit is contained in:
Cyber Gsus 2021-06-10 11:12:31 +02:00
parent 1046e7d4bd
commit a04dff4d10

View File

@ -165,19 +165,6 @@ export class ReadWriteProxy {
return (
this.app.storage
.readFileAsync(this.filename)
// Check for errors during read
.catch(err => {
if (err === FILE_NOT_FOUND) {
logger.log("File not found, using default data");
// File not found or unreadable, assume default file
return Promise.resolve(null);
}
return Promise.reject("file-error: " + err);
})
// Decrypt data (if its encrypted)
// @ts-ignore
.then(rawData => {
@ -211,19 +198,10 @@ export class ReadWriteProxy {
"bad-content / checksum-mismatch: " + desiredChecksum + " vs " + checksum
);
}
return jsonString;
} else {
if (!G_IS_DEV) {
return Promise.reject("bad-content / missing-compression");
}
}
return rawData;
})
// Parse JSON, this could throw but that's fine
.then(res => {
// Parse JSON
try {
return JSON.parse(res);
return JSON.parse(jsonString);
} catch (ex) {
logger.error(
"Failed to parse file content of",
@ -231,15 +209,34 @@ export class ReadWriteProxy {
":",
ex,
"(content was:",
res,
jsonString,
")"
);
throw new Error("invalid-serialized-data");
}
}
if (!G_IS_DEV) {
return Promise.reject("bad-content / missing-compression");
}
return rawData;
})
// Check for errors during read
.catch(err => {
if (err === FILE_NOT_FOUND) {
logger.log("File not found, using default data");
// File not found or unreadable, assume default file
return Promise.resolve(this.getDefaultData());
}
return Promise.reject("file-error: " + err);
})
// Decompress
.then(compressed => decompressObject(compressed))
.then(decompressObject)
// Verify basic structure
.then(contents => {