All files / src/lib/helpers checksum.ts

39.13% Statements 9/23
100% Branches 0/0
0% Functions 0/7
35.29% Lines 6/17

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 252x 2x 2x   2x                   2x         2x          
import { createReadStream, readFile } from "fs-extra";
import crypto from "crypto";
import { md5 } from "hash-wasm";
 
export const checksumFile = (path: string): Promise<string> => {
  return new Promise((resolve, reject) => {
    const hash = crypto.createHash("sha1");
    const stream = createReadStream(path);
    stream.on("error", (err) => reject(err));
    stream.on("data", (chunk) => hash.update(chunk));
    stream.on("end", () => resolve(hash.digest("hex")));
  });
};
 
export const checksumMD5File = async (path: string): Promise<string> => {
  const file = await readFile(path);
  return md5(file);
};
 
export const checksumString = (string: string): string => {
  const hash = crypto.createHash("sha1");
  hash.update(string);
  return hash.digest("hex");
};