const md5 = require("js-md5");

/**
 *
 * @param {any} str 字符串
 */
export const MD5 = content => {
  return md5(content);
};

export const fileMD5 = file => {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.onloadend = function() {
      const arrayBuffer = reader.result;
      resolve(md5(arrayBuffer));
    };
    reader.onerror = function(err) {
      reject(err);
    };
    reader.readAsArrayBuffer(file);
  });
};
