import CryptoJS from "crypto-js";

export const fileToMD5 = (file) => {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.onload = (e) => {
      const binary = e.target.result;
      // const hash = MD5(binary).toString();
      var hash = CryptoJS.MD5(CryptoJS.lib.WordArray.create(binary)).toString();

      resolve(hash);
    };
    reader.onerror = (error) => {
      reject(error);
    };
    reader.readAsArrayBuffer(file);
  });
};
