From c9d936abaddeaa798558b95b6fda3213a1285004 Mon Sep 17 00:00:00 2001 From: Frank Borden Date: Wed, 23 Jun 2021 22:21:24 +0000 Subject: [PATCH 1/3] Allow SlippiGame to accept an ArrayBuffer --- src/SlippiGame.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/SlippiGame.ts b/src/SlippiGame.ts index 83e8791e..c08a75fd 100644 --- a/src/SlippiGame.ts +++ b/src/SlippiGame.ts @@ -32,7 +32,7 @@ export class SlippiGame { private inputComputer: InputComputer = new InputComputer(); private statsComputer: Stats; - public constructor(input: string | Buffer, opts?: StatOptions) { + public constructor(input: string | Buffer | ArrayBuffer, opts?: StatOptions) { if (_.isString(input)) { this.input = { source: SlpInputSource.FILE, @@ -43,6 +43,11 @@ export class SlippiGame { source: SlpInputSource.BUFFER, buffer: input, }; + } else if (input instanceof ArrayBuffer) { + this.input = { + source: SlpInputSource.BUFFER, + buffer: Buffer.from(input), + }; } else { throw new Error("Cannot create SlippiGame with input of that type"); } From 9166ee6514faec78d826d94e221277a7c24eab9c Mon Sep 17 00:00:00 2001 From: Frank Borden Date: Wed, 23 Jun 2021 22:21:24 +0000 Subject: [PATCH 2/3] Allow SlippiGame to accept an ArrayBuffer --- src/SlippiGame.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/SlippiGame.ts b/src/SlippiGame.ts index 83e8791e..c08a75fd 100644 --- a/src/SlippiGame.ts +++ b/src/SlippiGame.ts @@ -32,7 +32,7 @@ export class SlippiGame { private inputComputer: InputComputer = new InputComputer(); private statsComputer: Stats; - public constructor(input: string | Buffer, opts?: StatOptions) { + public constructor(input: string | Buffer | ArrayBuffer, opts?: StatOptions) { if (_.isString(input)) { this.input = { source: SlpInputSource.FILE, @@ -43,6 +43,11 @@ export class SlippiGame { source: SlpInputSource.BUFFER, buffer: input, }; + } else if (input instanceof ArrayBuffer) { + this.input = { + source: SlpInputSource.BUFFER, + buffer: Buffer.from(input), + }; } else { throw new Error("Cannot create SlippiGame with input of that type"); } From d17f056a960905fb0b58e9629fe305bdca5dc670 Mon Sep 17 00:00:00 2001 From: Frank Borden Date: Thu, 24 Jun 2021 11:07:39 +0000 Subject: [PATCH 3/3] add test for arraybuffer input --- test/game.spec.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/game.spec.ts b/test/game.spec.ts index f962301c..fb9fac4e 100644 --- a/test/game.spec.ts +++ b/test/game.spec.ts @@ -119,6 +119,16 @@ it("should be able to support reading from a buffer input", () => { expect(_.last(settings.players).characterId).toBe(0xe); }); +it("should be able to support reading from an array buffer input", () => { + const buf = fs.readFileSync("slp/sheik_vs_ics_yoshis.slp"); + const arrayBuf = buf.buffer; + const game = new SlippiGame(arrayBuf); + const settings = game.getSettings(); + expect(settings.stageId).toBe(8); + expect(_.first(settings.players).characterId).toBe(0x13); + expect(_.last(settings.players).characterId).toBe(0xe); +}); + it("should support realtime parsing", () => { const fullData = fs.readFileSync("slp/realtimeTest.slp"); const buf = Buffer.alloc(100e6); // Allocate 100 MB of space