"use strict";

var _sparkMd = _interopRequireDefault(require("spark-md5"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/* eslint-disable no-restricted-globals */

self.addEventListener('message', function (e) {
  var chunksArr = e.data.chunksArr; // 收到主线程传递来的文件分片
  console.log('监听\'message\'收到主线程传递来的文件分片', chunksArr);
  var spark = new _sparkMd.default.ArrayBuffer();
  var fileReader = new FileReader();
  fileReader.readAsArrayBuffer(chunksArr.pop());
  console.log('创建文件读取', fileReader);
  fileReader.onload = function (e) {
    spark.append(e.target.result);
    if (chunksArr.length === 0) {
      self.postMessage({
        hash: spark.end()
      });
    } else {
      fileReader.readAsArrayBuffer(chunksArr.pop());
    }
  };
}, false);