From f0ee5a081c17acc54769321cb83583504eeaa5ca Mon Sep 17 00:00:00 2001 From: Corwin Date: Mon, 8 Apr 2024 03:23:47 +0100 Subject: [PATCH] make emulator wrapper be able to decompress gzip compressed roms --- website/app/src/mgba.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/website/app/src/mgba.tsx b/website/app/src/mgba.tsx index 7018ee6b..d857439e 100644 --- a/website/app/src/mgba.tsx +++ b/website/app/src/mgba.tsx @@ -41,6 +41,19 @@ export interface MgbaHandle { buttonRelease: (key: GbaKey) => void; } +const downloadGame = async (gameUrl: string): Promise => { + const game = await fetch(gameUrl); + + if (gameUrl.endsWith(".gz")) { + const decompressedStream = (await game.blob()) + .stream() + .pipeThrough(new DecompressionStream("gzip")); + return await new Response(decompressedStream).arrayBuffer(); + } else { + return await game.arrayBuffer(); + } +}; + export const Mgba = forwardRef( ({ gameUrl, volume, controls, paused }, ref) => { const canvas = useRef(null); @@ -52,9 +65,7 @@ export const Mgba = forwardRef( useEffect(() => { if (state !== MgbaState.Initialised) return; (async () => { - const game = await fetch(gameUrl); - const gameData = await game.arrayBuffer(); - + const gameData = await downloadGame(gameUrl); const gameSplit = gameUrl.split("/"); const gameBaseName = gameSplit[gameSplit.length - 1];