fluxforge
Version:
基于 Web Worker 的文件分片库,提供并发处理、可暂停/取消任务控制、自动重试与 MD5 校验。
391 lines (390 loc) • 27.8 kB
JavaScript
var F = Object.defineProperty;
var D = (a, s, o) => s in a ? F(a, s, { enumerable: !0, configurable: !0, writable: !0, value: o }) : a[s] = o;
var S = (a, s, o) => D(a, typeof s != "symbol" ? s + "" : s, o);
function j(a) {
return a && a.__esModule && Object.prototype.hasOwnProperty.call(a, "default") ? a.default : a;
}
var E = { exports: {} }, L;
function P() {
return L || (L = 1, function(a, s) {
(function(o) {
a.exports = o();
})(function(o) {
var u = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
function h(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 y(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 b(f) {
var i = f.length, e = [1732584193, -271733879, -1732584194, 271733878], t, n, r, g, v, U;
for (t = 64; t <= i; t += 64)
h(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 (h(e, r), t = 0; t < 16; t += 1)
r[t] = 0;
return g = i * 8, g = g.toString(16).match(/(.*?)(.{0,8})$/), v = parseInt(g[2], 16), U = parseInt(g[1], 16) || 0, r[14] = v, r[15] = U, h(e, r), e;
}
function p(f) {
var i = f.length, e = [1732584193, -271733879, -1732584194, 271733878], t, n, r, g, v, U;
for (t = 64; t <= i; t += 64)
h(e, y(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 (h(e, r), t = 0; t < 16; t += 1)
r[t] = 0;
return g = i * 8, g = g.toString(16).match(/(.*?)(.{0,8})$/), v = parseInt(g[2], 16), U = parseInt(g[1], 16) || 0, r[14] = v, r[15] = U, h(e, r), e;
}
function B(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 d(f) {
var i;
for (i = 0; i < f.length; i += 1)
f[i] = B(f[i]);
return f.join("");
}
d(b("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, g, v, U, M;
return e !== o && (r = f(e, t)), n > r ? new ArrayBuffer(0) : (g = r - n, v = new ArrayBuffer(g), U = new Uint8Array(v), M = new Uint8Array(this, n, g), U.set(M), v);
};
}();
function C(f) {
return /[\u0080-\uFFFF]/.test(f) && (f = unescape(encodeURIComponent(f))), f;
}
function _(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 A(f) {
return String.fromCharCode.apply(null, new Uint8Array(f));
}
function m(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 w(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(C(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)
h(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 = d(this._hash), f && (r = w(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 (h(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, h(this._hash, f);
}, c.hash = function(f, i) {
return c.hashBinary(C(f), i);
}, c.hashBinary = function(f, i) {
var e = b(f), t = d(e);
return i ? w(t) : t;
}, c.ArrayBuffer = function() {
this.reset();
}, c.ArrayBuffer.prototype.append = function(f) {
var i = m(this._buff.buffer, f), e = i.length, t;
for (this._length += f.byteLength, t = 64; t <= e; t += 64)
h(this._hash, y(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 = d(this._hash), f && (r = w(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 = A(f.buff), f;
}, c.ArrayBuffer.prototype.setState = function(f) {
return f.buff = _(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 = p(new Uint8Array(f)), t = d(e);
return i ? w(t) : t;
}, c;
});
}(E)), E.exports;
}
var T = P();
const W = /* @__PURE__ */ j(T);
class R extends Error {
constructor(s = "Task cancelled") {
super(s), this.name = "CancellationError";
}
}
class $ extends Error {
constructor(o, u) {
const h = u instanceof Error ? u.message : String(u);
super(`Retry exhausted after ${o} attempts: ${h}`);
S(this, "cause");
S(this, "attempts");
this.name = "RetryExhaustedError", this.cause = u, this.attempts = o;
}
}
class z {
constructor() {
S(this, "paused", !1);
S(this, "cancelled", !1);
S(this, "pauseResolvers", /* @__PURE__ */ new Set());
S(this, "delayHandles", /* @__PURE__ */ new Set());
S(this, "abortController", new AbortController());
}
get signal() {
return this.abortController.signal;
}
get isCancelled() {
return this.cancelled;
}
throwIfCancelled() {
if (this.cancelled)
throw new R();
}
async waitWhilePaused() {
for (; this.paused && !this.cancelled; )
await new Promise((s) => {
this.pauseResolvers.add(s);
});
this.throwIfCancelled();
}
async delay(s) {
s <= 0 || await new Promise((o) => {
let u;
const h = {
cancel: () => {
clearTimeout(u), this.delayHandles.delete(h), o();
}
};
u = setTimeout(() => {
this.delayHandles.delete(h), o();
}, s), this.delayHandles.add(h);
});
}
pause() {
this.cancelled || this.paused || (this.paused = !0);
}
resume() {
if (!this.paused)
return;
this.paused = !1;
const s = [...this.pauseResolvers];
this.pauseResolvers.clear(), s.forEach((o) => o());
}
cancel() {
if (this.cancelled)
return;
this.cancelled = !0, this.paused = !1, this.abortController.abort(), this.flushDelays();
const s = [...this.pauseResolvers];
this.pauseResolvers.clear(), s.forEach((o) => o());
}
cleanup() {
this.flushDelays(), this.pauseResolvers.clear();
}
flushDelays() {
const s = [...this.delayHandles];
this.delayHandles.clear(), s.forEach((o) => o.cancel());
}
}
async function O(a, s, o) {
const { maxRetries: u, baseDelayMs: h, maxDelayMs: l } = o;
let y = 0, b;
for (; ; ) {
s.throwIfCancelled(), await s.waitWhilePaused();
try {
return await a();
} catch (p) {
if (p instanceof R)
throw p;
if (s.isCancelled)
throw new R();
if (b = p, y >= u)
throw new $(y + 1, b);
const B = Math.min(h * 2 ** y, l);
y++, await s.delay(B);
}
}
}
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
`, x = typeof self != "undefined" && self.Blob && new Blob([I], { type: "text/javascript;charset=utf-8" });
function H(a) {
let s;
try {
if (s = x && (self.URL || self.webkitURL).createObjectURL(x), !s) throw "";
const o = new Worker(s, {
name: a == null ? void 0 : a.name
});
return o.addEventListener("error", () => {
(self.URL || self.webkitURL).revokeObjectURL(s);
}), o;
} catch (o) {
return new Worker(
"data:text/javascript;charset=utf-8," + encodeURIComponent(I),
{
name: a == null ? void 0 : a.name
}
);
} finally {
s && (self.URL || self.webkitURL).revokeObjectURL(s);
}
}
const Y = 1024 * 1024, N = 6, X = 3, K = 500, Z = 5e3;
function q(a, s, o) {
const u = new H();
return u.onmessage = ({ data: h }) => {
const l = o.get(h.index);
if (l) {
if (o.delete(h.index), h.type === "error") {
l.reject(new Error(`Failed to hash chunk #${h.index}: ${h.message}`));
return;
}
l.resolve({
index: h.index,
start: h.start,
end: h.end,
hash: h.hash,
blob: a.slice(h.start, h.end)
});
}
}, u.onerror = (h) => {
for (let l = s.start; l < s.end; l++) {
const y = o.get(l);
y && (o.delete(l), y.reject(new Error(`Worker error: ${h.message || "unknown"}`)));
}
}, u.postMessage(s), u;
}
function J(a, s = {}) {
var d, C;
if (!a || typeof a.size != "number" || typeof a.slice != "function")
throw new TypeError("chunkFile expects a File or Blob");
if (a.size === 0)
return [];
const o = (d = s.chunkSize) != null ? d : Math.min(Y, a.size);
if (!Number.isFinite(o) || o <= 0)
throw new RangeError("chunkSize must be a positive number");
const u = Math.ceil(a.size / o), h = typeof navigator != "undefined" && navigator.hardwareConcurrency || 4, l = Math.max(1, Math.min((C = s.workerCount) != null ? C : h, u)), y = /* @__PURE__ */ new Map(), b = Array.from({ length: u }, (_, A) => new Promise((m, w) => {
y.set(A, { resolve: m, reject: w });
})), p = Math.ceil(u / l), B = [];
for (let _ = 0; _ < l; _++) {
const A = _ * p;
if (A >= u)
break;
const m = Math.min(A + p, u);
B.push(q(a, { file: a, chunkSize: o, start: A, end: m }, y));
}
return Promise.allSettled(b).finally(() => {
B.forEach((_) => _.terminate()), y.clear();
}), b;
}
function Q(a, s, o = {}) {
const {
concurrency: u = N,
maxRetries: h = X,
retryBaseDelayMs: l = K,
retryMaxDelayMs: y = Z,
onProgress: b
} = o;
if (u < 1)
throw new RangeError("concurrency must be >= 1");
if (h < 0)
throw new RangeError("maxRetries must be >= 0");
const p = new z(), B = a.length, d = /* @__PURE__ */ new Set();
let C = 0;
const _ = async (m) => {
const w = await m;
await O(
() => Promise.resolve(s(w, p.signal)),
p,
{ maxRetries: h, baseDelayMs: l, maxDelayMs: y }
), C++, b == null || b(C, B);
}, A = (async () => {
try {
for (const m of a) {
p.throwIfCancelled(), await p.waitWhilePaused();
const w = _(m).finally(() => d.delete(w));
d.add(w), d.size >= u && await Promise.race([...d].map((c) => c.catch(() => {
})));
}
await Promise.all(d);
} finally {
await Promise.allSettled(d), p.cleanup();
}
})();
return {
pause: () => p.pause(),
resume: () => p.resume(),
cancel: () => p.cancel(),
promise: A
};
}
async function V(a) {
return Promise.all(a);
}
async function k(a) {
const s = new W.ArrayBuffer();
for (const o of a) {
const h = await (await o).blob.arrayBuffer();
s.append(h);
}
return s.end();
}
export {
R as CancellationError,
$ as RetryExhaustedError,
k as calculateFileHash,
J as chunkFile,
V as collectChunks,
Q as processChunks
};
//# sourceMappingURL=index.js.map