17 lines
496 B
TypeScript
17 lines
496 B
TypeScript
import { crypto, toHashString } from 'https://deno.land/std@0.176.0/crypto/mod.ts';
|
|
|
|
const getFileBuffer = (filePath: string) => {
|
|
const file = Deno.openSync(filePath);
|
|
const buf = new Uint8Array(file.statSync().size);
|
|
file.readSync(buf);
|
|
file.close();
|
|
return buf;
|
|
};
|
|
|
|
const getBuffer = (data: BufferSource) => toHashString(crypto.subtle.digestSync('SHA-256', data));
|
|
|
|
const getFileHash = (filePath: string) => getBuffer(getFileBuffer(filePath));
|
|
|
|
|
|
export default getFileHash
|