This code calculates the CRC checksum of a specific Quake 3 game archive file and can be used to verify its integrity by comparing the result to known checksum values. It imports a checksum function, defines a test function, and exports the function for use in other parts of the application.
npm run import -- "test crc file"
var importer = require('../Core')
var checksumZip = importer.import("crc checksum file")
var TEST_PK3 = '/Applications/ioquake3/baseq3/pak8a.pk3'
async function testCrcFile() {
return await checksumZip(TEST_PK3)
}
/*
1566731103,
298122907,
412165236,
2991495316,
1197932710,
4087071573,
3709064859,
908855077,
977125798
*/
module.exports = testCrcFile
const fs = require('fs');
const crc32 = require('crc-32');
const path = require('path');
/**
* Importer for core modules.
*/
const importer = require('../Core');
/**
* Import the crc checksum file module.
*/
const checksumZip = importer.import('crc-checksum-file');
/**
* Test the crc checksum file function.
*
* @returns {Promise<number>} The crc checksum of the file at TEST_PK3.
*/
async function testCrcFile() {
const filePath = '/Applications/ioquake3/baseq3/pak8a.pk3';
const fileBuffer = await fs.promises.readFile(filePath);
const crc = crc32.buf(fileBuffer);
return crc & 0xFFFFFFFF;
}
/**
* Example test data.
*
* @type {number[]}
*/
const testData = [
1566731103,
298122907,
412165236,
2991495316,
1197932710,
4087071573,
3709064859,
908855077,
977125798,
];
/**
* Export the testCrcFile function.
*/
module.exports = testCrcFile;
// TODO: Implement a way to test the crc checksum file function with the test data
// TODO: Consider adding input validation for the file path
This code snippet defines an asynchronous function testCrcFile
that calculates the CRC checksum of a Quake 3 game archive file (pak8a.pk3
).
Here's a breakdown:
Imports:
checksumZip
function from a module named crc checksum file
using the importer
object.Test File:
TEST_PK3
pointing to the path of the Quake 3 archive file to be checked.Checksum Function:
testCrcFile
that calls the imported checksumZip
function with the TEST_PK3
file path.Output:
pak8a.pk3
file.Export:
testCrcFile
function is exported as a module, making it available for use in other parts of the application.Purpose:
This code snippet provides a simple utility for verifying the integrity of a Quake 3 game archive file by comparing its calculated CRC checksum to a known set of values.