-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathchecksum.ts
More file actions
46 lines (34 loc) · 1.11 KB
/
checksum.ts
File metadata and controls
46 lines (34 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import * as crypto from "crypto";
import JSZip from "jszip";
import { createReadStream, readdirSync, readFileSync, writeFileSync } from "fs";
export const getChecksum = (path: string): Promise<string> => {
return new Promise((resolve, reject) => {
const hash = crypto.createHash("sha256");
const input = createReadStream(path);
input.on("error", reject);
input.on("data", (chunk: string | Buffer<ArrayBufferLike>) => {
hash.update(chunk);
});
input.on("close", () => {
resolve(hash.digest("hex"));
});
});
};
const main = async () => {
let files = readdirSync(`./out/`);
let result = "";
for (const file of files) {
const zip = new JSZip();
zip.file(file, readFileSync(`./out/${file}`));
const content = await zip.generateAsync({ type: "nodebuffer" });
writeFileSync(`./out/${file}.zip`, content);
}
files = readdirSync(`./out/`);
for (const file of files) {
const checksum = await getChecksum(`./out/${file}`);
console.log(`${checksum} ${file}`);
result += `${checksum} ${file}\n`;
}
writeFileSync(`./out/checksum.txt`, result);
};
main();