spark-md5import SparkMD5 from 'spark-md5';
var hexHash = SparkMD5.hash('Hi there'); // hex hash
var rawHash = SparkMD5.hash('Hi there', true); // OR raw hash (binary string)
这是最简单的生成hash的方法,但是如果是大文件断点续传的话,这种方式获取hash码就不行了。因为你上传的文件可能2G,4G,5G甚至更大,你的内存根本盛不下,这时候就需要换一种计算hash的方法了。function calcMD5(file,callback){
this.upstate="MD5计算中...";
this.percent=0;
let chunkSize=2097152,
chunks=Math.ceil(file.size/chunkSize),
currentChunk=0,
spark=new SparkMD5.ArrayBuffer(),
fileReader=new FileReader();
fileReader.οnlοad=(e)=>{
//对于读取的文件计算hash码。
spark.append(e.target.result);
currentChunk++;
this.percent=((currentChunk/chunks)*100).toFixed(2)-0;
if(currentChunk
load