mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-25 02:32:55 +02:00
MISC: Support compression of save data (#1162)
* Use Compression Streams API instead of jszip or other libraries. * Remove usage of base64 in the new binary format. * Do not convert binary data to string and back. The type of save data is SaveData, it's either string (old base64 format) or Uint8Array (new binary format). * Proper support for interacting with electron-related code. Electron-related code assumes that save data is in the base64 format. * Proper support for other tools (DevMenu, pretty-save.js). Full support for DevMenu will be added in a follow-up PR. Check the comments in src\DevMenu\ui\SaveFileDev.tsx for details.
This commit is contained in:
@@ -12,6 +12,7 @@ import { ToastVariant } from "@enums";
|
||||
import { Upload } from "@mui/icons-material";
|
||||
import { Button } from "@mui/material";
|
||||
import { OptionSwitch } from "../../ui/React/OptionSwitch";
|
||||
import { isBinaryFormat } from "../../../electron/saveDataBinaryFormat";
|
||||
|
||||
export function SaveFileDev(): React.ReactElement {
|
||||
const importInput = useRef<HTMLInputElement>(null);
|
||||
@@ -22,8 +23,14 @@ export function SaveFileDev(): React.ReactElement {
|
||||
|
||||
async function onImport(event: React.ChangeEvent<HTMLInputElement>): Promise<void> {
|
||||
try {
|
||||
const base64Save = await saveObject.getImportStringFromFile(event.target.files);
|
||||
const save = atob(base64Save);
|
||||
const saveData = await saveObject.getSaveDataFromFile(event.target.files);
|
||||
// TODO Support binary format. This is low priority because this entire feature (SaveFileDev) is not fully
|
||||
// implemented. "doRestore" does nothing.
|
||||
if (isBinaryFormat(saveData)) {
|
||||
SnackbarEvents.emit("We currently do not support binary format", ToastVariant.ERROR, 5000);
|
||||
return;
|
||||
}
|
||||
const save = decodeURIComponent(escape(atob(saveData as string)));
|
||||
setSaveFile(save);
|
||||
} catch (e: unknown) {
|
||||
SnackbarEvents.emit(String(e), ToastVariant.ERROR, 5000);
|
||||
|
||||
Reference in New Issue
Block a user