saul / demofile

Node.js library for parsing Counter-Strike: Global Offensive demo files

Home Page:https://demofile.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong parse streams with transformation

negezor opened this issue · comments

commented

Research

  • I searched but did not find an existing issue or discussion about this bug.

Description

I found that when I try to give a stream with a transformation, the parsing finishes halfway through. At the same time, if you first transform to Buffer and then pass to parsing, everything works as intended.

Code to reproduce

const fs = require('fs');
const zlib = require('zlib');
const demofile = require('demofile');

const demoFile = new demofile.DemoFile();

demoFile.gameEvents.on('player_death', e => {
	const victim = demoFile.entities.getByUserId(e.userid);
	const victimName = victim ? victim.name : 'unnamed';

	const attacker = demoFile.entities.getByUserId(e.attacker);
	const attackerName = attacker ? attacker.name : 'unnamed';

	const headshotText = e.headshot ? ' HS' : '';

	console.log(`${attackerName} [${e.weapon}${headshotText}] ${victimName}`);
});

const stream = fs.createReadStream('./test.dem.gz')
	.pipe(zlib.createGunzip());

demoFile.parseStream(stream);

/* With buffer */

// const streamToBuffer = async (stream) => {
// 	const chunks = [];
// 	let totalSize = 0;
// 	for await (const chunk of stream) {
// 		totalSize += chunk.length;
// 		chunks.push(chunk);
// 	}
// 	return Buffer.concat(chunks, totalSize);
// };

// streamToBuffer(stream)
// 	.then((buffer) => {
// 		demoFile.parse(buffer);
// 	});

Affected demos

https://www.mediafire.com/file/oy12h1rh6bzm8n3/test.dem.gz/file

Thanks for the report - raised #363 with a fix.