add crc32 checksum generation of original file
clean up log statements
This commit is contained in:
@@ -347,6 +347,15 @@ function formatFileSize(bytes) {
|
||||
// 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
|
||||
*/
|
||||
@@ -376,10 +385,10 @@ async function createOutputDirectory(outputPath, allowOverwrite = false, cleanEx
|
||||
|
||||
// Optionally remove existing directory
|
||||
if (cleanExisting) {
|
||||
console.log(`Removing existing directory contents: ${outputPath}`);
|
||||
console.log(` Removing existing directory contents: ${outputPath}`);
|
||||
await fs.rm(`${outputPath}`, { recursive: true, force: true });
|
||||
} else if (allowOverwrite) {
|
||||
console.log(`Overwriting existing directory: ${outputPath}`);
|
||||
console.log(` Overwriting existing directory: ${outputPath}`);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -437,6 +446,16 @@ async function saveBackup(outputPath, data) {
|
||||
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
|
||||
// ============================================================================
|
||||
@@ -669,8 +688,14 @@ async function main() {
|
||||
console.log(`\n📂 Creating output: ${outputPath}`);
|
||||
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
|
||||
console.log('\n⚙️ Processing properties:\n');
|
||||
console.log('\n⚙️ Processing properties:\n');
|
||||
const processedProperties = [];
|
||||
const rootProps = Object.keys(data);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user