import { expose } from "comlink";
import { blobToBase64 } from "@/utils/file";
import { sha256 } from "js-sha256";

export function workerBlobToBase64() {}

export function getFileHash(file: File) {
  return new Promise<string>((r) => {
    const fileReader = new FileReader();
    let fileHash = sha256.create();
    fileReader.onload = function (event: Event) {
      const result = (event!.target! as any).result;
      fileHash.update(result);
      fileHash.update(file.name);
      r(fileHash.hex());
    };
    fileReader.readAsArrayBuffer(file);
  });
}

expose(getFileHash);
