zoukankan      html  css  js  c++  java
  • spark-MD5文件MD5加密

    npm地址:https://www.npmjs.com/package/spark-md5
      //生成MD5
      md5Count() {
        let blobSlice = File.prototype.slice,
          file = this.importFormData.File,  // file
          chunkSize = 2097152,                             // Read in chunks of 2MB
          chunks = Math.ceil(file.size / chunkSize),
          currentChunk = 0,
          spark = new SparkMD5(),
          fileReader = new FileReader();
    
        fileReader.onload = (e) => {
          spark.appendBinary(e.target.result);                   // Append a binary string
          currentChunk++;
    
          if (currentChunk < chunks) {
            loadNext();
          } else {
            this.importFormData.SignFileMd5 = spark.end();
            console.log(this.importFormData.SignFileMd5);
          }
        };
    
        fileReader.onerror = function () {
          console.warn('oops, something went wrong.');
        };
    
        function loadNext() {
          let start = currentChunk * chunkSize,
            end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
    
          fileReader.readAsBinaryString(blobSlice.call(file, start, end));
        }
    
        loadNext();
      }

    调用,在input  change时,调用此函数

      uploadUser() {
        // @ts-ignore
        const files = document.getElementById('uploadUserFile').files;
        this.importFormData.File = files[0];
        this.md5Count();
      }

  • 相关阅读:
    数据库操作
    jquery 第一章
    算法很美 第一章
    python 学习第四天
    python学习第三天
    python学习第二天
    学习python的第一天
    C#-线程
    C#-流、存储
    C#-集合
  • 原文地址:https://www.cnblogs.com/huangmin1992/p/14976882.html
Copyright © 2011-2022 走看看