fix: correct hash schema and stream hashing
This commit is contained in:
@@ -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")));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user