md5-util
Version:
拓展spark-md5,支持计算网络文件md5的小插件
1 lines • 10.1 kB
JavaScript
/*! md5-util v1.0.1 拓展spark-md5,支持计算网络文件md5的小插件 License: MIT https://github.com/weijhfly/js-utils By weijhfly */ ;!function f(i,u,s){function a(r,t){if(!u[r]){if(!i[r]){var e="function"==typeof require&&require;if(!t&&e)return e(r,!0);if(h)return h(r,!0);var n=new Error("Cannot find module '"+r+"'");throw n.code="MODULE_NOT_FOUND",n}var o=u[r]={exports:{}};i[r][0].call(o.exports,function(t){return a(i[r][1][t]||t)},o,o.exports,f,i,u,s)}return u[r].exports}for(var h="function"==typeof require&&require,t=0;t<s.length;t++)a(s[t]);return a}({1:[function(t,e,n){!function(t){if("object"==typeof n)e.exports=t();else if("function"==typeof define&&define.amd)define(t);else{var r;try{r=window}catch(t){r=self}r.SparkMD5=t()}}(function(h){"use strict";var n=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function a(t,r){var e=t[0],n=t[1],o=t[2],f=t[3];n=((n+=((o=((o+=((f=((f+=((e=((e+=(n&o|~n&f)+r[0]-680876936|0)<<7|e>>>25)+n|0)&n|~e&o)+r[1]-389564586|0)<<12|f>>>20)+e|0)&e|~f&n)+r[2]+606105819|0)<<17|o>>>15)+f|0)&f|~o&e)+r[3]-1044525330|0)<<22|n>>>10)+o|0,n=((n+=((o=((o+=((f=((f+=((e=((e+=(n&o|~n&f)+r[4]-176418897|0)<<7|e>>>25)+n|0)&n|~e&o)+r[5]+1200080426|0)<<12|f>>>20)+e|0)&e|~f&n)+r[6]-1473231341|0)<<17|o>>>15)+f|0)&f|~o&e)+r[7]-45705983|0)<<22|n>>>10)+o|0,n=((n+=((o=((o+=((f=((f+=((e=((e+=(n&o|~n&f)+r[8]+1770035416|0)<<7|e>>>25)+n|0)&n|~e&o)+r[9]-1958414417|0)<<12|f>>>20)+e|0)&e|~f&n)+r[10]-42063|0)<<17|o>>>15)+f|0)&f|~o&e)+r[11]-1990404162|0)<<22|n>>>10)+o|0,n=((n+=((o=((o+=((f=((f+=((e=((e+=(n&o|~n&f)+r[12]+1804603682|0)<<7|e>>>25)+n|0)&n|~e&o)+r[13]-40341101|0)<<12|f>>>20)+e|0)&e|~f&n)+r[14]-1502002290|0)<<17|o>>>15)+f|0)&f|~o&e)+r[15]+1236535329|0)<<22|n>>>10)+o|0,n=((n+=((o=((o+=((f=((f+=((e=((e+=(n&f|o&~f)+r[1]-165796510|0)<<5|e>>>27)+n|0)&o|n&~o)+r[6]-1069501632|0)<<9|f>>>23)+e|0)&n|e&~n)+r[11]+643717713|0)<<14|o>>>18)+f|0)&e|f&~e)+r[0]-373897302|0)<<20|n>>>12)+o|0,n=((n+=((o=((o+=((f=((f+=((e=((e+=(n&f|o&~f)+r[5]-701558691|0)<<5|e>>>27)+n|0)&o|n&~o)+r[10]+38016083|0)<<9|f>>>23)+e|0)&n|e&~n)+r[15]-660478335|0)<<14|o>>>18)+f|0)&e|f&~e)+r[4]-405537848|0)<<20|n>>>12)+o|0,n=((n+=((o=((o+=((f=((f+=((e=((e+=(n&f|o&~f)+r[9]+568446438|0)<<5|e>>>27)+n|0)&o|n&~o)+r[14]-1019803690|0)<<9|f>>>23)+e|0)&n|e&~n)+r[3]-187363961|0)<<14|o>>>18)+f|0)&e|f&~e)+r[8]+1163531501|0)<<20|n>>>12)+o|0,n=((n+=((o=((o+=((f=((f+=((e=((e+=(n&f|o&~f)+r[13]-1444681467|0)<<5|e>>>27)+n|0)&o|n&~o)+r[2]-51403784|0)<<9|f>>>23)+e|0)&n|e&~n)+r[7]+1735328473|0)<<14|o>>>18)+f|0)&e|f&~e)+r[12]-1926607734|0)<<20|n>>>12)+o|0,n=((n+=((o=((o+=((f=((f+=((e=((e+=(n^o^f)+r[5]-378558|0)<<4|e>>>28)+n|0)^n^o)+r[8]-2022574463|0)<<11|f>>>21)+e|0)^e^n)+r[11]+1839030562|0)<<16|o>>>16)+f|0)^f^e)+r[14]-35309556|0)<<23|n>>>9)+o|0,n=((n+=((o=((o+=((f=((f+=((e=((e+=(n^o^f)+r[1]-1530992060|0)<<4|e>>>28)+n|0)^n^o)+r[4]+1272893353|0)<<11|f>>>21)+e|0)^e^n)+r[7]-155497632|0)<<16|o>>>16)+f|0)^f^e)+r[10]-1094730640|0)<<23|n>>>9)+o|0,n=((n+=((o=((o+=((f=((f+=((e=((e+=(n^o^f)+r[13]+681279174|0)<<4|e>>>28)+n|0)^n^o)+r[0]-358537222|0)<<11|f>>>21)+e|0)^e^n)+r[3]-722521979|0)<<16|o>>>16)+f|0)^f^e)+r[6]+76029189|0)<<23|n>>>9)+o|0,n=((n+=((o=((o+=((f=((f+=((e=((e+=(n^o^f)+r[9]-640364487|0)<<4|e>>>28)+n|0)^n^o)+r[12]-421815835|0)<<11|f>>>21)+e|0)^e^n)+r[15]+530742520|0)<<16|o>>>16)+f|0)^f^e)+r[2]-995338651|0)<<23|n>>>9)+o|0,n=((n+=((f=((f+=(n^((e=((e+=(o^(n|~f))+r[0]-198630844|0)<<6|e>>>26)+n|0)|~o))+r[7]+1126891415|0)<<10|f>>>22)+e|0)^((o=((o+=(e^(f|~n))+r[14]-1416354905|0)<<15|o>>>17)+f|0)|~e))+r[5]-57434055|0)<<21|n>>>11)+o|0,n=((n+=((f=((f+=(n^((e=((e+=(o^(n|~f))+r[12]+1700485571|0)<<6|e>>>26)+n|0)|~o))+r[3]-1894986606|0)<<10|f>>>22)+e|0)^((o=((o+=(e^(f|~n))+r[10]-1051523|0)<<15|o>>>17)+f|0)|~e))+r[1]-2054922799|0)<<21|n>>>11)+o|0,n=((n+=((f=((f+=(n^((e=((e+=(o^(n|~f))+r[8]+1873313359|0)<<6|e>>>26)+n|0)|~o))+r[15]-30611744|0)<<10|f>>>22)+e|0)^((o=((o+=(e^(f|~n))+r[6]-1560198380|0)<<15|o>>>17)+f|0)|~e))+r[13]+1309151649|0)<<21|n>>>11)+o|0,n=((n+=((f=((f+=(n^((e=((e+=(o^(n|~f))+r[4]-145523070|0)<<6|e>>>26)+n|0)|~o))+r[11]-1120210379|0)<<10|f>>>22)+e|0)^((o=((o+=(e^(f|~n))+r[2]+718787259|0)<<15|o>>>17)+f|0)|~e))+r[9]-343485551|0)<<21|n>>>11)+o|0,t[0]=e+t[0]|0,t[1]=n+t[1]|0,t[2]=o+t[2]|0,t[3]=f+t[3]|0}function p(t){var r,e=[];for(r=0;r<64;r+=4)e[r>>2]=t.charCodeAt(r)+(t.charCodeAt(r+1)<<8)+(t.charCodeAt(r+2)<<16)+(t.charCodeAt(r+3)<<24);return e}function c(t){var r,e=[];for(r=0;r<64;r+=4)e[r>>2]=t[r]+(t[r+1]<<8)+(t[r+2]<<16)+(t[r+3]<<24);return e}function o(t){var r,e,n,o,f,i,u=t.length,s=[1732584193,-271733879,-1732584194,271733878];for(r=64;r<=u;r+=64)a(s,p(t.substring(r-64,r)));for(e=(t=t.substring(r-64)).length,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=0;r<e;r+=1)n[r>>2]|=t.charCodeAt(r)<<(r%4<<3);if(n[r>>2]|=128<<(r%4<<3),55<r)for(a(s,n),r=0;r<16;r+=1)n[r]=0;return o=(o=8*u).toString(16).match(/(.*?)(.{0,8})$/),f=parseInt(o[2],16),i=parseInt(o[1],16)||0,n[14]=f,n[15]=i,a(s,n),s}function e(t){var r,e="";for(r=0;r<4;r+=1)e+=n[t>>8*r+4&15]+n[t>>8*r&15];return e}function i(t){var r;for(r=0;r<t.length;r+=1)t[r]=e(t[r]);return t.join("")}function f(t){return/[\u0080-\uFFFF]/.test(t)&&(t=unescape(encodeURIComponent(t))),t}function u(t){var r,e=[],n=t.length;for(r=0;r<n-1;r+=2)e.push(parseInt(t.substr(r,2),16));return String.fromCharCode.apply(String,e)}function s(){this.reset()}return"5d41402abc4b2a76b9719d911017c592"!==i(o("hello"))&&function(t,r){var e=(65535&t)+(65535&r);return(t>>16)+(r>>16)+(e>>16)<<16|65535&e},"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function a(t,r){return(t=0|t||0)<0?Math.max(t+r,0):Math.min(t,r)}ArrayBuffer.prototype.slice=function(t,r){var e,n,o,f,i=this.byteLength,u=a(t,i),s=i;return r!==h&&(s=a(r,i)),s<u?new ArrayBuffer(0):(e=s-u,n=new ArrayBuffer(e),o=new Uint8Array(n),f=new Uint8Array(this,u,e),o.set(f),n)}}(),s.prototype.append=function(t){return this.appendBinary(f(t)),this},s.prototype.appendBinary=function(t){this._buff+=t,this._length+=t.length;var r,e=this._buff.length;for(r=64;r<=e;r+=64)a(this._hash,p(this._buff.substring(r-64,r)));return this._buff=this._buff.substring(r-64),this},s.prototype.end=function(t){var r,e,n=this._buff,o=n.length,f=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(r=0;r<o;r+=1)f[r>>2]|=n.charCodeAt(r)<<(r%4<<3);return this._finish(f,o),e=i(this._hash),t&&(e=u(e)),this.reset(),e},s.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},s.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash}},s.prototype.setState=function(t){return this._buff=t.buff,this._length=t.length,this._hash=t.hash,this},s.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},s.prototype._finish=function(t,r){var e,n,o,f=r;if(t[f>>2]|=128<<(f%4<<3),55<f)for(a(this._hash,t),f=0;f<16;f+=1)t[f]=0;e=(e=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),n=parseInt(e[2],16),o=parseInt(e[1],16)||0,t[14]=n,t[15]=o,a(this._hash,t)},s.hash=function(t,r){return s.hashBinary(f(t),r)},s.hashBinary=function(t,r){var e=i(o(t));return r?u(e):e},(s.ArrayBuffer=function(){this.reset()}).prototype.append=function(t){var r,e=function(t,r,e){var n=new Uint8Array(t.byteLength+r.byteLength);return n.set(new Uint8Array(t)),n.set(new Uint8Array(r),t.byteLength),e?n:n.buffer}(this._buff.buffer,t,!0),n=e.length;for(this._length+=t.byteLength,r=64;r<=n;r+=64)a(this._hash,c(e.subarray(r-64,r)));return this._buff=r-64<n?new Uint8Array(e.buffer.slice(r-64)):new Uint8Array(0),this},s.ArrayBuffer.prototype.end=function(t){var r,e,n=this._buff,o=n.length,f=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(r=0;r<o;r+=1)f[r>>2]|=n[r]<<(r%4<<3);return this._finish(f,o),e=i(this._hash),t&&(e=u(e)),this.reset(),e},s.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},s.ArrayBuffer.prototype.getState=function(){var t=s.prototype.getState.call(this);return t.buff=function(t){return String.fromCharCode.apply(null,new Uint8Array(t))}(t.buff),t},s.ArrayBuffer.prototype.setState=function(t){return t.buff=function(t,r){var e,n=t.length,o=new ArrayBuffer(n),f=new Uint8Array(o);for(e=0;e<n;e+=1)f[e]=t.charCodeAt(e);return r?f:o}(t.buff,!0),s.prototype.setState.call(this,t)},s.ArrayBuffer.prototype.destroy=s.prototype.destroy,s.ArrayBuffer.prototype._finish=s.prototype._finish,s.ArrayBuffer.hash=function(t,r){var e=i(function(t){var r,e,n,o,f,i,u=t.length,s=[1732584193,-271733879,-1732584194,271733878];for(r=64;r<=u;r+=64)a(s,c(t.subarray(r-64,r)));for(e=(t=r-64<u?t.subarray(r-64):new Uint8Array(0)).length,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r=0;r<e;r+=1)n[r>>2]|=t[r]<<(r%4<<3);if(n[r>>2]|=128<<(r%4<<3),55<r)for(a(s,n),r=0;r<16;r+=1)n[r]=0;return o=(o=8*u).toString(16).match(/(.*?)(.{0,8})$/),f=parseInt(o[2],16),i=parseInt(o[1],16)||0,n[14]=f,n[15]=i,a(s,n),s}(new Uint8Array(t)));return r?u(e):e},s})},{}],2:[function(t,r,e){"use strict";var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},p=t("spark-md5");p.file=function(e,r){if("string"==typeof e){var n=new XMLHttpRequest;return n.open("GET",e,!0),n.responseType="blob",n.onload=function(t){200==t.target.status?p.file(n.response,r):(console.error(t),r(null))},n.onerror=function(t){console.error(t),r(null)},void n.send()}var o=File.prototype.slice||File.prototype.mozSlice||File.prototype.webkitSlice,f=2097152,i=Math.ceil(e.size/f),u=0,s=new p.ArrayBuffer,a=new FileReader;function h(){var t=u*f,r=t+f>=e.size?e.size:t+f;a.readAsArrayBuffer(o.call(e,t,r))}a.onload=function(t){s.append(t.target.result),++u<i?h():r(s.end())},a.onerror=function(){console.error("文件读取失败"),r(null)},h()},"function"==typeof define&&define.amd?define(function(){return p}):"object"===("undefined"==typeof window?"undefined":n(window))?window.SparkMD5=p:"object"===(void 0===e?"undefined":n(e))&&(r.exports=p)},{"spark-md5":1}]},{},[2]);