filehost/getFileHash.ts

17 lines
496 B
TypeScript
Raw Permalink Normal View History

2023-08-12 06:15:32 +03:00
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