add crc32 checksum generation of original file

clean up log statements
This commit is contained in:
2026-05-13 15:45:49 +02:00
parent 3e65395116
commit 29d7ea2a7a
+27 -2
View File
@@ -347,6 +347,15 @@ function formatFileSize(bytes) {
// FILE OPERATIONS // FILE OPERATIONS
// ============================================================================ // ============================================================================
async function calculateFileCrc32(filePath) {
try {
const buffer = await fs.readFile(filePath);
return (crc32.buf(buffer) >>> 0).toString(16).toUpperCase().padStart(8, '0');
} catch (error) {
throw new Error(`Failed to calculate CRC32: ${error.message}`);
}
}
/** /**
* Read and parse the input JSON file * Read and parse the input JSON file
*/ */
@@ -376,10 +385,10 @@ async function createOutputDirectory(outputPath, allowOverwrite = false, cleanEx
// Optionally remove existing directory // Optionally remove existing directory
if (cleanExisting) { if (cleanExisting) {
console.log(`Removing existing directory contents: ${outputPath}`); console.log(` Removing existing directory contents: ${outputPath}`);
await fs.rm(`${outputPath}`, { recursive: true, force: true }); await fs.rm(`${outputPath}`, { recursive: true, force: true });
} else if (allowOverwrite) { } else if (allowOverwrite) {
console.log(`Overwriting existing directory: ${outputPath}`); console.log(` Overwriting existing directory: ${outputPath}`);
} }
try { try {
@@ -437,6 +446,16 @@ async function saveBackup(outputPath, data) {
return backupPath; return backupPath;
} }
/**
* Create CRC32 checksum file for integrity verification
*/
async function createCrc32Checksum(outputPath, inputPath) {
const fileCrc32 = await calculateFileCrc32(inputPath);
const checksumPath = path.join(outputPath, `crc32.txt`);
await fs.writeFile(checksumPath, `${fileCrc32}\n`, 'utf-8');
return { checksumPath, fileCrc32 };
}
// ============================================================================ // ============================================================================
// PROPERTY PROCESSING // PROPERTY PROCESSING
// ============================================================================ // ============================================================================
@@ -669,6 +688,12 @@ async function main() {
console.log(`\n📂 Creating output: ${outputPath}`); console.log(`\n📂 Creating output: ${outputPath}`);
await createOutputDirectory(outputPath, allowOverwrite, cleanExisting); await createOutputDirectory(outputPath, allowOverwrite, cleanExisting);
// Create CRC32 checksum file for integrity verification
console.log(`\n🐾 Creating checksum file...`);
const crc32 = await createCrc32Checksum(outputPath, inputPath);
console.log(`\n Checksum file: ${crc32.checksumPath}`);
//console.log(` CRC32: ${crc32.fileCrc32}`);
// Process each root property // Process each root property
console.log('\n⚙️ Processing properties:\n'); console.log('\n⚙️ Processing properties:\n');
const processedProperties = []; const processedProperties = [];