import jsmd5 from "js-md5";

/**
 *
 * @param {string} content 字符串
 */
export const MD5 = (content: string): string => {
  return jsmd5(content);
};

/**
 * 获取文件MD5
 * @param file File
 */
export const fileMD5 = (file: File): Promise<string> => {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.onloadend = function () {
      const arrayBuffer = reader.result;
      resolve(jsmd5(arrayBuffer!));
    };
    reader.onerror = function (err) {
      reject(err);
    };
    reader.readAsArrayBuffer(file);
  });
};
