mirror of
https://github.com/morluto/rea.git
synced 2026-11-30 10:27:42 +00:00
* refactor(verifiers): share whole-file SHA-256 hashing * fix(verifiers): type the streamed digest input
13 lines
396 B
JavaScript
13 lines
396 B
JavaScript
import { createHash } from "node:crypto";
|
|
import { createReadStream } from "node:fs";
|
|
|
|
/**
|
|
* Stream a verifier input into a lowercase hexadecimal SHA-256 digest.
|
|
* @param {import("node:fs").PathLike} path
|
|
*/
|
|
export const sha256File = async (path) => {
|
|
const hash = createHash("sha256");
|
|
for await (const bytes of createReadStream(path)) hash.update(bytes);
|
|
return hash.digest("hex");
|
|
};
|