Skip to content

Commit

Permalink
checksum calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
zsoltoroszlany82 committed Nov 30, 2024
1 parent 9c19507 commit 4ef44c0
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions compress.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
const fs = require("fs");
const crypto = require("crypto");
const archiver = require("archiver");
const path = require("path");

const output = fs.createWriteStream(__dirname + "/dist/ps_live_search.ocmod.zip");
const outputPath = path.join(__dirname, "/dist/ps_live_search.ocmod.zip");

const output = fs.createWriteStream(outputPath);

const archive = archiver("zip", {
zlib: { level: 4 },
});

output.on("close", function () {
console.log(archive.pointer() + " total bytes");
console.log(`${archive.pointer()} total bytes`);
console.log("ps_live_search.ocmod.zip has been created");

// Calculate and log MD5 and SHA256 checksums
calculateChecksums(outputPath);
});

archive.on("warning", function (err) {
Expand All @@ -33,3 +39,17 @@ archive.file("src/install.json", { name: "install.json" });
archive.file("src/installation.txt", { name: "installation.txt" });

archive.finalize();

/**
* Calculate MD5 and SHA256 checksums for a file.
* @param {string} filePath - The path to the file.
*/
function calculateChecksums(filePath) {
const fileBuffer = fs.readFileSync(filePath);

const md5Hash = crypto.createHash("md5").update(fileBuffer).digest("hex");
console.log(`MD5 Checksum: ${md5Hash}`);

const sha256Hash = crypto.createHash("sha256").update(fileBuffer).digest("hex");
console.log(`SHA256 Checksum: ${sha256Hash}`);
}

0 comments on commit 4ef44c0

Please sign in to comment.