Add SHA hashes for packages (#1351)

This commit is contained in:
be5invis 2022-05-13 00:17:38 -07:00
parent c901d79f70
commit 8ef19e1b65
2 changed files with 45 additions and 16 deletions

View file

@ -0,0 +1,31 @@
const fs = require("fs");
const crypto = require("crypto");
module.exports = async function (out, archiveFiles) {
let s = "";
for (const file of archiveFiles) {
s += `${file.base}\t${await hashFile(file.full)}\n`;
}
await fs.promises.writeFile(out, s);
};
function hashFile(path) {
return new Promise((resolve, reject) => {
let sum = crypto.createHash("sha256");
let fileStream = fs.createReadStream(path);
fileStream.on("error", err => {
return reject(err);
});
fileStream.on("data", chunk => {
try {
sum.update(chunk);
} catch (ex) {
return reject(ex);
}
});
fileStream.on("end", () => {
return resolve(sum.digest("hex"));
});
});
}