Skip to content

Commit

Permalink
Merge 3836713 into 1c2fe87
Browse files Browse the repository at this point in the history
  • Loading branch information
frankborden committed Jun 24, 2021
2 parents 1c2fe87 + 3836713 commit a0b9316
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/SlippiGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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");
}
Expand Down
10 changes: 10 additions & 0 deletions test/game.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a0b9316

Please sign in to comment.