Parser combinators and utilities for GoldSrc demo files.
@cgdangelo/talent-parser-goldsrc
is published to NPM. Install with your package manager (pnpm, npm, yarn) of choice:
npm install @cgdangelo/talent-parser-goldsrc
import { readFile } from "fs/promises";
import { parseDemo } from "@cgdangelo/talent-parser-goldsrc";
const fileContents = await readFile('./demo.dem');
const demo = parseDemo(fileContents); // Demo | undefined
Demos take quite a while to process, and the final parse result is not exactly tiny. A 20-minute demo can represent several hundred megabytes of JSON data.
To alleviate this, the parser combinator allows for an event bus implementation to be provided so that data can be emitted as the file is evaluated, instead of waiting for the full parsing to complete.
See @cgdangelo/talent-demo-analyzer
application for more.
import { EventEmitter } from "events";
import { readFile } from "fs/promises";
import { parseDemo } from "@cgdangelo/talent-parser-goldsrc";
const demoEvents = new EventEmitter();
demoEvents.on('demo:frame', frame => console.log(frame));
const fileContents = await readFile('./demo.dem');
parseDemo(fileContents, demoEvents);
If you are working on a project within the fp-ts ecosystem, @cgdangelo/talent-parser-goldsrc
exports a demo
combinator constructor built with parser-ts. You should be able to use the combinator in your application the same way this library does.
See @cgdangelo/talent-demo-to-json
application for more.
Similarly, the goldsrcParserIO
and goldsrcParserEither
constructors return instances that you can manipulate with IO.map
, Either.chain
, and so on.