make emulator wrapper be able to decompress gzip compressed roms

This commit is contained in:
Corwin 2024-04-08 03:23:47 +01:00
parent 582cce78c8
commit f0ee5a081c
No known key found for this signature in database

View file

@ -41,6 +41,19 @@ export interface MgbaHandle {
buttonRelease: (key: GbaKey) => void;
}
const downloadGame = async (gameUrl: string): Promise<ArrayBuffer> => {
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<MgbaHandle, MgbaProps>(
({ gameUrl, volume, controls, paused }, ref) => {
const canvas = useRef(null);
@ -52,9 +65,7 @@ export const Mgba = forwardRef<MgbaHandle, MgbaProps>(
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];