fix: correct hash schema and stream hashing

This commit is contained in:
William Valentin
2026-02-04 19:39:17 -08:00
parent a133afad06
commit 1952fbaf30
2 changed files with 8 additions and 10 deletions

View File

@@ -1,11 +1,12 @@
import { createHash } from "node:crypto";
import { promises as fs } from "fs";
import { createReadStream } from "node:fs";
export async function computeFileSha256(filePath: string): Promise<string> {
const hash = createHash("sha256");
const content = await fs.readFile(filePath);
hash.update(content);
return hash.digest("hex");
const stream = createReadStream(filePath);
return await new Promise((resolve, reject) => {
stream.on("data", (chunk) => hash.update(chunk));
stream.on("error", reject);
stream.on("end", () => resolve(hash.digest("hex")));
});
}