1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 'use strict';
-
- Object.defineProperty(exports, "__esModule", {
- value: true
- });
- exports.default = getFilemd5sum;
-
- var _sparkMd = require('spark-md5');
-
- var _sparkMd2 = _interopRequireDefault(_sparkMd);
-
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
-
- function getFilemd5sum(ofile) {
- return new Promise(function (resolve, reject) {
- var file = ofile;
- var tmp_md5 = void 0;
- var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice,
-
- // file = this.files[0],
- chunkSize = 8097152,
- // Read in chunks of 2MB
- chunks = Math.ceil(file.size / chunkSize),
- currentChunk = 0,
- spark = new _sparkMd2.default.ArrayBuffer(),
- fileReader = new FileReader();
-
- function loadNext() {
- var start = currentChunk * chunkSize,
- end = start + chunkSize >= file.size ? file.size : start + chunkSize;
- fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
- }
-
- fileReader.onload = function (e) {
- spark.append(e.target.result); // Append array buffer
- currentChunk++;
-
- if (currentChunk < chunks) {
- loadNext();
- } else {
- tmp_md5 = spark.end();
- resolve(tmp_md5);
- }
- };
-
- fileReader.onerror = function () {
- reject('error');
- };
-
- loadNext();
- });
- }
|