UNPKG

fluxforge

Version:

基于 Web Worker 的文件分片库,提供并发处理、可暂停/取消任务控制、自动重试与 MD5 校验。

5 lines (4 loc) 22.3 kB
(function(p,w){typeof exports=="object"&&typeof module!="undefined"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(p=typeof globalThis!="undefined"?globalThis:p||self,w(p.FluxForge={}))})(this,function(p){"use strict";var V=Object.defineProperty;var k=(p,w,S)=>w in p?V(p,w,{enumerable:!0,configurable:!0,writable:!0,value:S}):p[w]=S;var M=(p,w,S)=>k(p,typeof w!="symbol"?w+"":w,S);function w(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var S={exports:{}},F;function P(){return F||(F=1,function(o,a){(function(h){o.exports=h()})(function(h){var u=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function s(f,i){var e=f[0],t=f[1],n=f[2],r=f[3];e+=(t&n|~t&r)+i[0]-680876936|0,e=(e<<7|e>>>25)+t|0,r+=(e&t|~e&n)+i[1]-389564586|0,r=(r<<12|r>>>20)+e|0,n+=(r&e|~r&t)+i[2]+606105819|0,n=(n<<17|n>>>15)+r|0,t+=(n&r|~n&e)+i[3]-1044525330|0,t=(t<<22|t>>>10)+n|0,e+=(t&n|~t&r)+i[4]-176418897|0,e=(e<<7|e>>>25)+t|0,r+=(e&t|~e&n)+i[5]+1200080426|0,r=(r<<12|r>>>20)+e|0,n+=(r&e|~r&t)+i[6]-1473231341|0,n=(n<<17|n>>>15)+r|0,t+=(n&r|~n&e)+i[7]-45705983|0,t=(t<<22|t>>>10)+n|0,e+=(t&n|~t&r)+i[8]+1770035416|0,e=(e<<7|e>>>25)+t|0,r+=(e&t|~e&n)+i[9]-1958414417|0,r=(r<<12|r>>>20)+e|0,n+=(r&e|~r&t)+i[10]-42063|0,n=(n<<17|n>>>15)+r|0,t+=(n&r|~n&e)+i[11]-1990404162|0,t=(t<<22|t>>>10)+n|0,e+=(t&n|~t&r)+i[12]+1804603682|0,e=(e<<7|e>>>25)+t|0,r+=(e&t|~e&n)+i[13]-40341101|0,r=(r<<12|r>>>20)+e|0,n+=(r&e|~r&t)+i[14]-1502002290|0,n=(n<<17|n>>>15)+r|0,t+=(n&r|~n&e)+i[15]+1236535329|0,t=(t<<22|t>>>10)+n|0,e+=(t&r|n&~r)+i[1]-165796510|0,e=(e<<5|e>>>27)+t|0,r+=(e&n|t&~n)+i[6]-1069501632|0,r=(r<<9|r>>>23)+e|0,n+=(r&t|e&~t)+i[11]+643717713|0,n=(n<<14|n>>>18)+r|0,t+=(n&e|r&~e)+i[0]-373897302|0,t=(t<<20|t>>>12)+n|0,e+=(t&r|n&~r)+i[5]-701558691|0,e=(e<<5|e>>>27)+t|0,r+=(e&n|t&~n)+i[10]+38016083|0,r=(r<<9|r>>>23)+e|0,n+=(r&t|e&~t)+i[15]-660478335|0,n=(n<<14|n>>>18)+r|0,t+=(n&e|r&~e)+i[4]-405537848|0,t=(t<<20|t>>>12)+n|0,e+=(t&r|n&~r)+i[9]+568446438|0,e=(e<<5|e>>>27)+t|0,r+=(e&n|t&~n)+i[14]-1019803690|0,r=(r<<9|r>>>23)+e|0,n+=(r&t|e&~t)+i[3]-187363961|0,n=(n<<14|n>>>18)+r|0,t+=(n&e|r&~e)+i[8]+1163531501|0,t=(t<<20|t>>>12)+n|0,e+=(t&r|n&~r)+i[13]-1444681467|0,e=(e<<5|e>>>27)+t|0,r+=(e&n|t&~n)+i[2]-51403784|0,r=(r<<9|r>>>23)+e|0,n+=(r&t|e&~t)+i[7]+1735328473|0,n=(n<<14|n>>>18)+r|0,t+=(n&e|r&~e)+i[12]-1926607734|0,t=(t<<20|t>>>12)+n|0,e+=(t^n^r)+i[5]-378558|0,e=(e<<4|e>>>28)+t|0,r+=(e^t^n)+i[8]-2022574463|0,r=(r<<11|r>>>21)+e|0,n+=(r^e^t)+i[11]+1839030562|0,n=(n<<16|n>>>16)+r|0,t+=(n^r^e)+i[14]-35309556|0,t=(t<<23|t>>>9)+n|0,e+=(t^n^r)+i[1]-1530992060|0,e=(e<<4|e>>>28)+t|0,r+=(e^t^n)+i[4]+1272893353|0,r=(r<<11|r>>>21)+e|0,n+=(r^e^t)+i[7]-155497632|0,n=(n<<16|n>>>16)+r|0,t+=(n^r^e)+i[10]-1094730640|0,t=(t<<23|t>>>9)+n|0,e+=(t^n^r)+i[13]+681279174|0,e=(e<<4|e>>>28)+t|0,r+=(e^t^n)+i[0]-358537222|0,r=(r<<11|r>>>21)+e|0,n+=(r^e^t)+i[3]-722521979|0,n=(n<<16|n>>>16)+r|0,t+=(n^r^e)+i[6]+76029189|0,t=(t<<23|t>>>9)+n|0,e+=(t^n^r)+i[9]-640364487|0,e=(e<<4|e>>>28)+t|0,r+=(e^t^n)+i[12]-421815835|0,r=(r<<11|r>>>21)+e|0,n+=(r^e^t)+i[15]+530742520|0,n=(n<<16|n>>>16)+r|0,t+=(n^r^e)+i[2]-995338651|0,t=(t<<23|t>>>9)+n|0,e+=(n^(t|~r))+i[0]-198630844|0,e=(e<<6|e>>>26)+t|0,r+=(t^(e|~n))+i[7]+1126891415|0,r=(r<<10|r>>>22)+e|0,n+=(e^(r|~t))+i[14]-1416354905|0,n=(n<<15|n>>>17)+r|0,t+=(r^(n|~e))+i[5]-57434055|0,t=(t<<21|t>>>11)+n|0,e+=(n^(t|~r))+i[12]+1700485571|0,e=(e<<6|e>>>26)+t|0,r+=(t^(e|~n))+i[3]-1894986606|0,r=(r<<10|r>>>22)+e|0,n+=(e^(r|~t))+i[10]-1051523|0,n=(n<<15|n>>>17)+r|0,t+=(r^(n|~e))+i[1]-2054922799|0,t=(t<<21|t>>>11)+n|0,e+=(n^(t|~r))+i[8]+1873313359|0,e=(e<<6|e>>>26)+t|0,r+=(t^(e|~n))+i[15]-30611744|0,r=(r<<10|r>>>22)+e|0,n+=(e^(r|~t))+i[6]-1560198380|0,n=(n<<15|n>>>17)+r|0,t+=(r^(n|~e))+i[13]+1309151649|0,t=(t<<21|t>>>11)+n|0,e+=(n^(t|~r))+i[4]-145523070|0,e=(e<<6|e>>>26)+t|0,r+=(t^(e|~n))+i[11]-1120210379|0,r=(r<<10|r>>>22)+e|0,n+=(e^(r|~t))+i[2]+718787259|0,n=(n<<15|n>>>17)+r|0,t+=(r^(n|~e))+i[9]-343485551|0,t=(t<<21|t>>>11)+n|0,f[0]=e+f[0]|0,f[1]=t+f[1]|0,f[2]=n+f[2]|0,f[3]=r+f[3]|0}function l(f){var i=[],e;for(e=0;e<64;e+=4)i[e>>2]=f.charCodeAt(e)+(f.charCodeAt(e+1)<<8)+(f.charCodeAt(e+2)<<16)+(f.charCodeAt(e+3)<<24);return i}function d(f){var i=[],e;for(e=0;e<64;e+=4)i[e>>2]=f[e]+(f[e+1]<<8)+(f[e+2]<<16)+(f[e+3]<<24);return i}function _(f){var i=f.length,e=[1732584193,-271733879,-1732584194,271733878],t,n,r,b,B,R;for(t=64;t<=i;t+=64)s(e,l(f.substring(t-64,t)));for(f=f.substring(t-64),n=f.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<n;t+=1)r[t>>2]|=f.charCodeAt(t)<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(s(e,r),t=0;t<16;t+=1)r[t]=0;return b=i*8,b=b.toString(16).match(/(.*?)(.{0,8})$/),B=parseInt(b[2],16),R=parseInt(b[1],16)||0,r[14]=B,r[15]=R,s(e,r),e}function y(f){var i=f.length,e=[1732584193,-271733879,-1732584194,271733878],t,n,r,b,B,R;for(t=64;t<=i;t+=64)s(e,d(f.subarray(t-64,t)));for(f=t-64<i?f.subarray(t-64):new Uint8Array(0),n=f.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<n;t+=1)r[t>>2]|=f[t]<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(s(e,r),t=0;t<16;t+=1)r[t]=0;return b=i*8,b=b.toString(16).match(/(.*?)(.{0,8})$/),B=parseInt(b[2],16),R=parseInt(b[1],16)||0,r[14]=B,r[15]=R,s(e,r),e}function U(f){var i="",e;for(e=0;e<4;e+=1)i+=u[f>>e*8+4&15]+u[f>>e*8&15];return i}function g(f){var i;for(i=0;i<f.length;i+=1)f[i]=U(f[i]);return f.join("")}g(_("hello")),typeof ArrayBuffer!="undefined"&&!ArrayBuffer.prototype.slice&&function(){function f(i,e){return i=i|0||0,i<0?Math.max(i+e,0):Math.min(i,e)}ArrayBuffer.prototype.slice=function(i,e){var t=this.byteLength,n=f(i,t),r=t,b,B,R,j;return e!==h&&(r=f(e,t)),n>r?new ArrayBuffer(0):(b=r-n,B=new ArrayBuffer(b),R=new Uint8Array(B),j=new Uint8Array(this,n,b),R.set(j),B)}}();function E(f){return/[\u0080-\uFFFF]/.test(f)&&(f=unescape(encodeURIComponent(f))),f}function A(f,i){var e=f.length,t=new ArrayBuffer(e),n=new Uint8Array(t),r;for(r=0;r<e;r+=1)n[r]=f.charCodeAt(r);return i?n:t}function v(f){return String.fromCharCode.apply(null,new Uint8Array(f))}function C(f,i,e){var t=new Uint8Array(f.byteLength+i.byteLength);return t.set(new Uint8Array(f)),t.set(new Uint8Array(i),f.byteLength),t}function m(f){var i=[],e=f.length,t;for(t=0;t<e-1;t+=2)i.push(parseInt(f.substr(t,2),16));return String.fromCharCode.apply(String,i)}function c(){this.reset()}return c.prototype.append=function(f){return this.appendBinary(E(f)),this},c.prototype.appendBinary=function(f){this._buff+=f,this._length+=f.length;var i=this._buff.length,e;for(e=64;e<=i;e+=64)s(this._hash,l(this._buff.substring(e-64,e)));return this._buff=this._buff.substring(e-64),this},c.prototype.end=function(f){var i=this._buff,e=i.length,t,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],r;for(t=0;t<e;t+=1)n[t>>2]|=i.charCodeAt(t)<<(t%4<<3);return this._finish(n,e),r=g(this._hash),f&&(r=m(r)),this.reset(),r},c.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},c.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},c.prototype.setState=function(f){return this._buff=f.buff,this._length=f.length,this._hash=f.hash,this},c.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},c.prototype._finish=function(f,i){var e=i,t,n,r;if(f[e>>2]|=128<<(e%4<<3),e>55)for(s(this._hash,f),e=0;e<16;e+=1)f[e]=0;t=this._length*8,t=t.toString(16).match(/(.*?)(.{0,8})$/),n=parseInt(t[2],16),r=parseInt(t[1],16)||0,f[14]=n,f[15]=r,s(this._hash,f)},c.hash=function(f,i){return c.hashBinary(E(f),i)},c.hashBinary=function(f,i){var e=_(f),t=g(e);return i?m(t):t},c.ArrayBuffer=function(){this.reset()},c.ArrayBuffer.prototype.append=function(f){var i=C(this._buff.buffer,f),e=i.length,t;for(this._length+=f.byteLength,t=64;t<=e;t+=64)s(this._hash,d(i.subarray(t-64,t)));return this._buff=t-64<e?new Uint8Array(i.buffer.slice(t-64)):new Uint8Array(0),this},c.ArrayBuffer.prototype.end=function(f){var i=this._buff,e=i.length,t=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n,r;for(n=0;n<e;n+=1)t[n>>2]|=i[n]<<(n%4<<3);return this._finish(t,e),r=g(this._hash),f&&(r=m(r)),this.reset(),r},c.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},c.ArrayBuffer.prototype.getState=function(){var f=c.prototype.getState.call(this);return f.buff=v(f.buff),f},c.ArrayBuffer.prototype.setState=function(f){return f.buff=A(f.buff,!0),c.prototype.setState.call(this,f)},c.ArrayBuffer.prototype.destroy=c.prototype.destroy,c.ArrayBuffer.prototype._finish=c.prototype._finish,c.ArrayBuffer.hash=function(f,i){var e=y(new Uint8Array(f)),t=g(e);return i?m(t):t},c})}(S)),S.exports}var T=P();const W=w(T);class L extends Error{constructor(a="Task cancelled"){super(a),this.name="CancellationError"}}class x extends Error{constructor(h,u){const s=u instanceof Error?u.message:String(u);super(`Retry exhausted after ${h} attempts: ${s}`);M(this,"cause");M(this,"attempts");this.name="RetryExhaustedError",this.cause=u,this.attempts=h}}class ${constructor(){M(this,"paused",!1);M(this,"cancelled",!1);M(this,"pauseResolvers",new Set);M(this,"delayHandles",new Set);M(this,"abortController",new AbortController)}get signal(){return this.abortController.signal}get isCancelled(){return this.cancelled}throwIfCancelled(){if(this.cancelled)throw new L}async waitWhilePaused(){for(;this.paused&&!this.cancelled;)await new Promise(a=>{this.pauseResolvers.add(a)});this.throwIfCancelled()}async delay(a){a<=0||await new Promise(h=>{let u;const s={cancel:()=>{clearTimeout(u),this.delayHandles.delete(s),h()}};u=setTimeout(()=>{this.delayHandles.delete(s),h()},a),this.delayHandles.add(s)})}pause(){this.cancelled||this.paused||(this.paused=!0)}resume(){if(!this.paused)return;this.paused=!1;const a=[...this.pauseResolvers];this.pauseResolvers.clear(),a.forEach(h=>h())}cancel(){if(this.cancelled)return;this.cancelled=!0,this.paused=!1,this.abortController.abort(),this.flushDelays();const a=[...this.pauseResolvers];this.pauseResolvers.clear(),a.forEach(h=>h())}cleanup(){this.flushDelays(),this.pauseResolvers.clear()}flushDelays(){const a=[...this.delayHandles];this.delayHandles.clear(),a.forEach(h=>h.cancel())}}async function z(o,a,h){const{maxRetries:u,baseDelayMs:s,maxDelayMs:l}=h;let d=0,_;for(;;){a.throwIfCancelled(),await a.waitWhilePaused();try{return await o()}catch(y){if(y instanceof L)throw y;if(a.isCancelled)throw new L;if(_=y,d>=u)throw new x(d+1,_);const U=Math.min(s*2**d,l);d++,await a.delay(U)}}}const I=`(function(){"use strict";function w(s){return s&&s.__esModule&&Object.prototype.hasOwnProperty.call(s,"default")?s.default:s}var m={exports:{}},B;function U(){return B||(B=1,function(s,d){(function(y){s.exports=y()})(function(y){var c=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function a(i,f){var r=i[0],t=i[1],n=i[2],e=i[3];r+=(t&n|~t&e)+f[0]-680876936|0,r=(r<<7|r>>>25)+t|0,e+=(r&t|~r&n)+f[1]-389564586|0,e=(e<<12|e>>>20)+r|0,n+=(e&r|~e&t)+f[2]+606105819|0,n=(n<<17|n>>>15)+e|0,t+=(n&e|~n&r)+f[3]-1044525330|0,t=(t<<22|t>>>10)+n|0,r+=(t&n|~t&e)+f[4]-176418897|0,r=(r<<7|r>>>25)+t|0,e+=(r&t|~r&n)+f[5]+1200080426|0,e=(e<<12|e>>>20)+r|0,n+=(e&r|~e&t)+f[6]-1473231341|0,n=(n<<17|n>>>15)+e|0,t+=(n&e|~n&r)+f[7]-45705983|0,t=(t<<22|t>>>10)+n|0,r+=(t&n|~t&e)+f[8]+1770035416|0,r=(r<<7|r>>>25)+t|0,e+=(r&t|~r&n)+f[9]-1958414417|0,e=(e<<12|e>>>20)+r|0,n+=(e&r|~e&t)+f[10]-42063|0,n=(n<<17|n>>>15)+e|0,t+=(n&e|~n&r)+f[11]-1990404162|0,t=(t<<22|t>>>10)+n|0,r+=(t&n|~t&e)+f[12]+1804603682|0,r=(r<<7|r>>>25)+t|0,e+=(r&t|~r&n)+f[13]-40341101|0,e=(e<<12|e>>>20)+r|0,n+=(e&r|~e&t)+f[14]-1502002290|0,n=(n<<17|n>>>15)+e|0,t+=(n&e|~n&r)+f[15]+1236535329|0,t=(t<<22|t>>>10)+n|0,r+=(t&e|n&~e)+f[1]-165796510|0,r=(r<<5|r>>>27)+t|0,e+=(r&n|t&~n)+f[6]-1069501632|0,e=(e<<9|e>>>23)+r|0,n+=(e&t|r&~t)+f[11]+643717713|0,n=(n<<14|n>>>18)+e|0,t+=(n&r|e&~r)+f[0]-373897302|0,t=(t<<20|t>>>12)+n|0,r+=(t&e|n&~e)+f[5]-701558691|0,r=(r<<5|r>>>27)+t|0,e+=(r&n|t&~n)+f[10]+38016083|0,e=(e<<9|e>>>23)+r|0,n+=(e&t|r&~t)+f[15]-660478335|0,n=(n<<14|n>>>18)+e|0,t+=(n&r|e&~r)+f[4]-405537848|0,t=(t<<20|t>>>12)+n|0,r+=(t&e|n&~e)+f[9]+568446438|0,r=(r<<5|r>>>27)+t|0,e+=(r&n|t&~n)+f[14]-1019803690|0,e=(e<<9|e>>>23)+r|0,n+=(e&t|r&~t)+f[3]-187363961|0,n=(n<<14|n>>>18)+e|0,t+=(n&r|e&~r)+f[8]+1163531501|0,t=(t<<20|t>>>12)+n|0,r+=(t&e|n&~e)+f[13]-1444681467|0,r=(r<<5|r>>>27)+t|0,e+=(r&n|t&~n)+f[2]-51403784|0,e=(e<<9|e>>>23)+r|0,n+=(e&t|r&~t)+f[7]+1735328473|0,n=(n<<14|n>>>18)+e|0,t+=(n&r|e&~r)+f[12]-1926607734|0,t=(t<<20|t>>>12)+n|0,r+=(t^n^e)+f[5]-378558|0,r=(r<<4|r>>>28)+t|0,e+=(r^t^n)+f[8]-2022574463|0,e=(e<<11|e>>>21)+r|0,n+=(e^r^t)+f[11]+1839030562|0,n=(n<<16|n>>>16)+e|0,t+=(n^e^r)+f[14]-35309556|0,t=(t<<23|t>>>9)+n|0,r+=(t^n^e)+f[1]-1530992060|0,r=(r<<4|r>>>28)+t|0,e+=(r^t^n)+f[4]+1272893353|0,e=(e<<11|e>>>21)+r|0,n+=(e^r^t)+f[7]-155497632|0,n=(n<<16|n>>>16)+e|0,t+=(n^e^r)+f[10]-1094730640|0,t=(t<<23|t>>>9)+n|0,r+=(t^n^e)+f[13]+681279174|0,r=(r<<4|r>>>28)+t|0,e+=(r^t^n)+f[0]-358537222|0,e=(e<<11|e>>>21)+r|0,n+=(e^r^t)+f[3]-722521979|0,n=(n<<16|n>>>16)+e|0,t+=(n^e^r)+f[6]+76029189|0,t=(t<<23|t>>>9)+n|0,r+=(t^n^e)+f[9]-640364487|0,r=(r<<4|r>>>28)+t|0,e+=(r^t^n)+f[12]-421815835|0,e=(e<<11|e>>>21)+r|0,n+=(e^r^t)+f[15]+530742520|0,n=(n<<16|n>>>16)+e|0,t+=(n^e^r)+f[2]-995338651|0,t=(t<<23|t>>>9)+n|0,r+=(n^(t|~e))+f[0]-198630844|0,r=(r<<6|r>>>26)+t|0,e+=(t^(r|~n))+f[7]+1126891415|0,e=(e<<10|e>>>22)+r|0,n+=(r^(e|~t))+f[14]-1416354905|0,n=(n<<15|n>>>17)+e|0,t+=(e^(n|~r))+f[5]-57434055|0,t=(t<<21|t>>>11)+n|0,r+=(n^(t|~e))+f[12]+1700485571|0,r=(r<<6|r>>>26)+t|0,e+=(t^(r|~n))+f[3]-1894986606|0,e=(e<<10|e>>>22)+r|0,n+=(r^(e|~t))+f[10]-1051523|0,n=(n<<15|n>>>17)+e|0,t+=(e^(n|~r))+f[1]-2054922799|0,t=(t<<21|t>>>11)+n|0,r+=(n^(t|~e))+f[8]+1873313359|0,r=(r<<6|r>>>26)+t|0,e+=(t^(r|~n))+f[15]-30611744|0,e=(e<<10|e>>>22)+r|0,n+=(r^(e|~t))+f[6]-1560198380|0,n=(n<<15|n>>>17)+e|0,t+=(e^(n|~r))+f[13]+1309151649|0,t=(t<<21|t>>>11)+n|0,r+=(n^(t|~e))+f[4]-145523070|0,r=(r<<6|r>>>26)+t|0,e+=(t^(r|~n))+f[11]-1120210379|0,e=(e<<10|e>>>22)+r|0,n+=(r^(e|~t))+f[2]+718787259|0,n=(n<<15|n>>>17)+e|0,t+=(e^(n|~r))+f[9]-343485551|0,t=(t<<21|t>>>11)+n|0,i[0]=r+i[0]|0,i[1]=t+i[1]|0,i[2]=n+i[2]|0,i[3]=e+i[3]|0}function l(i){var f=[],r;for(r=0;r<64;r+=4)f[r>>2]=i.charCodeAt(r)+(i.charCodeAt(r+1)<<8)+(i.charCodeAt(r+2)<<16)+(i.charCodeAt(r+3)<<24);return f}function u(i){var f=[],r;for(r=0;r<64;r+=4)f[r>>2]=i[r]+(i[r+1]<<8)+(i[r+2]<<16)+(i[r+3]<<24);return f}function b(i){var f=i.length,r=[1732584193,-271733879,-1732584194,271733878],t,n,e,o,p,g;for(t=64;t<=f;t+=64)a(r,l(i.substring(t-64,t)));for(i=i.substring(t-64),n=i.length,e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<n;t+=1)e[t>>2]|=i.charCodeAt(t)<<(t%4<<3);if(e[t>>2]|=128<<(t%4<<3),t>55)for(a(r,e),t=0;t<16;t+=1)e[t]=0;return o=f*8,o=o.toString(16).match(/(.*?)(.{0,8})$/),p=parseInt(o[2],16),g=parseInt(o[1],16)||0,e[14]=p,e[15]=g,a(r,e),r}function F(i){var f=i.length,r=[1732584193,-271733879,-1732584194,271733878],t,n,e,o,p,g;for(t=64;t<=f;t+=64)a(r,u(i.subarray(t-64,t)));for(i=t-64<f?i.subarray(t-64):new Uint8Array(0),n=i.length,e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<n;t+=1)e[t>>2]|=i[t]<<(t%4<<3);if(e[t>>2]|=128<<(t%4<<3),t>55)for(a(r,e),t=0;t<16;t+=1)e[t]=0;return o=f*8,o=o.toString(16).match(/(.*?)(.{0,8})$/),p=parseInt(o[2],16),g=parseInt(o[1],16)||0,e[14]=p,e[15]=g,a(r,e),r}function L(i){var f="",r;for(r=0;r<4;r+=1)f+=c[i>>r*8+4&15]+c[i>>r*8&15];return f}function _(i){var f;for(f=0;f<i.length;f+=1)i[f]=L(i[f]);return i.join("")}_(b("hello")),typeof ArrayBuffer!="undefined"&&!ArrayBuffer.prototype.slice&&function(){function i(f,r){return f=f|0||0,f<0?Math.max(f+r,0):Math.min(f,r)}ArrayBuffer.prototype.slice=function(f,r){var t=this.byteLength,n=i(f,t),e=t,o,p,g,S;return r!==y&&(e=i(r,t)),n>e?new ArrayBuffer(0):(o=e-n,p=new ArrayBuffer(o),g=new Uint8Array(p),S=new Uint8Array(this,n,o),g.set(S),p)}}();function v(i){return/[\\u0080-\\uFFFF]/.test(i)&&(i=unescape(encodeURIComponent(i))),i}function j(i,f){var r=i.length,t=new ArrayBuffer(r),n=new Uint8Array(t),e;for(e=0;e<r;e+=1)n[e]=i.charCodeAt(e);return f?n:t}function D(i){return String.fromCharCode.apply(null,new Uint8Array(i))}function E(i,f,r){var t=new Uint8Array(i.byteLength+f.byteLength);return t.set(new Uint8Array(i)),t.set(new Uint8Array(f),i.byteLength),t}function A(i){var f=[],r=i.length,t;for(t=0;t<r-1;t+=2)f.push(parseInt(i.substr(t,2),16));return String.fromCharCode.apply(String,f)}function h(){this.reset()}return h.prototype.append=function(i){return this.appendBinary(v(i)),this},h.prototype.appendBinary=function(i){this._buff+=i,this._length+=i.length;var f=this._buff.length,r;for(r=64;r<=f;r+=64)a(this._hash,l(this._buff.substring(r-64,r)));return this._buff=this._buff.substring(r-64),this},h.prototype.end=function(i){var f=this._buff,r=f.length,t,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e;for(t=0;t<r;t+=1)n[t>>2]|=f.charCodeAt(t)<<(t%4<<3);return this._finish(n,r),e=_(this._hash),i&&(e=A(e)),this.reset(),e},h.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},h.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},h.prototype.setState=function(i){return this._buff=i.buff,this._length=i.length,this._hash=i.hash,this},h.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},h.prototype._finish=function(i,f){var r=f,t,n,e;if(i[r>>2]|=128<<(r%4<<3),r>55)for(a(this._hash,i),r=0;r<16;r+=1)i[r]=0;t=this._length*8,t=t.toString(16).match(/(.*?)(.{0,8})$/),n=parseInt(t[2],16),e=parseInt(t[1],16)||0,i[14]=n,i[15]=e,a(this._hash,i)},h.hash=function(i,f){return h.hashBinary(v(i),f)},h.hashBinary=function(i,f){var r=b(i),t=_(r);return f?A(t):t},h.ArrayBuffer=function(){this.reset()},h.ArrayBuffer.prototype.append=function(i){var f=E(this._buff.buffer,i),r=f.length,t;for(this._length+=i.byteLength,t=64;t<=r;t+=64)a(this._hash,u(f.subarray(t-64,t)));return this._buff=t-64<r?new Uint8Array(f.buffer.slice(t-64)):new Uint8Array(0),this},h.ArrayBuffer.prototype.end=function(i){var f=this._buff,r=f.length,t=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n,e;for(n=0;n<r;n+=1)t[n>>2]|=f[n]<<(n%4<<3);return this._finish(t,r),e=_(this._hash),i&&(e=A(e)),this.reset(),e},h.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},h.ArrayBuffer.prototype.getState=function(){var i=h.prototype.getState.call(this);return i.buff=D(i.buff),i},h.ArrayBuffer.prototype.setState=function(i){return i.buff=j(i.buff,!0),h.prototype.setState.call(this,i)},h.ArrayBuffer.prototype.destroy=h.prototype.destroy,h.ArrayBuffer.prototype._finish=h.prototype._finish,h.ArrayBuffer.hash=function(i,f){var r=F(new Uint8Array(i)),t=_(r);return f?A(t):t},h})}(m)),m.exports}var C=U(),M=w(C);async function I(s,d,y){const c=d*y,a=Math.min(c+y,s.size),u=await s.slice(c,a).arrayBuffer(),b=new M.ArrayBuffer;return b.append(u),{type:"chunk",index:d,start:c,end:a,hash:b.end()}}onmessage=async({data:s})=>{const{file:d,chunkSize:y,start:c,end:a}=s;for(let l=c;l<a;l++)try{const u=await I(d,l,y);postMessage(u)}catch(u){const b=u instanceof Error?u.message:String(u);postMessage({type:"error",index:l,message:b});return}}})(); //# sourceMappingURL=worker-Pp9tipE5.js.map `,D=typeof self!="undefined"&&self.Blob&&new Blob([I],{type:"text/javascript;charset=utf-8"});function O(o){let a;try{if(a=D&&(self.URL||self.webkitURL).createObjectURL(D),!a)throw"";const h=new Worker(a,{name:o==null?void 0:o.name});return h.addEventListener("error",()=>{(self.URL||self.webkitURL).revokeObjectURL(a)}),h}catch(h){return new Worker("data:text/javascript;charset=utf-8,"+encodeURIComponent(I),{name:o==null?void 0:o.name})}finally{a&&(self.URL||self.webkitURL).revokeObjectURL(a)}}const H=1024*1024,Y=6,N=3,X=500,K=5e3;function Z(o,a,h){const u=new O;return u.onmessage=({data:s})=>{const l=h.get(s.index);if(l){if(h.delete(s.index),s.type==="error"){l.reject(new Error(`Failed to hash chunk #${s.index}: ${s.message}`));return}l.resolve({index:s.index,start:s.start,end:s.end,hash:s.hash,blob:o.slice(s.start,s.end)})}},u.onerror=s=>{for(let l=a.start;l<a.end;l++){const d=h.get(l);d&&(h.delete(l),d.reject(new Error(`Worker error: ${s.message||"unknown"}`)))}},u.postMessage(a),u}function q(o,a={}){var g,E;if(!o||typeof o.size!="number"||typeof o.slice!="function")throw new TypeError("chunkFile expects a File or Blob");if(o.size===0)return[];const h=(g=a.chunkSize)!=null?g:Math.min(H,o.size);if(!Number.isFinite(h)||h<=0)throw new RangeError("chunkSize must be a positive number");const u=Math.ceil(o.size/h),s=typeof navigator!="undefined"&&navigator.hardwareConcurrency||4,l=Math.max(1,Math.min((E=a.workerCount)!=null?E:s,u)),d=new Map,_=Array.from({length:u},(A,v)=>new Promise((C,m)=>{d.set(v,{resolve:C,reject:m})})),y=Math.ceil(u/l),U=[];for(let A=0;A<l;A++){const v=A*y;if(v>=u)break;const C=Math.min(v+y,u);U.push(Z(o,{file:o,chunkSize:h,start:v,end:C},d))}return Promise.allSettled(_).finally(()=>{U.forEach(A=>A.terminate()),d.clear()}),_}function G(o,a,h={}){const{concurrency:u=Y,maxRetries:s=N,retryBaseDelayMs:l=X,retryMaxDelayMs:d=K,onProgress:_}=h;if(u<1)throw new RangeError("concurrency must be >= 1");if(s<0)throw new RangeError("maxRetries must be >= 0");const y=new $,U=o.length,g=new Set;let E=0;const A=async C=>{const m=await C;await z(()=>Promise.resolve(a(m,y.signal)),y,{maxRetries:s,baseDelayMs:l,maxDelayMs:d}),E++,_==null||_(E,U)},v=(async()=>{try{for(const C of o){y.throwIfCancelled(),await y.waitWhilePaused();const m=A(C).finally(()=>g.delete(m));g.add(m),g.size>=u&&await Promise.race([...g].map(c=>c.catch(()=>{})))}await Promise.all(g)}finally{await Promise.allSettled(g),y.cleanup()}})();return{pause:()=>y.pause(),resume:()=>y.resume(),cancel:()=>y.cancel(),promise:v}}async function J(o){return Promise.all(o)}async function Q(o){const a=new W.ArrayBuffer;for(const h of o){const s=await(await h).blob.arrayBuffer();a.append(s)}return a.end()}p.CancellationError=L,p.RetryExhaustedError=x,p.calculateFileHash=Q,p.chunkFile=q,p.collectChunks=J,p.processChunks=G,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})}); //# sourceMappingURL=index.umd.cjs.map