Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

torrefy

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

torrefy - npm Package Compare versions

Comparing version 2.0.5 to 2.0.6

2

dist/index.js

@@ -1,1 +0,1 @@

var e={913:()=>{try{self["workbox:core:6.5.3"]&&_()}catch(e){}},1:()=>{try{self["workbox:streams:6.5.3"]&&_()}catch(e){}},211:(e,t,n)=>{n.r(t),n.d(t,{default:()=>w});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(e,t,n,r){let i,s,o;const a=t||[0],u=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<e.length;i+=1)o=i+u,s=o>>>2,a.length<=s&&a.push(0),a[s]|=e[i]<<8*(c+r*(o%4));return{value:a,binLen:8*e.length+n}}function s(e,t,n){switch(t){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(e,t,r){return function(e,t,n,r){let i,s,o,a;if(0!=e.length%2)throw new Error("String of HEX type must be in byte increments");const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(i=0;i<e.length;i+=2){if(s=parseInt(e.substr(i,2),16),isNaN(s))throw new Error("String of HEX type contains invalid characters");for(a=(i>>>1)+c,o=a>>>2;u.length<=o;)u.push(0);u[o]|=s<<8*(h+r*(a%4))}return{value:u,binLen:4*e.length+n}}(e,t,r,n)};case"TEXT":return function(e,r,i){return function(e,t,n,r,i){let s,o,a,u,c,h,l,f,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===t)for(l=-1===i?3:0,a=0;a<e.length;a+=1)for(s=e.charCodeAt(a),o=[],128>s?o.push(s):2048>s?(o.push(192|s>>>6),o.push(128|63&s)):55296>s||57344<=s?o.push(224|s>>>12,128|s>>>6&63,128|63&s):(a+=1,s=65536+((1023&s)<<10|1023&e.charCodeAt(a)),o.push(240|s>>>18,128|s>>>12&63,128|s>>>6&63,128|63&s)),u=0;u<o.length;u+=1){for(h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=o[u]<<8*(l+i*(h%4)),p+=1}else for(l=-1===i?2:0,f="UTF16LE"===t&&1!==i||"UTF16LE"!==t&&1===i,a=0;a<e.length;a+=1){for(s=e.charCodeAt(a),!0===f&&(u=255&s,s=u<<8|s>>>8),h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=s<<8*(l+i*(h%4)),p+=2}return{value:d,binLen:8*p+r}}(e,t,r,i,n)};case"B64":return function(e,t,i){return function(e,t,n,i){let s,o,a,u,c,h,l,f=0;const p=t||[0],d=(n=n||0)>>>3,g=-1===i?3:0,w=e.indexOf("=");if(-1===e.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(e=e.replace(/=/g,""),-1!==w&&w<e.length)throw new Error("Invalid '=' found in base-64 string");for(o=0;o<e.length;o+=4){for(c=e.substr(o,4),u=0,a=0;a<c.length;a+=1)s=r.indexOf(c.charAt(a)),u|=s<<18-6*a;for(a=0;a<c.length-1;a+=1){for(l=f+d,h=l>>>2;p.length<=h;)p.push(0);p[h]|=(u>>>16-8*a&255)<<8*(g+i*(l%4)),f+=1}}return{value:p,binLen:8*f+n}}(e,t,i,n)};case"BYTES":return function(e,t,r){return function(e,t,n,r){let i,s,o,a;const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(s=0;s<e.length;s+=1)i=e.charCodeAt(s),a=s+c,o=a>>>2,u.length<=o&&u.push(0),u[o]|=i<<8*(h+r*(a%4));return{value:u,binLen:8*e.length+n}}(e,t,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e,t,r){return function(e,t,n,r){return i(new Uint8Array(e),t,n,r)}(e,t,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e,t,r){return i(e,t,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function o(e,t,n,i){switch(e){case"HEX":return function(e){return function(e,t,n,r){const i="0123456789abcdef";let s,o,a="";const u=t/8,c=-1===n?3:0;for(s=0;s<u;s+=1)o=e[s>>>2]>>>8*(c+n*(s%4)),a+=i.charAt(o>>>4&15)+i.charAt(15&o);return r.outputUpper?a.toUpperCase():a}(e,t,n,i)};case"B64":return function(e){return function(e,t,n,i){let s,o,a,u,c,h="";const l=t/8,f=-1===n?3:0;for(s=0;s<l;s+=3)for(u=s+1<l?e[s+1>>>2]:0,c=s+2<l?e[s+2>>>2]:0,a=(e[s>>>2]>>>8*(f+n*(s%4))&255)<<16|(u>>>8*(f+n*((s+1)%4))&255)<<8|c>>>8*(f+n*((s+2)%4))&255,o=0;o<4;o+=1)h+=8*s+6*o<=t?r.charAt(a>>>6*(3-o)&63):i.b64Pad;return h}(e,t,n,i)};case"BYTES":return function(e){return function(e,t,n){let r,i,s="";const o=t/8,a=-1===n?3:0;for(r=0;r<o;r+=1)i=e[r>>>2]>>>8*(a+n*(r%4))&255,s+=String.fromCharCode(i);return s}(e,t,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,s=new ArrayBuffer(i),o=new Uint8Array(s),a=-1===n?3:0;for(r=0;r<i;r+=1)o[r]=e[r>>>2]>>>8*(a+n*(r%4))&255;return s}(e,t,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,s=-1===n?3:0,o=new Uint8Array(i);for(r=0;r<i;r+=1)o[r]=e[r>>>2]>>>8*(s+n*(r%4))&255;return o}(e,t,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function a(e){const t={outputUpper:!1,b64Pad:"=",outputLen:-1},n=e||{},r="Output length must be a multiple of 8";if(t.outputUpper=n.outputUpper||!1,n.b64Pad&&(t.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);t.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);t.outputLen=n.shakeLen}if("boolean"!=typeof t.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof t.b64Pad)throw new Error("Invalid b64Pad formatting option");return t}function u(e,t){return e<<t|e>>>32-t}function c(e,t,n){return e^t^n}function h(e,t,n){return e&t^e&n^t&n}function l(e,t){const n=(65535&e)+(65535&t);return(65535&(e>>>16)+(t>>>16)+(n>>>16))<<16|65535&n}function f(e,t,n,r,i){const s=(65535&e)+(65535&t)+(65535&n)+(65535&r)+(65535&i);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16)+(s>>>16))<<16|65535&s}function p(e){return[1732584193,4023233417,2562383102,271733878,3285377520]}function d(e,t){let n,r,i,s,o,a,p;const d=[];for(n=t[0],r=t[1],i=t[2],s=t[3],o=t[4],p=0;p<80;p+=1)d[p]=p<16?e[p]:u(d[p-3]^d[p-8]^d[p-14]^d[p-16],1),a=p<20?f(u(n,5),(g=r)&i^~g&s,o,1518500249,d[p]):p<40?f(u(n,5),c(r,i,s),o,1859775393,d[p]):p<60?f(u(n,5),h(r,i,s),o,2400959708,d[p]):f(u(n,5),c(r,i,s),o,3395469782,d[p]),o=s,s=i,i=u(r,30),r=n,n=a;var g;return t[0]=l(n,t[0]),t[1]=l(r,t[1]),t[2]=l(i,t[2]),t[3]=l(s,t[3]),t[4]=l(o,t[4]),t}function g(e,t,n,r){let i;const s=15+(t+65>>>9<<4),o=t+n;for(;e.length<=s;)e.push(0);for(e[t>>>5]|=128<<24-t%32,e[s]=4294967295&o,e[s-1]=o/4294967296|0,i=0;i<e.length;i+=16)r=d(e.slice(i,i+16),r);return r}class w extends class{constructor(e,t,n){const r=n||{};if(this.t=t,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=e,this.h=[],this.u=0,this.l=!1,this.A=0,this.p=!1,this.R=[],this.U=[]}update(e){let t,n=0;const r=this.T>>>5,i=this.F(e,this.h,this.u),s=i.binLen,o=i.value,a=s>>>5;for(t=0;t<a;t+=r)n+this.T<=s&&(this.m=this.g(o.slice(t,t+r),this.m),n+=this.T);return this.A+=n,this.h=o.slice(n>>>5),this.u=s%this.T,this.l=!0,this}getHash(e,t){let n,r,i=this.B;const s=a(t);if(this.v){if(-1===s.outputLen)throw new Error("Output length must be specified in options");i=s.outputLen}const u=o(e,i,this.Y,s);if(this.p&&this.H)return u(this.H(s));for(r=this.C(this.h.slice(),this.u,this.A,this.I(this.m),i),n=1;n<this.numRounds;n+=1)this.v&&i%32!=0&&(r[r.length-1]&=16777215>>>24-i%32),r=this.C(r,i,0,this.L(this.o),i);return u(r)}setHMACKey(e,t,n){if(!this.M)throw new Error("Variant does not support HMAC");if(this.l)throw new Error("Cannot set MAC key after calling update");const r=s(t,(n||{}).encoding||"UTF8",this.Y);this.N(r(e))}N(e){const t=this.T>>>3,n=t/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(t<e.binLen/8&&(e.value=this.C(e.value,e.binLen,0,this.L(this.o),this.B));e.value.length<=n;)e.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^e.value[r],this.U[r]=1549556828^e.value[r];this.m=this.g(this.R,this.m),this.A=this.T,this.p=!0}getHMAC(e,t){const n=a(t);return o(e,this.B,this.Y,n)(this.S())}S(){let e;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const t=this.C(this.h.slice(),this.u,this.A,this.I(this.m),this.B);return e=this.g(this.U,this.L(this.o)),e=this.C(t,this.B,this.T,e,this.B),e}}{constructor(e,t,n){if("SHA-1"!==e)throw new Error("Chosen SHA variant is not supported");super(e,t,n);const r=n||{};this.M=!0,this.H=this.S,this.Y=-1,this.F=s(this.t,this.i,this.Y),this.g=d,this.I=function(e){return e.slice()},this.L=p,this.C=g,this.m=[1732584193,4023233417,2562383102,271733878,3285377520],this.T=512,this.B=160,this.v=!1,r.hmacKey&&this.N(function(e,t,n,r){const i="hmacKey must include a value and format";if(!t)throw new Error(i);if(void 0===t.value||!t.format)throw new Error(i);return s(t.format,t.encoding||"UTF8",n)(t.value)}(0,r.hmacKey,this.Y))}}},673:(e,t,n)=>{n.r(t),n.d(t,{default:()=>k});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(e,t,n,r){let i,s,o;const a=t||[0],u=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<e.length;i+=1)o=i+u,s=o>>>2,a.length<=s&&a.push(0),a[s]|=e[i]<<8*(c+r*(o%4));return{value:a,binLen:8*e.length+n}}function s(e,t,n){switch(t){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(e,t,r){return function(e,t,n,r){let i,s,o,a;if(0!=e.length%2)throw new Error("String of HEX type must be in byte increments");const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(i=0;i<e.length;i+=2){if(s=parseInt(e.substr(i,2),16),isNaN(s))throw new Error("String of HEX type contains invalid characters");for(a=(i>>>1)+c,o=a>>>2;u.length<=o;)u.push(0);u[o]|=s<<8*(h+r*(a%4))}return{value:u,binLen:4*e.length+n}}(e,t,r,n)};case"TEXT":return function(e,r,i){return function(e,t,n,r,i){let s,o,a,u,c,h,l,f,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===t)for(l=-1===i?3:0,a=0;a<e.length;a+=1)for(s=e.charCodeAt(a),o=[],128>s?o.push(s):2048>s?(o.push(192|s>>>6),o.push(128|63&s)):55296>s||57344<=s?o.push(224|s>>>12,128|s>>>6&63,128|63&s):(a+=1,s=65536+((1023&s)<<10|1023&e.charCodeAt(a)),o.push(240|s>>>18,128|s>>>12&63,128|s>>>6&63,128|63&s)),u=0;u<o.length;u+=1){for(h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=o[u]<<8*(l+i*(h%4)),p+=1}else for(l=-1===i?2:0,f="UTF16LE"===t&&1!==i||"UTF16LE"!==t&&1===i,a=0;a<e.length;a+=1){for(s=e.charCodeAt(a),!0===f&&(u=255&s,s=u<<8|s>>>8),h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=s<<8*(l+i*(h%4)),p+=2}return{value:d,binLen:8*p+r}}(e,t,r,i,n)};case"B64":return function(e,t,i){return function(e,t,n,i){let s,o,a,u,c,h,l,f=0;const p=t||[0],d=(n=n||0)>>>3,g=-1===i?3:0,w=e.indexOf("=");if(-1===e.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(e=e.replace(/=/g,""),-1!==w&&w<e.length)throw new Error("Invalid '=' found in base-64 string");for(o=0;o<e.length;o+=4){for(c=e.substr(o,4),u=0,a=0;a<c.length;a+=1)s=r.indexOf(c.charAt(a)),u|=s<<18-6*a;for(a=0;a<c.length-1;a+=1){for(l=f+d,h=l>>>2;p.length<=h;)p.push(0);p[h]|=(u>>>16-8*a&255)<<8*(g+i*(l%4)),f+=1}}return{value:p,binLen:8*f+n}}(e,t,i,n)};case"BYTES":return function(e,t,r){return function(e,t,n,r){let i,s,o,a;const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(s=0;s<e.length;s+=1)i=e.charCodeAt(s),a=s+c,o=a>>>2,u.length<=o&&u.push(0),u[o]|=i<<8*(h+r*(a%4));return{value:u,binLen:8*e.length+n}}(e,t,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e,t,r){return function(e,t,n,r){return i(new Uint8Array(e),t,n,r)}(e,t,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e,t,r){return i(e,t,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function o(e,t,n,i){switch(e){case"HEX":return function(e){return function(e,t,n,r){const i="0123456789abcdef";let s,o,a="";const u=t/8,c=-1===n?3:0;for(s=0;s<u;s+=1)o=e[s>>>2]>>>8*(c+n*(s%4)),a+=i.charAt(o>>>4&15)+i.charAt(15&o);return r.outputUpper?a.toUpperCase():a}(e,t,n,i)};case"B64":return function(e){return function(e,t,n,i){let s,o,a,u,c,h="";const l=t/8,f=-1===n?3:0;for(s=0;s<l;s+=3)for(u=s+1<l?e[s+1>>>2]:0,c=s+2<l?e[s+2>>>2]:0,a=(e[s>>>2]>>>8*(f+n*(s%4))&255)<<16|(u>>>8*(f+n*((s+1)%4))&255)<<8|c>>>8*(f+n*((s+2)%4))&255,o=0;o<4;o+=1)h+=8*s+6*o<=t?r.charAt(a>>>6*(3-o)&63):i.b64Pad;return h}(e,t,n,i)};case"BYTES":return function(e){return function(e,t,n){let r,i,s="";const o=t/8,a=-1===n?3:0;for(r=0;r<o;r+=1)i=e[r>>>2]>>>8*(a+n*(r%4))&255,s+=String.fromCharCode(i);return s}(e,t,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,s=new ArrayBuffer(i),o=new Uint8Array(s),a=-1===n?3:0;for(r=0;r<i;r+=1)o[r]=e[r>>>2]>>>8*(a+n*(r%4))&255;return s}(e,t,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,s=-1===n?3:0,o=new Uint8Array(i);for(r=0;r<i;r+=1)o[r]=e[r>>>2]>>>8*(s+n*(r%4))&255;return o}(e,t,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}const a=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],u=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428],c=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];function h(e){const t={outputUpper:!1,b64Pad:"=",outputLen:-1},n=e||{},r="Output length must be a multiple of 8";if(t.outputUpper=n.outputUpper||!1,n.b64Pad&&(t.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);t.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);t.outputLen=n.shakeLen}if("boolean"!=typeof t.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof t.b64Pad)throw new Error("Invalid b64Pad formatting option");return t}function l(e,t){return e>>>t|e<<32-t}function f(e,t){return e>>>t}function p(e,t,n){return e&t^~e&n}function d(e,t,n){return e&t^e&n^t&n}function g(e){return l(e,2)^l(e,13)^l(e,22)}function w(e,t){const n=(65535&e)+(65535&t);return(65535&(e>>>16)+(t>>>16)+(n>>>16))<<16|65535&n}function y(e,t,n,r){const i=(65535&e)+(65535&t)+(65535&n)+(65535&r);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16))<<16|65535&i}function m(e,t,n,r,i){const s=(65535&e)+(65535&t)+(65535&n)+(65535&r)+(65535&i);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16)+(s>>>16))<<16|65535&s}function b(e){return l(e,7)^l(e,18)^f(e,3)}function v(e){return l(e,6)^l(e,11)^l(e,25)}function L(e){let t;return t="SHA-224"==e?u.slice():c.slice(),t}function A(e,t){let n,r,i,s,o,u,c,h,L,A,k;const E=[];for(n=t[0],r=t[1],i=t[2],s=t[3],o=t[4],u=t[5],c=t[6],h=t[7],k=0;k<64;k+=1)E[k]=k<16?e[k]:y(l(R=E[k-2],17)^l(R,19)^f(R,10),E[k-7],b(E[k-15]),E[k-16]),L=m(h,v(o),p(o,u,c),a[k],E[k]),A=w(g(n),d(n,r,i)),h=c,c=u,u=o,o=w(s,L),s=i,i=r,r=n,n=w(L,A);var R;return t[0]=w(n,t[0]),t[1]=w(r,t[1]),t[2]=w(i,t[2]),t[3]=w(s,t[3]),t[4]=w(o,t[4]),t[5]=w(u,t[5]),t[6]=w(c,t[6]),t[7]=w(h,t[7]),t}class k extends class{constructor(e,t,n){const r=n||{};if(this.t=t,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=e,this.h=[],this.u=0,this.A=!1,this.l=0,this.p=!1,this.R=[],this.U=[]}update(e){let t,n=0;const r=this.T>>>5,i=this.F(e,this.h,this.u),s=i.binLen,o=i.value,a=s>>>5;for(t=0;t<a;t+=r)n+this.T<=s&&(this.m=this.g(o.slice(t,t+r),this.m),n+=this.T);return this.l+=n,this.h=o.slice(n>>>5),this.u=s%this.T,this.A=!0,this}getHash(e,t){let n,r,i=this.B;const s=h(t);if(this.H){if(-1===s.outputLen)throw new Error("Output length must be specified in options");i=s.outputLen}const a=o(e,i,this.v,s);if(this.p&&this.Y)return a(this.Y(s));for(r=this.C(this.h.slice(),this.u,this.l,this.S(this.m),i),n=1;n<this.numRounds;n+=1)this.H&&i%32!=0&&(r[r.length-1]&=16777215>>>24-i%32),r=this.C(r,i,0,this.I(this.o),i);return a(r)}setHMACKey(e,t,n){if(!this.L)throw new Error("Variant does not support HMAC");if(this.A)throw new Error("Cannot set MAC key after calling update");const r=s(t,(n||{}).encoding||"UTF8",this.v);this.M(r(e))}M(e){const t=this.T>>>3,n=t/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(t<e.binLen/8&&(e.value=this.C(e.value,e.binLen,0,this.I(this.o),this.B));e.value.length<=n;)e.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^e.value[r],this.U[r]=1549556828^e.value[r];this.m=this.g(this.R,this.m),this.l=this.T,this.p=!0}getHMAC(e,t){const n=h(t);return o(e,this.B,this.v,n)(this.N())}N(){let e;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const t=this.C(this.h.slice(),this.u,this.l,this.S(this.m),this.B);return e=this.g(this.U,this.I(this.o)),e=this.C(t,this.B,this.T,e,this.B),e}}{constructor(e,t,n){if("SHA-224"!==e&&"SHA-256"!==e)throw new Error("Chosen SHA variant is not supported");super(e,t,n);const r=n||{};this.Y=this.N,this.L=!0,this.v=-1,this.F=s(this.t,this.i,this.v),this.g=A,this.S=function(e){return e.slice()},this.I=L,this.C=function(t,n,r,i){return function(e,t,n,r,i){let s,o;const a=15+(t+65>>>9<<4),u=t+n;for(;e.length<=a;)e.push(0);for(e[t>>>5]|=128<<24-t%32,e[a]=4294967295&u,e[a-1]=u/4294967296|0,s=0;s<e.length;s+=16)r=A(e.slice(s,s+16),r);return o="SHA-224"===i?[r[0],r[1],r[2],r[3],r[4],r[5],r[6]]:r,o}(t,n,r,i,e)},this.m=L(e),this.T=512,this.B="SHA-224"===e?224:256,this.H=!1,r.hmacKey&&this.M(function(e,t,n,r){const i="hmacKey must include a value and format";if(!t)throw new Error(i);if(void 0===t.value||!t.format)throw new Error(i);return s(t.format,t.encoding||"UTF8",n)(t.value)}(0,r.hmacKey,this.v))}}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};(()=>{n.d(r,{j$:()=>g,nm:()=>l,Xz:()=>s,ul:()=>a,zo:()=>c,zM:()=>t,pI:()=>p,I4:()=>d,Fl:()=>h,In:()=>i,Cj:()=>o,t6:()=>u,mh:()=>e,LQ:()=>f,R2:()=>z,rJ:()=>q,xI:()=>Le,$$:()=>ve,e9:()=>X,K2:()=>j,ZC:()=>J,iv:()=>B,d2:()=>F,vB:()=>be,y1:()=>me,Hv:()=>b,Ue:()=>Ue,Jx:()=>x,cv:()=>E,Pi:()=>ne,um:()=>re,sK:()=>y,Fw:()=>w,zE:()=>W,RU:()=>Z,Xs:()=>G,r1:()=>Q,Kl:()=>ee,A7:()=>ye,px:()=>ge,ZW:()=>we,ti:()=>de,bX:()=>m,Dc:()=>L,fp:()=>v,Ye:()=>fe,Qc:()=>C,hP:()=>le,LU:()=>he,yQ:()=>S,Zk:()=>T,uh:()=>U});const e=108,t=new Uint8Array([e]),i=100,s=new Uint8Array([i]),o=101,a=new Uint8Array([o]),u=105,c=new Uint8Array([u]),h=58,l=new Uint8Array([h]),f=45,p=new Uint8Array([f]),d=48,g=new Uint8Array([d]);function w(e){return e>=d&&e<=d+9}function y(e,t,n){let r=0,i=e.length;for(;r<i;){const s=r+i>>>1,o=n(e[s],t);if(0===o)return{index:s,result:e[s]};o<0?r=s+1:i=s}return{index:r,result:void 0}}function m(e,t){const n=[];for(const r of e){const{index:e}=y(n,r,t);n.splice(e,0,r)}return n}function b(...e){const t=new Uint8Array(e.reduce(((e,t)=>e+t.byteLength),0));return e.reduce(((e,n)=>(t.set(n,e),e+n.byteLength)),0),t}function v(e){return 1<<32-Math.clz32(e-1)}async function L(e){if(0===e.length)throw new Error("Empty leaves");const t=new Uint8Array(64);for(;e.length>1;){let r=!1;const i=[];for(const s of e)if(r){let e;t.set(s,32);try{e=new Uint8Array(await crypto.subtle.digest("SHA-256",t))}catch{const{default:r}=await Promise.resolve().then(n.bind(n,673)),i=new r("SHA-256","UINT8ARRAY");i.update(t),e=i.getHash("UINT8ARRAY")}i.push(e),r=!1}else t.set(s),r=!0;e=i}return e[0]}const A=new WeakMap;class k{textEncoder=new TextEncoder;textDecoder=new TextDecoder;data;path=[];hooks;consumedHookHandler=new WeakMap;constructor(e,t){this.data=e,this.hooks=t,t&&A.set(t,!0)}start(e){if(this.encode(this.data,e),this.hooks)for(const e of this.hooks.values())this.consumedHookHandler.get(e)||e({value:void 0,done:!0});e.close()}encode(e,n){if(null!=e)if("boolean"==typeof e)this.encode(e?1:0,n);else if("number"==typeof e){const t=Math.round(e);n.enqueue(this.textEncoder.encode(`i${t}e`)),t!==e&&(console.warn(`WARNING: Possible data corruption detected with value "${e}":`,`Bencoding only defines support for integers, value was converted to "${t}"`),console.trace())}else if("bigint"==typeof e)n.enqueue(this.textEncoder.encode(`i${e}e`));else if("string"==typeof e){const t=this.textEncoder.encode(e),r=t.byteLength;n.enqueue(this.textEncoder.encode(`${r}:`)),n.enqueue(t)}else if(e instanceof ArrayBuffer){const t=new Uint8Array(e),r=t.byteLength;n.enqueue(this.textEncoder.encode(`${r}:`)),n.enqueue(t)}else if(Array.isArray(e)){n.enqueue(t);let r=0;for(const t of e){if(this.path.push(r),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0})}else this.encode(t,n)}this.path.pop(),++r}n.enqueue(a)}else if(e instanceof Map){n.enqueue(s);const t=m(e.keys(),((e,t)=>(e="string"==typeof e?e:this.textDecoder.decode(e))<(t="string"==typeof t?t:this.textDecoder.decode(t))?-1:e>t?1:0));for(const r of t){const t=e.get(r);if(void 0!==t&&null!==e)if(r instanceof ArrayBuffer)this.encode(r,n),this.encode(t,n);else{if(this.path.push(r),this.encode(r,n),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0}),this.consumedHookHandler.set(e,!0)}else this.encode(t,n)}this.path.pop()}}n.enqueue(a)}else{n.enqueue(s);const t=Object.keys(e).sort();for(const r of t){const t=e[r];if(void 0!==t&&null!==e){if(this.path.push(r),this.encode(r,n),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0}),this.consumedHookHandler.set(e,!0)}else this.encode(t,n)}this.path.pop()}}n.enqueue(a)}}}function E(e,t){return new ReadableStream(new k(e,t))}function R(e,t){return new Proxy(e,{get:function(e,n,r){return"enqueue"===n?(n=>{e.enqueue(n),t({value:n,done:!1})}).bind(e):Reflect.get(e,n,r)}})}function U(e,t){const n={controller:null},r=new ReadableStream({start(e){n.controller=e},pull(e){A.get(t)||(console.warn("You need to call encode() first and then consume hooks."),e.close(),n.controller=null)}});return t.set(e,(({value:e,done:t})=>{null!==n.controller&&(t?n.controller.close():n.controller.enqueue(e))})),[r]}function S(e,t){const[n]=U(e,t);return[new Response(n).arrayBuffer()]}function T(e,t){const[n]=U(e,t);return[new Response(n).text()]}var B;!function(e){e.Integer="Integer",e.ByteString="ByteString",e.ListStart="ListStart",e.ListEnd="ListEnd",e.DictionaryStart="DictionaryStart",e.DictionaryEnd="DictionaryEnd"}(B||(B={}));class P{endStack=[];token=null;byteStringLength=-1;byteStringOffset=0;transform(e,t){this.tokenize(e,t)}flush(){if(this.endStack.length||this.token||-1!==this.byteStringLength||this.byteStringOffset)throw new SyntaxError("Unexpected end of torrent stream")}tokenize(t,n){if(0!==t.byteLength)if(null===this.token&&-1===this.byteStringLength){const r=t[0];if(r===u)this.token={type:B.Integer,value:new Uint8Array};else if(w(r))this.byteStringLength=r-d;else if(r===e)this.endStack.push(B.ListEnd),n.enqueue({type:B.ListStart});else if(r===i)this.endStack.push(B.DictionaryEnd),n.enqueue({type:B.DictionaryStart});else{if(r!==o)throw new SyntaxError(`Unexpected byte: ${r}`);{const e=this.endStack.pop();if(!e)throw new SyntaxError("Unbalanced delimiter");n.enqueue({type:e})}}this.tokenize(t.subarray(1),n)}else if(this.token&&-1===this.byteStringLength)if(this.token.type===B.Integer){const e=t.indexOf(o);-1===e?this.token.value=this.token.value?b(this.token.value,t):t:(this.token.value=this.token.value?b(this.token.value,t.subarray(0,e)):t.subarray(0,e),n.enqueue(this.token),this.token=null,this.tokenize(t.subarray(e+1),n))}else{if(this.token.type!==B.ByteString)throw new Error("This is a bug");{const e=this.token.value.byteLength-this.byteStringOffset,r=t.byteLength;r<e?(this.token.value.set(t,this.byteStringOffset),this.byteStringOffset+=r):(this.token.value.set(t.subarray(0,e),this.byteStringOffset),this.byteStringOffset=0,n.enqueue(this.token),this.token=null,this.tokenize(t.subarray(e),n))}}else{if(!(this.byteStringLength>-1&&null===this.token))throw new Error("This is a bug");{let e=-1;for(const[n,r]of t.entries()){if(!w(r)){if(r===h){e=n;break}throw new SyntaxError(`Unexpected byte: ${r}`)}this.byteStringLength=10*this.byteStringLength-d+r}-1!==e&&(this.token={type:B.ByteString,value:new Uint8Array(this.byteStringLength)},this.byteStringLength=-1,this.tokenize(t.subarray(e+1),n))}}}}class F extends TransformStream{constructor(){super(new P)}}async function C(e){let t;const n=[],r=e.getReader();let i;for(;;){const{done:e,value:s}=await r.read();if(e)break;const o=n.at(-1);if(o)if(Array.isArray(o))switch(s.type){case B.Integer:o.push(I(s.value));break;case B.ByteString:o.push(H(s.value));break;case B.DictionaryStart:{const e=Object.create(null);o.push(e),n.push(e);break}case B.ListStart:{const e=[];o.push(e),n.push(e);break}case B.ListEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`)}else if(void 0===i)switch(s.type){case B.ByteString:i=H(s.value);break;case B.DictionaryEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`)}else{switch(s.type){case B.Integer:o[i]=I(s.value);break;case B.ByteString:o[i]=H(s.value);break;case B.DictionaryStart:{const e=Object.create(null);o[i]=e,n.push(e);break}case B.ListStart:{const e=[];o[i]=e,n.push(e);break}default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`)}i=void 0}else{if(void 0!==t)throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`);switch(s.type){case B.Integer:t=I(s.value);break;case B.ByteString:t=H(s.value);break;case B.DictionaryStart:{const e=Object.create(null);n.push(e),t=e;break}case B.ListStart:{const e=[];n.push(e),t=e;break}default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`)}}}if(n.length)throw new Error("Unexpected end of token stream");return t}async function x(e){const t=new F,n=e.pipeThrough(t);return await C(n)}function I(e){let t=0,n=!0;for(const[r,i]of e.entries()){if(0===r&&i===f){n=!1;continue}if(1===r&&!n&&i===d)throw new SyntaxError("Negative zero is not a valid integer");if(1===r&&0===t)throw new SyntaxError("Leading zeros are not allowed");if(!w(i))throw new SyntaxError(`Unexpected byte: ${i}`);const e=i-d;(n&&"number"==typeof t&&t>(Number.MAX_SAFE_INTEGER-e)/10||!n&&"number"==typeof t&&t<(Number.MIN_SAFE_INTEGER+e)/10)&&(t=BigInt(t)),t="number"==typeof t?n?10*t+e:10*t-e:n?10n*t+BigInt(e):10n*t-BigInt(e)}return t}function H(e){return(new TextDecoder).decode(e)}n(913);class N extends Error{constructor(e,t){super(((e,...t)=>{let n=e;return t.length>0&&(n+=` :: ${JSON.stringify(t)}`),n})(e,t)),this.name=e,this.details=t}}class M{constructor(){this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t}))}}function Y(e){const t=e.map((e=>Promise.resolve(e).then((e=>function(e){if(e instanceof Response){if(e.body)return e.body.getReader();throw new N("opaque-streams-source",{type:e.type})}return e instanceof ReadableStream?e.getReader():new Response(e).body.getReader()}(e))))),n=new M;let r=0;const i=new ReadableStream({pull(e){return t[r].then((e=>e.read())).then((i=>{if(i.done)return r++,r>=t.length?(e.close(),void n.resolve()):this.pull(e);e.enqueue(i.value)})).catch((e=>{throw n.reject(e),e}))},cancel(){n.resolve()}});return{done:n.promise,stream:i}}n(1);const D=new Uint8Array(32);class O{blockCount=0;merkleLeaves=[];blocksPerPiece;constructor(e){this.blocksPerPiece=e}async transform(e,t){let r;++this.blockCount;try{r=new Uint8Array(await crypto.subtle.digest("SHA-256",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,673)),i=new t("SHA-256","UINT8ARRAY");i.update(e),r=i.getHash("UINT8ARRAY")}this.merkleLeaves.push(r),this.merkleLeaves.length===this.blocksPerPiece&&(t.enqueue(this.merkleLeaves),this.merkleLeaves=[])}flush(e){if(0===this.blockCount)return;let t=0;if(this.blockCount<this.blocksPerPiece)t=v(this.blockCount)-this.blockCount;else{const e=this.blockCount%this.blocksPerPiece;e>0&&(t=this.blocksPerPiece-e)}if(t>0)for(let e=0;e<t;++e)this.merkleLeaves.push(D);this.merkleLeaves.length>0&&e.enqueue(this.merkleLeaves)}}class z extends TransformStream{constructor(e){super(new O(e))}}class ${residuePointer=0;chunkLength;residue;opts;constructor(e,t={padding:!1}){this.chunkLength=e,this.opts=t,this.residue=new Uint8Array(this.chunkLength)}transform(e,t){for(;this.residuePointer+e.byteLength>=this.chunkLength;){const n=this.chunkLength-this.residuePointer;this.residue.set(e.subarray(0,n),this.residuePointer),this.residuePointer=0,t.enqueue(new Uint8Array(this.residue)),e=e.subarray(n)}this.residue.set(e,this.residuePointer),this.residuePointer+=e.byteLength}flush(e){this.residuePointer<=0||(this.opts.padding?(this.residue.set(new Uint8Array(this.chunkLength-this.residuePointer),this.residuePointer),e.enqueue(this.residue)):e.enqueue(this.residue.subarray(0,this.residuePointer)))}}class q extends TransformStream{constructor(e,t={padding:!1}){super(new $(e,t))}}class K{updateProgress;constructor(e){this.updateProgress=e}async transform(e,t){t.enqueue(await L(e)),this.updateProgress&&await this.updateProgress()}}class X extends TransformStream{constructor(e){super(new K(e))}}class _{leafCount=0;merkleLeaves=[];blocksPerPiece;constructor(e){this.blocksPerPiece=e}transform(e){++this.leafCount,this.merkleLeaves.push(e)}async flush(e){const t=v(this.leafCount)-this.leafCount;if(t>0){const e=await this.padLeafPromise;for(let n=0;n<t;++n)this.merkleLeaves.push(e)}e.enqueue(this.merkleLeaves)}get padLeafPromise(){return L(Array(this.blocksPerPiece).fill(new Uint8Array(32)))}}class j extends TransformStream{constructor(e){super(new _(e))}}class V{updateProgress;constructor(e){this.updateProgress=e}async transform(e,t){let r;try{r=new Uint8Array(await crypto.subtle.digest("SHA-1",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,211)),i=new t("SHA-1","UINT8ARRAY");i.update(e),r=i.getHash("UINT8ARRAY")}t.enqueue(r),this.updateProgress&&await this.updateProgress()}}class J extends TransformStream{constructor(e){super(new V(e))}}function W(e){return e instanceof File}function Z(e){return!G(e)&&!W(e)&&e.isDirectory}function Q(e){return!G(e)&&!W(e)&&e.isFile}function G(e){try{if(e instanceof FileSystemHandle&&"directory"===e.kind)return!0}catch(e){}return!1}function ee(e){try{if(e instanceof FileSystemHandle&&"file"===e.kind)return!0}catch(e){}return!1}function te(e){return new Promise(((t,n)=>{e.readEntries(t,n)}))}async function*ne(e){const t=e.createReader();let n=[];do{n=await te(t);for(const e of n)yield e}while(n.length>0)}function re(e){return new Promise(((t,n)=>{e.file(t,n)}))}const ie={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let se;const oe=new Uint8Array(16);function ae(){if(!se&&(se="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!se))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return se(oe)}const ue=[];for(let e=0;e<256;++e)ue.push((e+256).toString(16).slice(1));const ce=function(e,t,n){if(ie.randomUUID&&!t&&!e)return ie.randomUUID();const r=(e=e||{}).random||(e.rng||ae)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return(ue[e[t+0]]+ue[e[t+1]]+ue[e[t+2]]+ue[e[t+3]]+"-"+ue[e[t+4]]+ue[e[t+5]]+"-"+ue[e[t+6]]+ue[e[t+7]]+"-"+ue[e[t+8]]+ue[e[t+9]]+"-"+ue[e[t+10]]+ue[e[t+11]]+ue[e[t+12]]+ue[e[t+13]]+ue[e[t+14]]+ue[e[t+15]]).toLowerCase()}(r)};function he(e,t){if(t.size>1||0===t.size)return{name:e??ce(),commonDir:void 0};const[n,r]=t.entries().next().value;return de(r)?{name:n,commonDir:void 0}:{name:e??n,commonDir:n}}async function le(e,{sort:t=!0,compareFunction:n=me,polyfillWebkitRelativePath:r=!0}={sort:!0,compareFunction:me,polyfillWebkitRelativePath:!0}){let i=0,s=0;const o=new WeakMap,a=new WeakMap,u=new WeakMap,c=["file tree",[]],h=[c];let l=!1;for await(const t of e)await f(t);return{fileTree:fe(c[1],l),traverseTree:function*e(t){if(ge(t))for(const n of t.values())yield*e(n);else yield[t,u.get(t)]},totalFileSize:i,totalFileCount:s};async function f(e){const p=h.at(-1);if(!p)throw new Error("This is a bug");const d=W(e),g=G(e),w=Z(e),m=ee(e),b=Q(e);if(g||w){const r=e.name,{index:i,result:s}=y(p[1],r,n);let o=s;if(we(o))throw new Error("A same name file already exists");if(ye(o)&&g){const t=a.get(o);if(!t||!await e.isSameEntry(t))throw new Error("File system handle not match")}o||(o=[r,[]],t?p[1].splice(i,0,o):p[1].push(o),g&&a.set(o,e)),h.push(o);for await(const t of g?e.values():ne(e))await f(t);o[1]=new Map(o[1]),h.pop()}else if(m||b){const a=e.name,{index:c,result:l}=y(p[1],a,n);let f=l;if(we(f)&&m){const t=o.get(f);if(!t||!await e.isSameEntry(t))throw new Error("A same name file already exists")}if(ye(f))throw new Error("A same name directory already exists");if(f)return;const d=await(m?e.getFile():re(e)),g=d.size;if(r){const e=h.reduce(((e,t,n)=>0===n?e:e+t[0]+"/"),"")+d.name;Object.defineProperty(d,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>e})}const w={"":{length:g}};f=[a,w],t?p[1].splice(c,0,f):p[1].push(f),m&&o.set(f,e),u.set(w,d),i+=g,s+=1}else{if(!d)throw new Error("Unrecognized type of input");{r&&""===e.webkitRelativePath&&Object.defineProperty(e,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>e.name});const o=(e.webkitRelativePath||e.name).split("/"),a=[c];for(const[r,c]of o.entries()){r>=1&&(l=!0);const h=a.at(-1);if(!h)throw new Error("This is a bug");const{index:f,result:p}=y(h[1],c,n);if(r<o.length-1){let e=p;if(we(e))throw new Error("A same name file already exists");e||(e=[c,[]],t?h[1].splice(f,0,e):h[1].push(e)),a.push(e)}else{let n=p;if(ye(n))throw new Error("A same name directory already exists");if(n)return;const r=e.size,o={"":{length:r}};n=[c,o],t?h[1].splice(f,0,n):h[1].push(n),u.set(o,e),i+=r,s+=1}}}}}}function fe(e,t=!1){return t&&pe(e),new Map(e)}function pe(e){for(const t of e)if(ye(t)){const e=t[1];pe(e),t[1]=new Map(e)}}function de(e){return!!e&&""in e}function ge(e){return e instanceof Map}function we(e){return!!e&&""in e[1]}function ye(e){return!!e&&!(""in e[1])}function me(e,t){return e[0]<t?-1:e[0]>t?1:0}var be;!function(e){e.V1="v1",e.V2="v2",e.HYBRID="hybrid"}(be||(be={}));const ve=16384;var Le;!function(e){e[e["16KB"]=16384]="16KB",e[e["32KB"]=32768]="32KB",e[e["64KB"]=65536]="64KB",e[e["128KB"]=131072]="128KB",e[e["256KB"]=262144]="256KB",e[e["512KB"]=524288]="512KB",e[e["1MB"]=1048576]="1MB",e[e["2MB"]=2097152]="2MB",e[e["4MB"]=4194304]="4MB",e[e["8MB"]=8388608]="8MB",e[e["16MB"]=16777216]="16MB",e[e["32MB"]=33554432]="32MB"}(Le||(Le={}));const Ae={type:be.V1,addCreatedBy:!0,addCreationDate:!0,addPaddingFiles:!1,blockLength:ve,pieceLength:NaN,sortFiles:!0,isPrivate:!1},ke={type:be.V2,addCreatedBy:!0,addCreationDate:!0,blockLength:ve,pieceLength:NaN,metaVersion:2,isPrivate:!1},Ee={type:be.HYBRID,addCreatedBy:!0,addCreationDate:!0,blockLength:ve,pieceLength:NaN,metaVersion:2,isPrivate:!1};function Re(e,t){let n=0;for(const r of e)n+=Math.ceil(r.size/t);return n}async function Ue(e,t={type:be.V1},n){switch(t.type){case be.V1:return await async function(e,t,n){const r={...Ae,...t},{fileTree:i,traverseTree:s,totalFileCount:o,totalFileSize:a}=await le(e,{sort:r.sortFiles});if(0===o)return;const u=[];for(const[,e]of s(i))u.push(e);isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),0!=(r.pieceLength&r.pieceLength-1)&&console.warn(`piece length ${r.pieceLength} is not a power of 2`),r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const[c,h]=Pe(0,n),{commonDir:l,name:f}=he(r.name,i);let p;if(r.name=f,r.addPaddingFiles){const e=Re(u,r.pieceLength);await h(e);const t=[],n=o-1;for(let e=n;e>=0;--e){const i=u[e];if(t.unshift(Promise.resolve(Te(i.stream(),{pieceLength:r.pieceLength,padding:e!==n,updateProgress:c}))),e===n)continue;const s=i.size%r.pieceLength;if(0===s)continue;const o=Be(r.pieceLength-s,l);u.splice(e+1,0,o)}p=Y(t).stream}else{const e=Math.ceil(a/r.pieceLength);await h(e);const{stream:t}=Y(u.map((e=>Promise.resolve(e.stream()))));p=Te(t,{pieceLength:r.pieceLength,padding:!1,updateProgress:c})}return{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.5"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{...o>1?{files:u.map((e=>{const t=(e.webkitRelativePath||e.name).split("/");return void 0!==l&&t.shift(),{...e.padding?{attr:"p"}:{},length:e.size,path:t}}))}:{length:a},name:r.name,"piece length":r.pieceLength,pieces:await new Response(p).arrayBuffer(),...r.isPrivate?{private:!0}:{}}}}(e,t,n);case be.V2:return await async function(e,t,n){const r={...ke,...t},{fileTree:i,traverseTree:s,totalFileCount:o,totalFileSize:a}=await le(e);if(0===o)return;const u=[],c=[];for(const[e,t]of s(i))u.push(t),c.push([e,t]);if(isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),r.pieceLength<r.blockLength)throw new Error(`piece length ${r.pieceLength} is smaller than block length ${r.blockLength}`);if(0!=(r.pieceLength&r.pieceLength-1))throw new Error(`piece length ${r.pieceLength} is not a power of 2`);const h=r.pieceLength/r.blockLength;r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const l=Re(u,r.pieceLength),[f]=Pe(l,n),{name:p}=he(r.name,i);r.name=p;const d=new Map;return await Promise.all(c.map((async([e,t])=>{await Se(t.stream(),d,e,{blockLength:r.blockLength,pieceLength:r.pieceLength,blocksPerPiece:h,updateProgress:f})}))),{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.5"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{"file tree":i,"meta version":r.metaVersion,name:r.name,"piece length":r.pieceLength,...r.isPrivate?{private:!0}:{}},"piece layers":d}}(e,t,n);case be.HYBRID:return await async function(e,t,n){const r={...Ee,...t},{fileTree:i,traverseTree:s,totalFileCount:o,totalFileSize:a}=await le(e);if(0===o)return;const u=[],c=[];for(const[e,t]of s(i))u.push(t),c.push([e,t]);if(isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),r.pieceLength<r.blockLength)throw new Error(`piece length ${r.pieceLength} is smaller than block length ${r.blockLength}`);if(0!=(r.pieceLength&r.pieceLength-1))throw new Error(`piece length ${r.pieceLength} is not a power of 2`);const h=r.pieceLength/r.blockLength;r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const[l]=Pe(2*Re(u,r.pieceLength),n),{commonDir:f,name:p}=he(r.name,i);r.name=p;const d=new Map,g=[],w=o-1;let y=-1;for(const[e,t]of c){++y;const[n,i]=t.stream().tee();if(g.unshift(Promise.resolve(Te(n,{pieceLength:r.pieceLength,padding:y!==w,updateProgress:l}))),await Se(i,d,e,{blockLength:r.blockLength,pieceLength:r.pieceLength,blocksPerPiece:h,updateProgress:l}),y===w)break;const s=t.size%r.pieceLength;if(0===s)continue;const o=Be(r.pieceLength-s,f);u.splice(y+1,0,o)}const m=Y(g).stream;return{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.5"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{"file tree":i,...o>1?{files:u.map((e=>{const t=(e.webkitRelativePath||e.name).split("/");return void 0!==f&&t.shift(),{...e.padding?{attr:"p"}:{},length:e.size,path:t}}))}:{length:a},"meta version":r.metaVersion,name:r.name,"piece length":r.pieceLength,pieces:await new Response(m).arrayBuffer(),...r.isPrivate?{private:!0}:{}},"piece layers":d}}(e,t,n)}}async function Se(e,t,n,r){const{piecesRootReadableStream:i,pieceLayerReadableStream:s}=function(e,t){const n=e.pipeThrough(new q(t.blockLength)).pipeThrough(new z(t.blocksPerPiece)).pipeThrough(new X(t.updateProgress)),[r,i]=n.tee();return{piecesRootReadableStream:i.pipeThrough(new j(t.blocksPerPiece)).pipeThrough(new X),pieceLayerReadableStream:r}}(e,r),o=new Response(i).arrayBuffer();if(n[""].length>r.pieceLength){const e=new Response(s).arrayBuffer();t.set(await o,await e)}n[""].length>0&&(n[""]["pieces root"]=await o)}function Te(e,t){return e.pipeThrough(new q(t.pieceLength,{padding:t.padding})).pipeThrough(new J(t.updateProgress))}function Be(e,t){const n=new File([new ArrayBuffer(e)],`${e}`,{type:"application/octet-stream"}),r=`.pad/${e}`,i=void 0===t?r:`${t}/${r}`;return Object.defineProperties(n,{webkitRelativePath:{configurable:!0,enumerable:!0,get:()=>i},padding:{configurable:!0,enumerable:!1,get:()=>!0}}),n}function Pe(e,t){const n={current:0,total:e};return[async()=>{t&&await t(++n.current,n.total)},async e=>{n.total="number"==typeof e?e:await e(n.total,n.current)}]}function Fe(e){if(void 0===e)return;const t=[];for(const n of e)0!==n.length&&t.push(n);return 0!==t.length?t:void 0}function Ce(e,t){return Math.max(t,v(e>>>10))}})();var i=r.j$,s=r.nm,o=r.Xz,a=r.ul,u=r.zo,c=r.zM,h=r.pI,l=r.I4,f=r.Fl,p=r.In,d=r.Cj,g=r.t6,w=r.mh,y=r.LQ,m=r.R2,b=r.rJ,v=r.xI,L=r.$$,A=r.e9,k=r.K2,E=r.ZC,R=r.iv,U=r.d2,S=r.vB,T=r.y1,B=r.Hv,P=r.Ue,F=r.Jx,C=r.cv,x=r.Pi,I=r.um,H=r.sK,N=r.Fw,M=r.zE,Y=r.RU,D=r.Xs,O=r.r1,z=r.Kl,$=r.A7,q=r.px,K=r.ZW,X=r.ti,j=r.bX,V=r.Dc,J=r.fp,W=r.Ye,Z=r.Qc,Q=r.hP,G=r.LU,ee=r.yQ,te=r.Zk,ne=r.uh;export{i as BUFF_0,s as BUFF_COLON,o as BUFF_D,a as BUFF_E,u as BUFF_I,c as BUFF_L,h as BUFF_MINUS,l as BYTE_0,f as BYTE_COLON,p as BYTE_D,d as BYTE_E,g as BYTE_I,w as BYTE_L,y as BYTE_MINUS,m as BlockHasher,b as ChunkSplitter,v as CommonPieceLength,L as DEFAULT_BLOCK_LENGTH,A as MerkleRootCalculator,k as MerkleTreeBalancer,E as PieceHasher,R as TokenType,U as Tokenizer,S as TorrentType,T as compareEntryNames,B as concatUint8Arrays,P as create,F as decode,C as encode,x as getEntriesOfDirEntry,I as getFileOfFileEntry,H as getSortedIndex,N as isDigitByte,M as isFile,Y as isFileSystemDirectoryEntry,D as isFileSystemDirectoryHandle,O as isFileSystemFileEntry,z as isFileSystemFileHandle,$ as isFileTreeDirEntry,q as isFileTreeDirNode,K as isFileTreeFileEntry,X as isFileTreeFileNode,j as iterableSort,V as merkleRoot,J as nextPowerOfTwo,W as packEntriesToDirNode,Z as parse,Q as populateFileTree,G as resolveCommonDirAndTorrentName,ee as useArrayBufferPromiseHook,te as useTextPromiseHook,ne as useUint8ArrayStreamHook};
var e={913:()=>{try{self["workbox:core:6.5.3"]&&_()}catch(e){}},1:()=>{try{self["workbox:streams:6.5.3"]&&_()}catch(e){}},211:(e,t,n)=>{n.r(t),n.d(t,{default:()=>w});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(e,t,n,r){let i,s,o;const a=t||[0],u=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<e.length;i+=1)o=i+u,s=o>>>2,a.length<=s&&a.push(0),a[s]|=e[i]<<8*(c+r*(o%4));return{value:a,binLen:8*e.length+n}}function s(e,t,n){switch(t){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(e,t,r){return function(e,t,n,r){let i,s,o,a;if(0!=e.length%2)throw new Error("String of HEX type must be in byte increments");const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(i=0;i<e.length;i+=2){if(s=parseInt(e.substr(i,2),16),isNaN(s))throw new Error("String of HEX type contains invalid characters");for(a=(i>>>1)+c,o=a>>>2;u.length<=o;)u.push(0);u[o]|=s<<8*(h+r*(a%4))}return{value:u,binLen:4*e.length+n}}(e,t,r,n)};case"TEXT":return function(e,r,i){return function(e,t,n,r,i){let s,o,a,u,c,h,l,f,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===t)for(l=-1===i?3:0,a=0;a<e.length;a+=1)for(s=e.charCodeAt(a),o=[],128>s?o.push(s):2048>s?(o.push(192|s>>>6),o.push(128|63&s)):55296>s||57344<=s?o.push(224|s>>>12,128|s>>>6&63,128|63&s):(a+=1,s=65536+((1023&s)<<10|1023&e.charCodeAt(a)),o.push(240|s>>>18,128|s>>>12&63,128|s>>>6&63,128|63&s)),u=0;u<o.length;u+=1){for(h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=o[u]<<8*(l+i*(h%4)),p+=1}else for(l=-1===i?2:0,f="UTF16LE"===t&&1!==i||"UTF16LE"!==t&&1===i,a=0;a<e.length;a+=1){for(s=e.charCodeAt(a),!0===f&&(u=255&s,s=u<<8|s>>>8),h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=s<<8*(l+i*(h%4)),p+=2}return{value:d,binLen:8*p+r}}(e,t,r,i,n)};case"B64":return function(e,t,i){return function(e,t,n,i){let s,o,a,u,c,h,l,f=0;const p=t||[0],d=(n=n||0)>>>3,g=-1===i?3:0,w=e.indexOf("=");if(-1===e.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(e=e.replace(/=/g,""),-1!==w&&w<e.length)throw new Error("Invalid '=' found in base-64 string");for(o=0;o<e.length;o+=4){for(c=e.substr(o,4),u=0,a=0;a<c.length;a+=1)s=r.indexOf(c.charAt(a)),u|=s<<18-6*a;for(a=0;a<c.length-1;a+=1){for(l=f+d,h=l>>>2;p.length<=h;)p.push(0);p[h]|=(u>>>16-8*a&255)<<8*(g+i*(l%4)),f+=1}}return{value:p,binLen:8*f+n}}(e,t,i,n)};case"BYTES":return function(e,t,r){return function(e,t,n,r){let i,s,o,a;const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(s=0;s<e.length;s+=1)i=e.charCodeAt(s),a=s+c,o=a>>>2,u.length<=o&&u.push(0),u[o]|=i<<8*(h+r*(a%4));return{value:u,binLen:8*e.length+n}}(e,t,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e,t,r){return function(e,t,n,r){return i(new Uint8Array(e),t,n,r)}(e,t,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e,t,r){return i(e,t,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function o(e,t,n,i){switch(e){case"HEX":return function(e){return function(e,t,n,r){const i="0123456789abcdef";let s,o,a="";const u=t/8,c=-1===n?3:0;for(s=0;s<u;s+=1)o=e[s>>>2]>>>8*(c+n*(s%4)),a+=i.charAt(o>>>4&15)+i.charAt(15&o);return r.outputUpper?a.toUpperCase():a}(e,t,n,i)};case"B64":return function(e){return function(e,t,n,i){let s,o,a,u,c,h="";const l=t/8,f=-1===n?3:0;for(s=0;s<l;s+=3)for(u=s+1<l?e[s+1>>>2]:0,c=s+2<l?e[s+2>>>2]:0,a=(e[s>>>2]>>>8*(f+n*(s%4))&255)<<16|(u>>>8*(f+n*((s+1)%4))&255)<<8|c>>>8*(f+n*((s+2)%4))&255,o=0;o<4;o+=1)h+=8*s+6*o<=t?r.charAt(a>>>6*(3-o)&63):i.b64Pad;return h}(e,t,n,i)};case"BYTES":return function(e){return function(e,t,n){let r,i,s="";const o=t/8,a=-1===n?3:0;for(r=0;r<o;r+=1)i=e[r>>>2]>>>8*(a+n*(r%4))&255,s+=String.fromCharCode(i);return s}(e,t,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,s=new ArrayBuffer(i),o=new Uint8Array(s),a=-1===n?3:0;for(r=0;r<i;r+=1)o[r]=e[r>>>2]>>>8*(a+n*(r%4))&255;return s}(e,t,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,s=-1===n?3:0,o=new Uint8Array(i);for(r=0;r<i;r+=1)o[r]=e[r>>>2]>>>8*(s+n*(r%4))&255;return o}(e,t,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function a(e){const t={outputUpper:!1,b64Pad:"=",outputLen:-1},n=e||{},r="Output length must be a multiple of 8";if(t.outputUpper=n.outputUpper||!1,n.b64Pad&&(t.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);t.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);t.outputLen=n.shakeLen}if("boolean"!=typeof t.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof t.b64Pad)throw new Error("Invalid b64Pad formatting option");return t}function u(e,t){return e<<t|e>>>32-t}function c(e,t,n){return e^t^n}function h(e,t,n){return e&t^e&n^t&n}function l(e,t){const n=(65535&e)+(65535&t);return(65535&(e>>>16)+(t>>>16)+(n>>>16))<<16|65535&n}function f(e,t,n,r,i){const s=(65535&e)+(65535&t)+(65535&n)+(65535&r)+(65535&i);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16)+(s>>>16))<<16|65535&s}function p(e){return[1732584193,4023233417,2562383102,271733878,3285377520]}function d(e,t){let n,r,i,s,o,a,p;const d=[];for(n=t[0],r=t[1],i=t[2],s=t[3],o=t[4],p=0;p<80;p+=1)d[p]=p<16?e[p]:u(d[p-3]^d[p-8]^d[p-14]^d[p-16],1),a=p<20?f(u(n,5),(g=r)&i^~g&s,o,1518500249,d[p]):p<40?f(u(n,5),c(r,i,s),o,1859775393,d[p]):p<60?f(u(n,5),h(r,i,s),o,2400959708,d[p]):f(u(n,5),c(r,i,s),o,3395469782,d[p]),o=s,s=i,i=u(r,30),r=n,n=a;var g;return t[0]=l(n,t[0]),t[1]=l(r,t[1]),t[2]=l(i,t[2]),t[3]=l(s,t[3]),t[4]=l(o,t[4]),t}function g(e,t,n,r){let i;const s=15+(t+65>>>9<<4),o=t+n;for(;e.length<=s;)e.push(0);for(e[t>>>5]|=128<<24-t%32,e[s]=4294967295&o,e[s-1]=o/4294967296|0,i=0;i<e.length;i+=16)r=d(e.slice(i,i+16),r);return r}class w extends class{constructor(e,t,n){const r=n||{};if(this.t=t,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=e,this.h=[],this.u=0,this.l=!1,this.A=0,this.p=!1,this.R=[],this.U=[]}update(e){let t,n=0;const r=this.T>>>5,i=this.F(e,this.h,this.u),s=i.binLen,o=i.value,a=s>>>5;for(t=0;t<a;t+=r)n+this.T<=s&&(this.m=this.g(o.slice(t,t+r),this.m),n+=this.T);return this.A+=n,this.h=o.slice(n>>>5),this.u=s%this.T,this.l=!0,this}getHash(e,t){let n,r,i=this.B;const s=a(t);if(this.v){if(-1===s.outputLen)throw new Error("Output length must be specified in options");i=s.outputLen}const u=o(e,i,this.Y,s);if(this.p&&this.H)return u(this.H(s));for(r=this.C(this.h.slice(),this.u,this.A,this.I(this.m),i),n=1;n<this.numRounds;n+=1)this.v&&i%32!=0&&(r[r.length-1]&=16777215>>>24-i%32),r=this.C(r,i,0,this.L(this.o),i);return u(r)}setHMACKey(e,t,n){if(!this.M)throw new Error("Variant does not support HMAC");if(this.l)throw new Error("Cannot set MAC key after calling update");const r=s(t,(n||{}).encoding||"UTF8",this.Y);this.N(r(e))}N(e){const t=this.T>>>3,n=t/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(t<e.binLen/8&&(e.value=this.C(e.value,e.binLen,0,this.L(this.o),this.B));e.value.length<=n;)e.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^e.value[r],this.U[r]=1549556828^e.value[r];this.m=this.g(this.R,this.m),this.A=this.T,this.p=!0}getHMAC(e,t){const n=a(t);return o(e,this.B,this.Y,n)(this.S())}S(){let e;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const t=this.C(this.h.slice(),this.u,this.A,this.I(this.m),this.B);return e=this.g(this.U,this.L(this.o)),e=this.C(t,this.B,this.T,e,this.B),e}}{constructor(e,t,n){if("SHA-1"!==e)throw new Error("Chosen SHA variant is not supported");super(e,t,n);const r=n||{};this.M=!0,this.H=this.S,this.Y=-1,this.F=s(this.t,this.i,this.Y),this.g=d,this.I=function(e){return e.slice()},this.L=p,this.C=g,this.m=[1732584193,4023233417,2562383102,271733878,3285377520],this.T=512,this.B=160,this.v=!1,r.hmacKey&&this.N(function(e,t,n,r){const i="hmacKey must include a value and format";if(!t)throw new Error(i);if(void 0===t.value||!t.format)throw new Error(i);return s(t.format,t.encoding||"UTF8",n)(t.value)}(0,r.hmacKey,this.Y))}}},673:(e,t,n)=>{n.r(t),n.d(t,{default:()=>k});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(e,t,n,r){let i,s,o;const a=t||[0],u=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<e.length;i+=1)o=i+u,s=o>>>2,a.length<=s&&a.push(0),a[s]|=e[i]<<8*(c+r*(o%4));return{value:a,binLen:8*e.length+n}}function s(e,t,n){switch(t){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(e,t,r){return function(e,t,n,r){let i,s,o,a;if(0!=e.length%2)throw new Error("String of HEX type must be in byte increments");const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(i=0;i<e.length;i+=2){if(s=parseInt(e.substr(i,2),16),isNaN(s))throw new Error("String of HEX type contains invalid characters");for(a=(i>>>1)+c,o=a>>>2;u.length<=o;)u.push(0);u[o]|=s<<8*(h+r*(a%4))}return{value:u,binLen:4*e.length+n}}(e,t,r,n)};case"TEXT":return function(e,r,i){return function(e,t,n,r,i){let s,o,a,u,c,h,l,f,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===t)for(l=-1===i?3:0,a=0;a<e.length;a+=1)for(s=e.charCodeAt(a),o=[],128>s?o.push(s):2048>s?(o.push(192|s>>>6),o.push(128|63&s)):55296>s||57344<=s?o.push(224|s>>>12,128|s>>>6&63,128|63&s):(a+=1,s=65536+((1023&s)<<10|1023&e.charCodeAt(a)),o.push(240|s>>>18,128|s>>>12&63,128|s>>>6&63,128|63&s)),u=0;u<o.length;u+=1){for(h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=o[u]<<8*(l+i*(h%4)),p+=1}else for(l=-1===i?2:0,f="UTF16LE"===t&&1!==i||"UTF16LE"!==t&&1===i,a=0;a<e.length;a+=1){for(s=e.charCodeAt(a),!0===f&&(u=255&s,s=u<<8|s>>>8),h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=s<<8*(l+i*(h%4)),p+=2}return{value:d,binLen:8*p+r}}(e,t,r,i,n)};case"B64":return function(e,t,i){return function(e,t,n,i){let s,o,a,u,c,h,l,f=0;const p=t||[0],d=(n=n||0)>>>3,g=-1===i?3:0,w=e.indexOf("=");if(-1===e.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(e=e.replace(/=/g,""),-1!==w&&w<e.length)throw new Error("Invalid '=' found in base-64 string");for(o=0;o<e.length;o+=4){for(c=e.substr(o,4),u=0,a=0;a<c.length;a+=1)s=r.indexOf(c.charAt(a)),u|=s<<18-6*a;for(a=0;a<c.length-1;a+=1){for(l=f+d,h=l>>>2;p.length<=h;)p.push(0);p[h]|=(u>>>16-8*a&255)<<8*(g+i*(l%4)),f+=1}}return{value:p,binLen:8*f+n}}(e,t,i,n)};case"BYTES":return function(e,t,r){return function(e,t,n,r){let i,s,o,a;const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(s=0;s<e.length;s+=1)i=e.charCodeAt(s),a=s+c,o=a>>>2,u.length<=o&&u.push(0),u[o]|=i<<8*(h+r*(a%4));return{value:u,binLen:8*e.length+n}}(e,t,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e,t,r){return function(e,t,n,r){return i(new Uint8Array(e),t,n,r)}(e,t,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e,t,r){return i(e,t,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function o(e,t,n,i){switch(e){case"HEX":return function(e){return function(e,t,n,r){const i="0123456789abcdef";let s,o,a="";const u=t/8,c=-1===n?3:0;for(s=0;s<u;s+=1)o=e[s>>>2]>>>8*(c+n*(s%4)),a+=i.charAt(o>>>4&15)+i.charAt(15&o);return r.outputUpper?a.toUpperCase():a}(e,t,n,i)};case"B64":return function(e){return function(e,t,n,i){let s,o,a,u,c,h="";const l=t/8,f=-1===n?3:0;for(s=0;s<l;s+=3)for(u=s+1<l?e[s+1>>>2]:0,c=s+2<l?e[s+2>>>2]:0,a=(e[s>>>2]>>>8*(f+n*(s%4))&255)<<16|(u>>>8*(f+n*((s+1)%4))&255)<<8|c>>>8*(f+n*((s+2)%4))&255,o=0;o<4;o+=1)h+=8*s+6*o<=t?r.charAt(a>>>6*(3-o)&63):i.b64Pad;return h}(e,t,n,i)};case"BYTES":return function(e){return function(e,t,n){let r,i,s="";const o=t/8,a=-1===n?3:0;for(r=0;r<o;r+=1)i=e[r>>>2]>>>8*(a+n*(r%4))&255,s+=String.fromCharCode(i);return s}(e,t,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,s=new ArrayBuffer(i),o=new Uint8Array(s),a=-1===n?3:0;for(r=0;r<i;r+=1)o[r]=e[r>>>2]>>>8*(a+n*(r%4))&255;return s}(e,t,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,s=-1===n?3:0,o=new Uint8Array(i);for(r=0;r<i;r+=1)o[r]=e[r>>>2]>>>8*(s+n*(r%4))&255;return o}(e,t,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}const a=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],u=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428],c=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];function h(e){const t={outputUpper:!1,b64Pad:"=",outputLen:-1},n=e||{},r="Output length must be a multiple of 8";if(t.outputUpper=n.outputUpper||!1,n.b64Pad&&(t.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);t.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);t.outputLen=n.shakeLen}if("boolean"!=typeof t.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof t.b64Pad)throw new Error("Invalid b64Pad formatting option");return t}function l(e,t){return e>>>t|e<<32-t}function f(e,t){return e>>>t}function p(e,t,n){return e&t^~e&n}function d(e,t,n){return e&t^e&n^t&n}function g(e){return l(e,2)^l(e,13)^l(e,22)}function w(e,t){const n=(65535&e)+(65535&t);return(65535&(e>>>16)+(t>>>16)+(n>>>16))<<16|65535&n}function y(e,t,n,r){const i=(65535&e)+(65535&t)+(65535&n)+(65535&r);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16))<<16|65535&i}function m(e,t,n,r,i){const s=(65535&e)+(65535&t)+(65535&n)+(65535&r)+(65535&i);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16)+(s>>>16))<<16|65535&s}function b(e){return l(e,7)^l(e,18)^f(e,3)}function v(e){return l(e,6)^l(e,11)^l(e,25)}function L(e){let t;return t="SHA-224"==e?u.slice():c.slice(),t}function A(e,t){let n,r,i,s,o,u,c,h,L,A,k;const E=[];for(n=t[0],r=t[1],i=t[2],s=t[3],o=t[4],u=t[5],c=t[6],h=t[7],k=0;k<64;k+=1)E[k]=k<16?e[k]:y(l(R=E[k-2],17)^l(R,19)^f(R,10),E[k-7],b(E[k-15]),E[k-16]),L=m(h,v(o),p(o,u,c),a[k],E[k]),A=w(g(n),d(n,r,i)),h=c,c=u,u=o,o=w(s,L),s=i,i=r,r=n,n=w(L,A);var R;return t[0]=w(n,t[0]),t[1]=w(r,t[1]),t[2]=w(i,t[2]),t[3]=w(s,t[3]),t[4]=w(o,t[4]),t[5]=w(u,t[5]),t[6]=w(c,t[6]),t[7]=w(h,t[7]),t}class k extends class{constructor(e,t,n){const r=n||{};if(this.t=t,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=e,this.h=[],this.u=0,this.A=!1,this.l=0,this.p=!1,this.R=[],this.U=[]}update(e){let t,n=0;const r=this.T>>>5,i=this.F(e,this.h,this.u),s=i.binLen,o=i.value,a=s>>>5;for(t=0;t<a;t+=r)n+this.T<=s&&(this.m=this.g(o.slice(t,t+r),this.m),n+=this.T);return this.l+=n,this.h=o.slice(n>>>5),this.u=s%this.T,this.A=!0,this}getHash(e,t){let n,r,i=this.B;const s=h(t);if(this.H){if(-1===s.outputLen)throw new Error("Output length must be specified in options");i=s.outputLen}const a=o(e,i,this.v,s);if(this.p&&this.Y)return a(this.Y(s));for(r=this.C(this.h.slice(),this.u,this.l,this.S(this.m),i),n=1;n<this.numRounds;n+=1)this.H&&i%32!=0&&(r[r.length-1]&=16777215>>>24-i%32),r=this.C(r,i,0,this.I(this.o),i);return a(r)}setHMACKey(e,t,n){if(!this.L)throw new Error("Variant does not support HMAC");if(this.A)throw new Error("Cannot set MAC key after calling update");const r=s(t,(n||{}).encoding||"UTF8",this.v);this.M(r(e))}M(e){const t=this.T>>>3,n=t/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(t<e.binLen/8&&(e.value=this.C(e.value,e.binLen,0,this.I(this.o),this.B));e.value.length<=n;)e.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^e.value[r],this.U[r]=1549556828^e.value[r];this.m=this.g(this.R,this.m),this.l=this.T,this.p=!0}getHMAC(e,t){const n=h(t);return o(e,this.B,this.v,n)(this.N())}N(){let e;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const t=this.C(this.h.slice(),this.u,this.l,this.S(this.m),this.B);return e=this.g(this.U,this.I(this.o)),e=this.C(t,this.B,this.T,e,this.B),e}}{constructor(e,t,n){if("SHA-224"!==e&&"SHA-256"!==e)throw new Error("Chosen SHA variant is not supported");super(e,t,n);const r=n||{};this.Y=this.N,this.L=!0,this.v=-1,this.F=s(this.t,this.i,this.v),this.g=A,this.S=function(e){return e.slice()},this.I=L,this.C=function(t,n,r,i){return function(e,t,n,r,i){let s,o;const a=15+(t+65>>>9<<4),u=t+n;for(;e.length<=a;)e.push(0);for(e[t>>>5]|=128<<24-t%32,e[a]=4294967295&u,e[a-1]=u/4294967296|0,s=0;s<e.length;s+=16)r=A(e.slice(s,s+16),r);return o="SHA-224"===i?[r[0],r[1],r[2],r[3],r[4],r[5],r[6]]:r,o}(t,n,r,i,e)},this.m=L(e),this.T=512,this.B="SHA-224"===e?224:256,this.H=!1,r.hmacKey&&this.M(function(e,t,n,r){const i="hmacKey must include a value and format";if(!t)throw new Error(i);if(void 0===t.value||!t.format)throw new Error(i);return s(t.format,t.encoding||"UTF8",n)(t.value)}(0,r.hmacKey,this.v))}}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var s=t[r]={exports:{}};return e[r](s,s.exports,n),s.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};(()=>{n.d(r,{j$:()=>g,nm:()=>l,Xz:()=>s,ul:()=>a,zo:()=>c,zM:()=>t,pI:()=>p,I4:()=>d,Fl:()=>h,In:()=>i,Cj:()=>o,t6:()=>u,mh:()=>e,LQ:()=>f,R2:()=>z,rJ:()=>q,xI:()=>Le,$$:()=>ve,e9:()=>X,K2:()=>j,ZC:()=>J,iv:()=>B,d2:()=>F,vB:()=>be,y1:()=>me,Hv:()=>b,Ue:()=>Ue,Jx:()=>x,cv:()=>E,Pi:()=>ne,um:()=>re,sK:()=>y,Fw:()=>w,zE:()=>W,RU:()=>Z,Xs:()=>G,r1:()=>Q,Kl:()=>ee,A7:()=>ye,px:()=>ge,ZW:()=>we,ti:()=>de,bX:()=>m,Dc:()=>L,fp:()=>v,Ye:()=>fe,Qc:()=>C,hP:()=>le,LU:()=>he,yQ:()=>S,Zk:()=>T,uh:()=>U});const e=108,t=new Uint8Array([e]),i=100,s=new Uint8Array([i]),o=101,a=new Uint8Array([o]),u=105,c=new Uint8Array([u]),h=58,l=new Uint8Array([h]),f=45,p=new Uint8Array([f]),d=48,g=new Uint8Array([d]);function w(e){return e>=d&&e<=d+9}function y(e,t,n){let r=0,i=e.length;for(;r<i;){const s=r+i>>>1,o=n(e[s],t);if(0===o)return{index:s,result:e[s]};o<0?r=s+1:i=s}return{index:r,result:void 0}}function m(e,t){const n=[];for(const r of e){const{index:e}=y(n,r,t);n.splice(e,0,r)}return n}function b(...e){const t=new Uint8Array(e.reduce(((e,t)=>e+t.byteLength),0));return e.reduce(((e,n)=>(t.set(n,e),e+n.byteLength)),0),t}function v(e){return 1<<32-Math.clz32(e-1)}async function L(e){if(0===e.length)throw new Error("Empty leaves");const t=new Uint8Array(64);for(;e.length>1;){let r=!1;const i=[];for(const s of e)if(r){let e;t.set(s,32);try{e=new Uint8Array(await crypto.subtle.digest("SHA-256",t))}catch{const{default:r}=await Promise.resolve().then(n.bind(n,673)),i=new r("SHA-256","UINT8ARRAY");i.update(t),e=i.getHash("UINT8ARRAY")}i.push(e),r=!1}else t.set(s),r=!0;e=i}return e[0]}const A=new WeakMap;class k{textEncoder=new TextEncoder;textDecoder=new TextDecoder;data;path=[];hooks;consumedHookHandler=new WeakMap;constructor(e,t){this.data=e,this.hooks=t,t&&A.set(t,!0)}start(e){if(this.encode(this.data,e),this.hooks)for(const e of this.hooks.values())this.consumedHookHandler.get(e)||e({value:void 0,done:!0});e.close()}encode(e,n){if(null!=e)if("boolean"==typeof e)this.encode(e?1:0,n);else if("number"==typeof e){const t=Math.round(e);n.enqueue(this.textEncoder.encode(`i${t}e`)),t!==e&&(console.warn(`WARNING: Possible data corruption detected with value "${e}":`,`Bencoding only defines support for integers, value was converted to "${t}"`),console.trace())}else if("bigint"==typeof e)n.enqueue(this.textEncoder.encode(`i${e}e`));else if("string"==typeof e){const t=this.textEncoder.encode(e),r=t.byteLength;n.enqueue(this.textEncoder.encode(`${r}:`)),n.enqueue(t)}else if(e instanceof ArrayBuffer){const t=new Uint8Array(e),r=t.byteLength;n.enqueue(this.textEncoder.encode(`${r}:`)),n.enqueue(t)}else if(Array.isArray(e)){n.enqueue(t);let r=0;for(const t of e){if(this.path.push(r),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0})}else this.encode(t,n)}this.path.pop(),++r}n.enqueue(a)}else if(e instanceof Map){n.enqueue(s);const t=m(e.keys(),((e,t)=>(e="string"==typeof e?e:this.textDecoder.decode(e))<(t="string"==typeof t?t:this.textDecoder.decode(t))?-1:e>t?1:0));for(const r of t){const t=e.get(r);if(void 0!==t&&null!==e)if(r instanceof ArrayBuffer)this.encode(r,n),this.encode(t,n);else{if(this.path.push(r),this.encode(r,n),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0}),this.consumedHookHandler.set(e,!0)}else this.encode(t,n)}this.path.pop()}}n.enqueue(a)}else{n.enqueue(s);const t=Object.keys(e).sort();for(const r of t){const t=e[r];if(void 0!==t&&null!==e){if(this.path.push(r),this.encode(r,n),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0}),this.consumedHookHandler.set(e,!0)}else this.encode(t,n)}this.path.pop()}}n.enqueue(a)}}}function E(e,t){return new ReadableStream(new k(e,t))}function R(e,t){return new Proxy(e,{get:function(e,n,r){return"enqueue"===n?(n=>{e.enqueue(n),t({value:n,done:!1})}).bind(e):Reflect.get(e,n,r)}})}function U(e,t){const n={controller:null},r=new ReadableStream({start(e){n.controller=e},pull(e){A.get(t)||(console.warn("You need to call encode() first and then consume hooks."),e.close(),n.controller=null)}});return t.set(e,(({value:e,done:t})=>{null!==n.controller&&(t?n.controller.close():n.controller.enqueue(e))})),[r]}function S(e,t){const[n]=U(e,t);return[new Response(n).arrayBuffer()]}function T(e,t){const[n]=U(e,t);return[new Response(n).text()]}var B;!function(e){e.Integer="Integer",e.ByteString="ByteString",e.ListStart="ListStart",e.ListEnd="ListEnd",e.DictionaryStart="DictionaryStart",e.DictionaryEnd="DictionaryEnd"}(B||(B={}));class P{endStack=[];token=null;byteStringLength=-1;byteStringOffset=0;transform(e,t){this.tokenize(e,t)}flush(){if(this.endStack.length||this.token||-1!==this.byteStringLength||this.byteStringOffset)throw new SyntaxError("Unexpected end of torrent stream")}tokenize(t,n){if(0!==t.byteLength)if(null===this.token&&-1===this.byteStringLength){const r=t[0];if(r===u)this.token={type:B.Integer,value:new Uint8Array};else if(w(r))this.byteStringLength=r-d;else if(r===e)this.endStack.push(B.ListEnd),n.enqueue({type:B.ListStart});else if(r===i)this.endStack.push(B.DictionaryEnd),n.enqueue({type:B.DictionaryStart});else{if(r!==o)throw new SyntaxError(`Unexpected byte: ${r}`);{const e=this.endStack.pop();if(!e)throw new SyntaxError("Unbalanced delimiter");n.enqueue({type:e})}}this.tokenize(t.subarray(1),n)}else if(this.token&&-1===this.byteStringLength)if(this.token.type===B.Integer){const e=t.indexOf(o);-1===e?this.token.value=this.token.value?b(this.token.value,t):t:(this.token.value=this.token.value?b(this.token.value,t.subarray(0,e)):t.subarray(0,e),n.enqueue(this.token),this.token=null,this.tokenize(t.subarray(e+1),n))}else{if(this.token.type!==B.ByteString)throw new Error("This is a bug");{const e=this.token.value.byteLength-this.byteStringOffset,r=t.byteLength;r<e?(this.token.value.set(t,this.byteStringOffset),this.byteStringOffset+=r):(this.token.value.set(t.subarray(0,e),this.byteStringOffset),this.byteStringOffset=0,n.enqueue(this.token),this.token=null,this.tokenize(t.subarray(e),n))}}else{if(!(this.byteStringLength>-1&&null===this.token))throw new Error("This is a bug");{let e=-1;for(const[n,r]of t.entries()){if(!w(r)){if(r===h){e=n;break}throw new SyntaxError(`Unexpected byte: ${r}`)}this.byteStringLength=10*this.byteStringLength-d+r}-1!==e&&(this.token={type:B.ByteString,value:new Uint8Array(this.byteStringLength)},this.byteStringLength=-1,this.tokenize(t.subarray(e+1),n))}}}}class F extends TransformStream{constructor(){super(new P)}}async function C(e){let t;const n=[],r=e.getReader();let i;for(;;){const{done:e,value:s}=await r.read();if(e)break;const o=n.at(-1);if(o)if(Array.isArray(o))switch(s.type){case B.Integer:o.push(I(s.value));break;case B.ByteString:o.push(H(s.value));break;case B.DictionaryStart:{const e=Object.create(null);o.push(e),n.push(e);break}case B.ListStart:{const e=[];o.push(e),n.push(e);break}case B.ListEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`)}else if(void 0===i)switch(s.type){case B.ByteString:i=H(s.value);break;case B.DictionaryEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`)}else{switch(s.type){case B.Integer:o[i]=I(s.value);break;case B.ByteString:o[i]=H(s.value);break;case B.DictionaryStart:{const e=Object.create(null);o[i]=e,n.push(e);break}case B.ListStart:{const e=[];o[i]=e,n.push(e);break}default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`)}i=void 0}else{if(void 0!==t)throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`);switch(s.type){case B.Integer:t=I(s.value);break;case B.ByteString:t=H(s.value);break;case B.DictionaryStart:{const e=Object.create(null);n.push(e),t=e;break}case B.ListStart:{const e=[];n.push(e),t=e;break}default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(s)}`)}}}if(n.length)throw new Error("Unexpected end of token stream");return t}async function x(e){const t=new F,n=e.pipeThrough(t);return await C(n)}function I(e){let t=0,n=!0;for(const[r,i]of e.entries()){if(0===r&&i===f){n=!1;continue}if(1===r&&!n&&i===d)throw new SyntaxError("Negative zero is not a valid integer");if(1===r&&0===t)throw new SyntaxError("Leading zeros are not allowed");if(!w(i))throw new SyntaxError(`Unexpected byte: ${i}`);const e=i-d;(n&&"number"==typeof t&&t>(Number.MAX_SAFE_INTEGER-e)/10||!n&&"number"==typeof t&&t<(Number.MIN_SAFE_INTEGER+e)/10)&&(t=BigInt(t)),t="number"==typeof t?n?10*t+e:10*t-e:n?10n*t+BigInt(e):10n*t-BigInt(e)}return t}function H(e){return(new TextDecoder).decode(e)}n(913);class N extends Error{constructor(e,t){super(((e,...t)=>{let n=e;return t.length>0&&(n+=` :: ${JSON.stringify(t)}`),n})(e,t)),this.name=e,this.details=t}}class M{constructor(){this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t}))}}function Y(e){const t=e.map((e=>Promise.resolve(e).then((e=>function(e){if(e instanceof Response){if(e.body)return e.body.getReader();throw new N("opaque-streams-source",{type:e.type})}return e instanceof ReadableStream?e.getReader():new Response(e).body.getReader()}(e))))),n=new M;let r=0;const i=new ReadableStream({pull(e){return t[r].then((e=>e.read())).then((i=>{if(i.done)return r++,r>=t.length?(e.close(),void n.resolve()):this.pull(e);e.enqueue(i.value)})).catch((e=>{throw n.reject(e),e}))},cancel(){n.resolve()}});return{done:n.promise,stream:i}}n(1);const D=new Uint8Array(32);class O{blockCount=0;merkleLeaves=[];blocksPerPiece;constructor(e){this.blocksPerPiece=e}async transform(e,t){let r;++this.blockCount;try{r=new Uint8Array(await crypto.subtle.digest("SHA-256",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,673)),i=new t("SHA-256","UINT8ARRAY");i.update(e),r=i.getHash("UINT8ARRAY")}this.merkleLeaves.push(r),this.merkleLeaves.length===this.blocksPerPiece&&(t.enqueue(this.merkleLeaves),this.merkleLeaves=[])}flush(e){if(0===this.blockCount)return;let t=0;if(this.blockCount<this.blocksPerPiece)t=v(this.blockCount)-this.blockCount;else{const e=this.blockCount%this.blocksPerPiece;e>0&&(t=this.blocksPerPiece-e)}if(t>0)for(let e=0;e<t;++e)this.merkleLeaves.push(D);this.merkleLeaves.length>0&&e.enqueue(this.merkleLeaves)}}class z extends TransformStream{constructor(e){super(new O(e))}}class ${residuePointer=0;chunkLength;residue;opts;constructor(e,t={padding:!1}){this.chunkLength=e,this.opts=t,this.residue=new Uint8Array(this.chunkLength)}transform(e,t){for(;this.residuePointer+e.byteLength>=this.chunkLength;){const n=this.chunkLength-this.residuePointer;this.residue.set(e.subarray(0,n),this.residuePointer),this.residuePointer=0,t.enqueue(new Uint8Array(this.residue)),e=e.subarray(n)}this.residue.set(e,this.residuePointer),this.residuePointer+=e.byteLength}flush(e){this.residuePointer<=0||(this.opts.padding?(this.residue.set(new Uint8Array(this.chunkLength-this.residuePointer),this.residuePointer),e.enqueue(this.residue)):e.enqueue(this.residue.subarray(0,this.residuePointer)))}}class q extends TransformStream{constructor(e,t={padding:!1}){super(new $(e,t))}}class K{updateProgress;constructor(e){this.updateProgress=e}async transform(e,t){t.enqueue(await L(e)),this.updateProgress&&await this.updateProgress()}}class X extends TransformStream{constructor(e){super(new K(e))}}class _{leafCount=0;merkleLeaves=[];blocksPerPiece;constructor(e){this.blocksPerPiece=e}transform(e){++this.leafCount,this.merkleLeaves.push(e)}async flush(e){const t=v(this.leafCount)-this.leafCount;if(t>0){const e=await this.padLeafPromise;for(let n=0;n<t;++n)this.merkleLeaves.push(e)}e.enqueue(this.merkleLeaves)}get padLeafPromise(){return L(Array(this.blocksPerPiece).fill(new Uint8Array(32)))}}class j extends TransformStream{constructor(e){super(new _(e))}}class V{updateProgress;constructor(e){this.updateProgress=e}async transform(e,t){let r;try{r=new Uint8Array(await crypto.subtle.digest("SHA-1",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,211)),i=new t("SHA-1","UINT8ARRAY");i.update(e),r=i.getHash("UINT8ARRAY")}t.enqueue(r),this.updateProgress&&await this.updateProgress()}}class J extends TransformStream{constructor(e){super(new V(e))}}function W(e){return e instanceof File}function Z(e){return!G(e)&&!W(e)&&e.isDirectory}function Q(e){return!G(e)&&!W(e)&&e.isFile}function G(e){try{if(e instanceof FileSystemHandle&&"directory"===e.kind)return!0}catch(e){}return!1}function ee(e){try{if(e instanceof FileSystemHandle&&"file"===e.kind)return!0}catch(e){}return!1}function te(e){return new Promise(((t,n)=>{e.readEntries(t,n)}))}async function*ne(e){const t=e.createReader();let n=[];do{n=await te(t);for(const e of n)yield e}while(n.length>0)}function re(e){return new Promise(((t,n)=>{e.file(t,n)}))}const ie={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let se;const oe=new Uint8Array(16);function ae(){if(!se&&(se="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!se))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return se(oe)}const ue=[];for(let e=0;e<256;++e)ue.push((e+256).toString(16).slice(1));const ce=function(e,t,n){if(ie.randomUUID&&!t&&!e)return ie.randomUUID();const r=(e=e||{}).random||(e.rng||ae)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return(ue[e[t+0]]+ue[e[t+1]]+ue[e[t+2]]+ue[e[t+3]]+"-"+ue[e[t+4]]+ue[e[t+5]]+"-"+ue[e[t+6]]+ue[e[t+7]]+"-"+ue[e[t+8]]+ue[e[t+9]]+"-"+ue[e[t+10]]+ue[e[t+11]]+ue[e[t+12]]+ue[e[t+13]]+ue[e[t+14]]+ue[e[t+15]]).toLowerCase()}(r)};function he(e,t){if(t.size>1||0===t.size)return{name:e??ce(),commonDir:void 0};const[n,r]=t.entries().next().value;return de(r)?{name:n,commonDir:void 0}:{name:e??n,commonDir:n}}async function le(e,{sort:t=!0,compareFunction:n=me,polyfillWebkitRelativePath:r=!0}={sort:!0,compareFunction:me,polyfillWebkitRelativePath:!0}){let i=0,s=0;const o=new WeakMap,a=new WeakMap,u=new WeakMap,c=["file tree",[]],h=[c];let l=!1;for await(const t of e)await f(t);return{fileTree:fe(c[1],l),traverseTree:function*e(t){if(ge(t))for(const n of t.values())yield*e(n);else yield[t,u.get(t)]},totalFileSize:i,totalFileCount:s};async function f(e){const p=h.at(-1);if(!p)throw new Error("This is a bug");const d=W(e),g=G(e),w=Z(e),m=ee(e),b=Q(e);if(g||w){const r=e.name,{index:i,result:s}=y(p[1],r,n);let o=s;if(we(o))throw new Error("A same name file already exists");if(ye(o)&&g){const t=a.get(o);if(!t||!await e.isSameEntry(t))throw new Error("File system handle not match")}o||(o=[r,[]],t?p[1].splice(i,0,o):p[1].push(o),g&&a.set(o,e)),h.push(o);for await(const t of g?e.values():ne(e))await f(t);o[1]=new Map(o[1]),h.pop()}else if(m||b){const a=e.name,{index:c,result:l}=y(p[1],a,n);let f=l;if(we(f)&&m){const t=o.get(f);if(!t||!await e.isSameEntry(t))throw new Error("A same name file already exists")}if(ye(f))throw new Error("A same name directory already exists");if(f)return;const d=await(m?e.getFile():re(e)),g=d.size;if(r){const e=h.reduce(((e,t,n)=>0===n?e:e+t[0]+"/"),"")+d.name;Object.defineProperty(d,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>e})}const w={"":{length:g}};f=[a,w],t?p[1].splice(c,0,f):p[1].push(f),m&&o.set(f,e),u.set(w,d),i+=g,s+=1}else{if(!d)throw new Error("Unrecognized type of input");{r&&""===e.webkitRelativePath&&Object.defineProperty(e,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>e.name});const o=(e.webkitRelativePath||e.name).split("/"),a=[c];for(const[r,c]of o.entries()){r>=1&&(l=!0);const h=a.at(-1);if(!h)throw new Error("This is a bug");const{index:f,result:p}=y(h[1],c,n);if(r<o.length-1){let e=p;if(we(e))throw new Error("A same name file already exists");e||(e=[c,[]],t?h[1].splice(f,0,e):h[1].push(e)),a.push(e)}else{let n=p;if(ye(n))throw new Error("A same name directory already exists");if(n)return;const r=e.size,o={"":{length:r}};n=[c,o],t?h[1].splice(f,0,n):h[1].push(n),u.set(o,e),i+=r,s+=1}}}}}}function fe(e,t=!1){return t&&pe(e),new Map(e)}function pe(e){for(const t of e)if(ye(t)){const e=t[1];pe(e),t[1]=new Map(e)}}function de(e){return!!e&&""in e}function ge(e){return e instanceof Map}function we(e){return!!e&&""in e[1]}function ye(e){return!!e&&!(""in e[1])}function me(e,t){return e[0]<t?-1:e[0]>t?1:0}var be;!function(e){e.V1="v1",e.V2="v2",e.HYBRID="hybrid"}(be||(be={}));const ve=16384;var Le;!function(e){e[e["16KB"]=16384]="16KB",e[e["32KB"]=32768]="32KB",e[e["64KB"]=65536]="64KB",e[e["128KB"]=131072]="128KB",e[e["256KB"]=262144]="256KB",e[e["512KB"]=524288]="512KB",e[e["1MB"]=1048576]="1MB",e[e["2MB"]=2097152]="2MB",e[e["4MB"]=4194304]="4MB",e[e["8MB"]=8388608]="8MB",e[e["16MB"]=16777216]="16MB",e[e["32MB"]=33554432]="32MB"}(Le||(Le={}));const Ae={type:be.V1,addCreatedBy:!0,addCreationDate:!0,addPaddingFiles:!1,blockLength:ve,pieceLength:NaN,sortFiles:!0,isPrivate:!1},ke={type:be.V2,addCreatedBy:!0,addCreationDate:!0,blockLength:ve,pieceLength:NaN,metaVersion:2,isPrivate:!1},Ee={type:be.HYBRID,addCreatedBy:!0,addCreationDate:!0,blockLength:ve,pieceLength:NaN,metaVersion:2,isPrivate:!1};function Re(e,t){let n=0;for(const r of e)n+=Math.ceil(r.size/t);return n}async function Ue(e,t={type:be.V1},n){switch(t.type){case be.V1:return await async function(e,t,n){const r={...Ae,...t},{fileTree:i,traverseTree:s,totalFileCount:o,totalFileSize:a}=await le(e,{sort:r.sortFiles});if(0===o)return;const u=[];for(const[,e]of s(i))u.push(e);isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),0!=(r.pieceLength&r.pieceLength-1)&&console.warn(`piece length ${r.pieceLength} is not a power of 2`),r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const[c,h]=Pe(0,n),{commonDir:l,name:f}=he(r.name,i);let p;if(r.name=f,r.addPaddingFiles){const e=Re(u,r.pieceLength);await h(e);const t=[],n=o-1;for(let e=n;e>=0;--e){const i=u[e];if(t.unshift(Promise.resolve(Te(i.stream(),{pieceLength:r.pieceLength,padding:e!==n,updateProgress:c}))),e===n)continue;const s=i.size%r.pieceLength;if(0===s)continue;const o=Be(r.pieceLength-s,l);u.splice(e+1,0,o)}p=Y(t).stream}else{const e=Math.ceil(a/r.pieceLength);await h(e);const{stream:t}=Y(u.map((e=>Promise.resolve(e.stream()))));p=Te(t,{pieceLength:r.pieceLength,padding:!1,updateProgress:c})}return{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.6"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{...o>1?{files:u.map((e=>{const t=(e.webkitRelativePath||e.name).split("/");return void 0!==l&&t.shift(),{...e.padding?{attr:"p"}:{},length:e.size,path:t}}))}:{length:a},name:r.name,"piece length":r.pieceLength,pieces:await new Response(p).arrayBuffer(),...r.isPrivate?{private:!0}:{}}}}(e,t,n);case be.V2:return await async function(e,t,n){const r={...ke,...t},{fileTree:i,traverseTree:s,totalFileCount:o,totalFileSize:a}=await le(e);if(0===o)return;const u=[],c=[];for(const[e,t]of s(i))u.push(t),c.push([e,t]);if(isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),r.pieceLength<r.blockLength)throw new Error(`piece length ${r.pieceLength} is smaller than block length ${r.blockLength}`);if(0!=(r.pieceLength&r.pieceLength-1))throw new Error(`piece length ${r.pieceLength} is not a power of 2`);const h=r.pieceLength/r.blockLength;r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const l=Re(u,r.pieceLength),[f]=Pe(l,n),{name:p}=he(r.name,i);r.name=p;const d=new Map;return await Promise.all(c.map((async([e,t])=>{await Se(t.stream(),d,e,{blockLength:r.blockLength,pieceLength:r.pieceLength,blocksPerPiece:h,updateProgress:f})}))),{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.6"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{"file tree":i,"meta version":r.metaVersion,name:r.name,"piece length":r.pieceLength,...r.isPrivate?{private:!0}:{}},"piece layers":d}}(e,t,n);case be.HYBRID:return await async function(e,t,n){const r={...Ee,...t},{fileTree:i,traverseTree:s,totalFileCount:o,totalFileSize:a}=await le(e);if(0===o)return;const u=[],c=[];for(const[e,t]of s(i))u.push(t),c.push([e,t]);if(isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),r.pieceLength<r.blockLength)throw new Error(`piece length ${r.pieceLength} is smaller than block length ${r.blockLength}`);if(0!=(r.pieceLength&r.pieceLength-1))throw new Error(`piece length ${r.pieceLength} is not a power of 2`);const h=r.pieceLength/r.blockLength;r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const[l]=Pe(2*Re(u,r.pieceLength),n),{commonDir:f,name:p}=he(r.name,i);r.name=p;const d=new Map,g=[],w=o-1;let y=-1;for(const[e,t]of c){++y;const[n,i]=t.stream().tee();if(g.unshift(Promise.resolve(Te(n,{pieceLength:r.pieceLength,padding:y!==w,updateProgress:l}))),await Se(i,d,e,{blockLength:r.blockLength,pieceLength:r.pieceLength,blocksPerPiece:h,updateProgress:l}),y===w)break;const s=t.size%r.pieceLength;if(0===s)continue;const o=Be(r.pieceLength-s,f);u.splice(y+1,0,o)}const m=Y(g).stream;return{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.6"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{"file tree":i,...o>1?{files:u.map((e=>{const t=(e.webkitRelativePath||e.name).split("/");return void 0!==f&&t.shift(),{...e.padding?{attr:"p"}:{},length:e.size,path:t}}))}:{length:a},"meta version":r.metaVersion,name:r.name,"piece length":r.pieceLength,pieces:await new Response(m).arrayBuffer(),...r.isPrivate?{private:!0}:{}},"piece layers":d}}(e,t,n)}}async function Se(e,t,n,r){const{piecesRootReadableStream:i,pieceLayerReadableStream:s}=function(e,t){const n=e.pipeThrough(new q(t.blockLength)).pipeThrough(new z(t.blocksPerPiece)).pipeThrough(new X(t.updateProgress)),[r,i]=n.tee();return{piecesRootReadableStream:i.pipeThrough(new j(t.blocksPerPiece)).pipeThrough(new X),pieceLayerReadableStream:r}}(e,r),o=new Response(i).arrayBuffer();if(n[""].length>r.pieceLength){const e=new Response(s).arrayBuffer();t.set(await o,await e)}n[""].length>0&&(n[""]["pieces root"]=await o)}function Te(e,t){return e.pipeThrough(new q(t.pieceLength,{padding:t.padding})).pipeThrough(new J(t.updateProgress))}function Be(e,t){const n=new File([new ArrayBuffer(e)],`${e}`,{type:"application/octet-stream"}),r=`.pad/${e}`,i=void 0===t?r:`${t}/${r}`;return Object.defineProperties(n,{webkitRelativePath:{configurable:!0,enumerable:!0,get:()=>i},padding:{configurable:!0,enumerable:!1,get:()=>!0}}),n}function Pe(e,t){const n={current:0,total:e};return[async()=>{t&&await t(++n.current,n.total)},async e=>{n.total="number"==typeof e?e:await e(n.total,n.current)}]}function Fe(e){if(void 0===e)return;const t=[];for(const n of e)0!==n.length&&t.push(n);return 0!==t.length?t:void 0}function Ce(e,t){return Math.max(t,v(e>>>10))}})();var i=r.j$,s=r.nm,o=r.Xz,a=r.ul,u=r.zo,c=r.zM,h=r.pI,l=r.I4,f=r.Fl,p=r.In,d=r.Cj,g=r.t6,w=r.mh,y=r.LQ,m=r.R2,b=r.rJ,v=r.xI,L=r.$$,A=r.e9,k=r.K2,E=r.ZC,R=r.iv,U=r.d2,S=r.vB,T=r.y1,B=r.Hv,P=r.Ue,F=r.Jx,C=r.cv,x=r.Pi,I=r.um,H=r.sK,N=r.Fw,M=r.zE,Y=r.RU,D=r.Xs,O=r.r1,z=r.Kl,$=r.A7,q=r.px,K=r.ZW,X=r.ti,j=r.bX,V=r.Dc,J=r.fp,W=r.Ye,Z=r.Qc,Q=r.hP,G=r.LU,ee=r.yQ,te=r.Zk,ne=r.uh;export{i as BUFF_0,s as BUFF_COLON,o as BUFF_D,a as BUFF_E,u as BUFF_I,c as BUFF_L,h as BUFF_MINUS,l as BYTE_0,f as BYTE_COLON,p as BYTE_D,d as BYTE_E,g as BYTE_I,w as BYTE_L,y as BYTE_MINUS,m as BlockHasher,b as ChunkSplitter,v as CommonPieceLength,L as DEFAULT_BLOCK_LENGTH,A as MerkleRootCalculator,k as MerkleTreeBalancer,E as PieceHasher,R as TokenType,U as Tokenizer,S as TorrentType,T as compareEntryNames,B as concatUint8Arrays,P as create,F as decode,C as encode,x as getEntriesOfDirEntry,I as getFileOfFileEntry,H as getSortedIndex,N as isDigitByte,M as isFile,Y as isFileSystemDirectoryEntry,D as isFileSystemDirectoryHandle,O as isFileSystemFileEntry,z as isFileSystemFileHandle,$ as isFileTreeDirEntry,q as isFileTreeDirNode,K as isFileTreeFileEntry,X as isFileTreeFileNode,j as iterableSort,V as merkleRoot,J as nextPowerOfTwo,W as packEntriesToDirNode,Z as parse,Q as populateFileTree,G as resolveCommonDirAndTorrentName,ee as useArrayBufferPromiseHook,te as useTextPromiseHook,ne as useUint8ArrayStreamHook};

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.torrefy=t():e.torrefy=t()}(self,(()=>(()=>{"use strict";var e={913:()=>{try{self["workbox:core:6.5.3"]&&_()}catch(e){}},1:()=>{try{self["workbox:streams:6.5.3"]&&_()}catch(e){}},211:(e,t,n)=>{n.r(t),n.d(t,{default:()=>w});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(e,t,n,r){let i,o,s;const a=t||[0],u=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<e.length;i+=1)s=i+u,o=s>>>2,a.length<=o&&a.push(0),a[o]|=e[i]<<8*(c+r*(s%4));return{value:a,binLen:8*e.length+n}}function o(e,t,n){switch(t){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(e,t,r){return function(e,t,n,r){let i,o,s,a;if(0!=e.length%2)throw new Error("String of HEX type must be in byte increments");const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(i=0;i<e.length;i+=2){if(o=parseInt(e.substr(i,2),16),isNaN(o))throw new Error("String of HEX type contains invalid characters");for(a=(i>>>1)+c,s=a>>>2;u.length<=s;)u.push(0);u[s]|=o<<8*(h+r*(a%4))}return{value:u,binLen:4*e.length+n}}(e,t,r,n)};case"TEXT":return function(e,r,i){return function(e,t,n,r,i){let o,s,a,u,c,h,l,f,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===t)for(l=-1===i?3:0,a=0;a<e.length;a+=1)for(o=e.charCodeAt(a),s=[],128>o?s.push(o):2048>o?(s.push(192|o>>>6),s.push(128|63&o)):55296>o||57344<=o?s.push(224|o>>>12,128|o>>>6&63,128|63&o):(a+=1,o=65536+((1023&o)<<10|1023&e.charCodeAt(a)),s.push(240|o>>>18,128|o>>>12&63,128|o>>>6&63,128|63&o)),u=0;u<s.length;u+=1){for(h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=s[u]<<8*(l+i*(h%4)),p+=1}else for(l=-1===i?2:0,f="UTF16LE"===t&&1!==i||"UTF16LE"!==t&&1===i,a=0;a<e.length;a+=1){for(o=e.charCodeAt(a),!0===f&&(u=255&o,o=u<<8|o>>>8),h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=o<<8*(l+i*(h%4)),p+=2}return{value:d,binLen:8*p+r}}(e,t,r,i,n)};case"B64":return function(e,t,i){return function(e,t,n,i){let o,s,a,u,c,h,l,f=0;const p=t||[0],d=(n=n||0)>>>3,g=-1===i?3:0,w=e.indexOf("=");if(-1===e.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(e=e.replace(/=/g,""),-1!==w&&w<e.length)throw new Error("Invalid '=' found in base-64 string");for(s=0;s<e.length;s+=4){for(c=e.substr(s,4),u=0,a=0;a<c.length;a+=1)o=r.indexOf(c.charAt(a)),u|=o<<18-6*a;for(a=0;a<c.length-1;a+=1){for(l=f+d,h=l>>>2;p.length<=h;)p.push(0);p[h]|=(u>>>16-8*a&255)<<8*(g+i*(l%4)),f+=1}}return{value:p,binLen:8*f+n}}(e,t,i,n)};case"BYTES":return function(e,t,r){return function(e,t,n,r){let i,o,s,a;const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(o=0;o<e.length;o+=1)i=e.charCodeAt(o),a=o+c,s=a>>>2,u.length<=s&&u.push(0),u[s]|=i<<8*(h+r*(a%4));return{value:u,binLen:8*e.length+n}}(e,t,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e,t,r){return function(e,t,n,r){return i(new Uint8Array(e),t,n,r)}(e,t,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e,t,r){return i(e,t,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function s(e,t,n,i){switch(e){case"HEX":return function(e){return function(e,t,n,r){const i="0123456789abcdef";let o,s,a="";const u=t/8,c=-1===n?3:0;for(o=0;o<u;o+=1)s=e[o>>>2]>>>8*(c+n*(o%4)),a+=i.charAt(s>>>4&15)+i.charAt(15&s);return r.outputUpper?a.toUpperCase():a}(e,t,n,i)};case"B64":return function(e){return function(e,t,n,i){let o,s,a,u,c,h="";const l=t/8,f=-1===n?3:0;for(o=0;o<l;o+=3)for(u=o+1<l?e[o+1>>>2]:0,c=o+2<l?e[o+2>>>2]:0,a=(e[o>>>2]>>>8*(f+n*(o%4))&255)<<16|(u>>>8*(f+n*((o+1)%4))&255)<<8|c>>>8*(f+n*((o+2)%4))&255,s=0;s<4;s+=1)h+=8*o+6*s<=t?r.charAt(a>>>6*(3-s)&63):i.b64Pad;return h}(e,t,n,i)};case"BYTES":return function(e){return function(e,t,n){let r,i,o="";const s=t/8,a=-1===n?3:0;for(r=0;r<s;r+=1)i=e[r>>>2]>>>8*(a+n*(r%4))&255,o+=String.fromCharCode(i);return o}(e,t,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,o=new ArrayBuffer(i),s=new Uint8Array(o),a=-1===n?3:0;for(r=0;r<i;r+=1)s[r]=e[r>>>2]>>>8*(a+n*(r%4))&255;return o}(e,t,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,o=-1===n?3:0,s=new Uint8Array(i);for(r=0;r<i;r+=1)s[r]=e[r>>>2]>>>8*(o+n*(r%4))&255;return s}(e,t,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function a(e){const t={outputUpper:!1,b64Pad:"=",outputLen:-1},n=e||{},r="Output length must be a multiple of 8";if(t.outputUpper=n.outputUpper||!1,n.b64Pad&&(t.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);t.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);t.outputLen=n.shakeLen}if("boolean"!=typeof t.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof t.b64Pad)throw new Error("Invalid b64Pad formatting option");return t}function u(e,t){return e<<t|e>>>32-t}function c(e,t,n){return e^t^n}function h(e,t,n){return e&t^e&n^t&n}function l(e,t){const n=(65535&e)+(65535&t);return(65535&(e>>>16)+(t>>>16)+(n>>>16))<<16|65535&n}function f(e,t,n,r,i){const o=(65535&e)+(65535&t)+(65535&n)+(65535&r)+(65535&i);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16)+(o>>>16))<<16|65535&o}function p(e){return[1732584193,4023233417,2562383102,271733878,3285377520]}function d(e,t){let n,r,i,o,s,a,p;const d=[];for(n=t[0],r=t[1],i=t[2],o=t[3],s=t[4],p=0;p<80;p+=1)d[p]=p<16?e[p]:u(d[p-3]^d[p-8]^d[p-14]^d[p-16],1),a=p<20?f(u(n,5),(g=r)&i^~g&o,s,1518500249,d[p]):p<40?f(u(n,5),c(r,i,o),s,1859775393,d[p]):p<60?f(u(n,5),h(r,i,o),s,2400959708,d[p]):f(u(n,5),c(r,i,o),s,3395469782,d[p]),s=o,o=i,i=u(r,30),r=n,n=a;var g;return t[0]=l(n,t[0]),t[1]=l(r,t[1]),t[2]=l(i,t[2]),t[3]=l(o,t[3]),t[4]=l(s,t[4]),t}function g(e,t,n,r){let i;const o=15+(t+65>>>9<<4),s=t+n;for(;e.length<=o;)e.push(0);for(e[t>>>5]|=128<<24-t%32,e[o]=4294967295&s,e[o-1]=s/4294967296|0,i=0;i<e.length;i+=16)r=d(e.slice(i,i+16),r);return r}class w extends class{constructor(e,t,n){const r=n||{};if(this.t=t,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=e,this.h=[],this.u=0,this.l=!1,this.A=0,this.p=!1,this.R=[],this.U=[]}update(e){let t,n=0;const r=this.T>>>5,i=this.F(e,this.h,this.u),o=i.binLen,s=i.value,a=o>>>5;for(t=0;t<a;t+=r)n+this.T<=o&&(this.m=this.g(s.slice(t,t+r),this.m),n+=this.T);return this.A+=n,this.h=s.slice(n>>>5),this.u=o%this.T,this.l=!0,this}getHash(e,t){let n,r,i=this.B;const o=a(t);if(this.v){if(-1===o.outputLen)throw new Error("Output length must be specified in options");i=o.outputLen}const u=s(e,i,this.Y,o);if(this.p&&this.H)return u(this.H(o));for(r=this.C(this.h.slice(),this.u,this.A,this.I(this.m),i),n=1;n<this.numRounds;n+=1)this.v&&i%32!=0&&(r[r.length-1]&=16777215>>>24-i%32),r=this.C(r,i,0,this.L(this.o),i);return u(r)}setHMACKey(e,t,n){if(!this.M)throw new Error("Variant does not support HMAC");if(this.l)throw new Error("Cannot set MAC key after calling update");const r=o(t,(n||{}).encoding||"UTF8",this.Y);this.N(r(e))}N(e){const t=this.T>>>3,n=t/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(t<e.binLen/8&&(e.value=this.C(e.value,e.binLen,0,this.L(this.o),this.B));e.value.length<=n;)e.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^e.value[r],this.U[r]=1549556828^e.value[r];this.m=this.g(this.R,this.m),this.A=this.T,this.p=!0}getHMAC(e,t){const n=a(t);return s(e,this.B,this.Y,n)(this.S())}S(){let e;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const t=this.C(this.h.slice(),this.u,this.A,this.I(this.m),this.B);return e=this.g(this.U,this.L(this.o)),e=this.C(t,this.B,this.T,e,this.B),e}}{constructor(e,t,n){if("SHA-1"!==e)throw new Error("Chosen SHA variant is not supported");super(e,t,n);const r=n||{};this.M=!0,this.H=this.S,this.Y=-1,this.F=o(this.t,this.i,this.Y),this.g=d,this.I=function(e){return e.slice()},this.L=p,this.C=g,this.m=[1732584193,4023233417,2562383102,271733878,3285377520],this.T=512,this.B=160,this.v=!1,r.hmacKey&&this.N(function(e,t,n,r){const i="hmacKey must include a value and format";if(!t)throw new Error(i);if(void 0===t.value||!t.format)throw new Error(i);return o(t.format,t.encoding||"UTF8",n)(t.value)}(0,r.hmacKey,this.Y))}}},673:(e,t,n)=>{n.r(t),n.d(t,{default:()=>k});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(e,t,n,r){let i,o,s;const a=t||[0],u=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<e.length;i+=1)s=i+u,o=s>>>2,a.length<=o&&a.push(0),a[o]|=e[i]<<8*(c+r*(s%4));return{value:a,binLen:8*e.length+n}}function o(e,t,n){switch(t){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(e,t,r){return function(e,t,n,r){let i,o,s,a;if(0!=e.length%2)throw new Error("String of HEX type must be in byte increments");const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(i=0;i<e.length;i+=2){if(o=parseInt(e.substr(i,2),16),isNaN(o))throw new Error("String of HEX type contains invalid characters");for(a=(i>>>1)+c,s=a>>>2;u.length<=s;)u.push(0);u[s]|=o<<8*(h+r*(a%4))}return{value:u,binLen:4*e.length+n}}(e,t,r,n)};case"TEXT":return function(e,r,i){return function(e,t,n,r,i){let o,s,a,u,c,h,l,f,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===t)for(l=-1===i?3:0,a=0;a<e.length;a+=1)for(o=e.charCodeAt(a),s=[],128>o?s.push(o):2048>o?(s.push(192|o>>>6),s.push(128|63&o)):55296>o||57344<=o?s.push(224|o>>>12,128|o>>>6&63,128|63&o):(a+=1,o=65536+((1023&o)<<10|1023&e.charCodeAt(a)),s.push(240|o>>>18,128|o>>>12&63,128|o>>>6&63,128|63&o)),u=0;u<s.length;u+=1){for(h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=s[u]<<8*(l+i*(h%4)),p+=1}else for(l=-1===i?2:0,f="UTF16LE"===t&&1!==i||"UTF16LE"!==t&&1===i,a=0;a<e.length;a+=1){for(o=e.charCodeAt(a),!0===f&&(u=255&o,o=u<<8|o>>>8),h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=o<<8*(l+i*(h%4)),p+=2}return{value:d,binLen:8*p+r}}(e,t,r,i,n)};case"B64":return function(e,t,i){return function(e,t,n,i){let o,s,a,u,c,h,l,f=0;const p=t||[0],d=(n=n||0)>>>3,g=-1===i?3:0,w=e.indexOf("=");if(-1===e.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(e=e.replace(/=/g,""),-1!==w&&w<e.length)throw new Error("Invalid '=' found in base-64 string");for(s=0;s<e.length;s+=4){for(c=e.substr(s,4),u=0,a=0;a<c.length;a+=1)o=r.indexOf(c.charAt(a)),u|=o<<18-6*a;for(a=0;a<c.length-1;a+=1){for(l=f+d,h=l>>>2;p.length<=h;)p.push(0);p[h]|=(u>>>16-8*a&255)<<8*(g+i*(l%4)),f+=1}}return{value:p,binLen:8*f+n}}(e,t,i,n)};case"BYTES":return function(e,t,r){return function(e,t,n,r){let i,o,s,a;const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(o=0;o<e.length;o+=1)i=e.charCodeAt(o),a=o+c,s=a>>>2,u.length<=s&&u.push(0),u[s]|=i<<8*(h+r*(a%4));return{value:u,binLen:8*e.length+n}}(e,t,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e,t,r){return function(e,t,n,r){return i(new Uint8Array(e),t,n,r)}(e,t,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e,t,r){return i(e,t,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function s(e,t,n,i){switch(e){case"HEX":return function(e){return function(e,t,n,r){const i="0123456789abcdef";let o,s,a="";const u=t/8,c=-1===n?3:0;for(o=0;o<u;o+=1)s=e[o>>>2]>>>8*(c+n*(o%4)),a+=i.charAt(s>>>4&15)+i.charAt(15&s);return r.outputUpper?a.toUpperCase():a}(e,t,n,i)};case"B64":return function(e){return function(e,t,n,i){let o,s,a,u,c,h="";const l=t/8,f=-1===n?3:0;for(o=0;o<l;o+=3)for(u=o+1<l?e[o+1>>>2]:0,c=o+2<l?e[o+2>>>2]:0,a=(e[o>>>2]>>>8*(f+n*(o%4))&255)<<16|(u>>>8*(f+n*((o+1)%4))&255)<<8|c>>>8*(f+n*((o+2)%4))&255,s=0;s<4;s+=1)h+=8*o+6*s<=t?r.charAt(a>>>6*(3-s)&63):i.b64Pad;return h}(e,t,n,i)};case"BYTES":return function(e){return function(e,t,n){let r,i,o="";const s=t/8,a=-1===n?3:0;for(r=0;r<s;r+=1)i=e[r>>>2]>>>8*(a+n*(r%4))&255,o+=String.fromCharCode(i);return o}(e,t,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,o=new ArrayBuffer(i),s=new Uint8Array(o),a=-1===n?3:0;for(r=0;r<i;r+=1)s[r]=e[r>>>2]>>>8*(a+n*(r%4))&255;return o}(e,t,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,o=-1===n?3:0,s=new Uint8Array(i);for(r=0;r<i;r+=1)s[r]=e[r>>>2]>>>8*(o+n*(r%4))&255;return s}(e,t,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}const a=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],u=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428],c=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];function h(e){const t={outputUpper:!1,b64Pad:"=",outputLen:-1},n=e||{},r="Output length must be a multiple of 8";if(t.outputUpper=n.outputUpper||!1,n.b64Pad&&(t.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);t.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);t.outputLen=n.shakeLen}if("boolean"!=typeof t.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof t.b64Pad)throw new Error("Invalid b64Pad formatting option");return t}function l(e,t){return e>>>t|e<<32-t}function f(e,t){return e>>>t}function p(e,t,n){return e&t^~e&n}function d(e,t,n){return e&t^e&n^t&n}function g(e){return l(e,2)^l(e,13)^l(e,22)}function w(e,t){const n=(65535&e)+(65535&t);return(65535&(e>>>16)+(t>>>16)+(n>>>16))<<16|65535&n}function y(e,t,n,r){const i=(65535&e)+(65535&t)+(65535&n)+(65535&r);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16))<<16|65535&i}function m(e,t,n,r,i){const o=(65535&e)+(65535&t)+(65535&n)+(65535&r)+(65535&i);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16)+(o>>>16))<<16|65535&o}function b(e){return l(e,7)^l(e,18)^f(e,3)}function v(e){return l(e,6)^l(e,11)^l(e,25)}function L(e){let t;return t="SHA-224"==e?u.slice():c.slice(),t}function A(e,t){let n,r,i,o,s,u,c,h,L,A,k;const E=[];for(n=t[0],r=t[1],i=t[2],o=t[3],s=t[4],u=t[5],c=t[6],h=t[7],k=0;k<64;k+=1)E[k]=k<16?e[k]:y(l(R=E[k-2],17)^l(R,19)^f(R,10),E[k-7],b(E[k-15]),E[k-16]),L=m(h,v(s),p(s,u,c),a[k],E[k]),A=w(g(n),d(n,r,i)),h=c,c=u,u=s,s=w(o,L),o=i,i=r,r=n,n=w(L,A);var R;return t[0]=w(n,t[0]),t[1]=w(r,t[1]),t[2]=w(i,t[2]),t[3]=w(o,t[3]),t[4]=w(s,t[4]),t[5]=w(u,t[5]),t[6]=w(c,t[6]),t[7]=w(h,t[7]),t}class k extends class{constructor(e,t,n){const r=n||{};if(this.t=t,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=e,this.h=[],this.u=0,this.A=!1,this.l=0,this.p=!1,this.R=[],this.U=[]}update(e){let t,n=0;const r=this.T>>>5,i=this.F(e,this.h,this.u),o=i.binLen,s=i.value,a=o>>>5;for(t=0;t<a;t+=r)n+this.T<=o&&(this.m=this.g(s.slice(t,t+r),this.m),n+=this.T);return this.l+=n,this.h=s.slice(n>>>5),this.u=o%this.T,this.A=!0,this}getHash(e,t){let n,r,i=this.B;const o=h(t);if(this.H){if(-1===o.outputLen)throw new Error("Output length must be specified in options");i=o.outputLen}const a=s(e,i,this.v,o);if(this.p&&this.Y)return a(this.Y(o));for(r=this.C(this.h.slice(),this.u,this.l,this.S(this.m),i),n=1;n<this.numRounds;n+=1)this.H&&i%32!=0&&(r[r.length-1]&=16777215>>>24-i%32),r=this.C(r,i,0,this.I(this.o),i);return a(r)}setHMACKey(e,t,n){if(!this.L)throw new Error("Variant does not support HMAC");if(this.A)throw new Error("Cannot set MAC key after calling update");const r=o(t,(n||{}).encoding||"UTF8",this.v);this.M(r(e))}M(e){const t=this.T>>>3,n=t/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(t<e.binLen/8&&(e.value=this.C(e.value,e.binLen,0,this.I(this.o),this.B));e.value.length<=n;)e.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^e.value[r],this.U[r]=1549556828^e.value[r];this.m=this.g(this.R,this.m),this.l=this.T,this.p=!0}getHMAC(e,t){const n=h(t);return s(e,this.B,this.v,n)(this.N())}N(){let e;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const t=this.C(this.h.slice(),this.u,this.l,this.S(this.m),this.B);return e=this.g(this.U,this.I(this.o)),e=this.C(t,this.B,this.T,e,this.B),e}}{constructor(e,t,n){if("SHA-224"!==e&&"SHA-256"!==e)throw new Error("Chosen SHA variant is not supported");super(e,t,n);const r=n||{};this.Y=this.N,this.L=!0,this.v=-1,this.F=o(this.t,this.i,this.v),this.g=A,this.S=function(e){return e.slice()},this.I=L,this.C=function(t,n,r,i){return function(e,t,n,r,i){let o,s;const a=15+(t+65>>>9<<4),u=t+n;for(;e.length<=a;)e.push(0);for(e[t>>>5]|=128<<24-t%32,e[a]=4294967295&u,e[a-1]=u/4294967296|0,o=0;o<e.length;o+=16)r=A(e.slice(o,o+16),r);return s="SHA-224"===i?[r[0],r[1],r[2],r[3],r[4],r[5],r[6]]:r,s}(t,n,r,i,e)},this.m=L(e),this.T=512,this.B="SHA-224"===e?224:256,this.H=!1,r.hmacKey&&this.M(function(e,t,n,r){const i="hmacKey must include a value and format";if(!t)throw new Error(i);if(void 0===t.value||!t.format)throw new Error(i);return o(t.format,t.encoding||"UTF8",n)(t.value)}(0,r.hmacKey,this.v))}}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{n.r(r),n.d(r,{BUFF_0:()=>g,BUFF_COLON:()=>l,BUFF_D:()=>o,BUFF_E:()=>a,BUFF_I:()=>c,BUFF_L:()=>t,BUFF_MINUS:()=>p,BYTE_0:()=>d,BYTE_COLON:()=>h,BYTE_D:()=>i,BYTE_E:()=>s,BYTE_I:()=>u,BYTE_L:()=>e,BYTE_MINUS:()=>f,BlockHasher:()=>q,ChunkSplitter:()=>$,CommonPieceLength:()=>Le,DEFAULT_BLOCK_LENGTH:()=>ve,MerkleRootCalculator:()=>K,MerkleTreeBalancer:()=>X,PieceHasher:()=>W,TokenType:()=>B,Tokenizer:()=>F,TorrentType:()=>be,compareEntryNames:()=>me,concatUint8Arrays:()=>b,create:()=>Ue,decode:()=>x,encode:()=>E,getEntriesOfDirEntry:()=>ne,getFileOfFileEntry:()=>re,getSortedIndex:()=>y,isDigitByte:()=>w,isFile:()=>J,isFileSystemDirectoryEntry:()=>G,isFileSystemDirectoryHandle:()=>Q,isFileSystemFileEntry:()=>Z,isFileSystemFileHandle:()=>ee,isFileTreeDirEntry:()=>ye,isFileTreeDirNode:()=>ge,isFileTreeFileEntry:()=>we,isFileTreeFileNode:()=>de,iterableSort:()=>m,merkleRoot:()=>L,nextPowerOfTwo:()=>v,packEntriesToDirNode:()=>fe,parse:()=>C,populateFileTree:()=>le,resolveCommonDirAndTorrentName:()=>he,useArrayBufferPromiseHook:()=>S,useTextPromiseHook:()=>T,useUint8ArrayStreamHook:()=>U});const e=108,t=new Uint8Array([e]),i=100,o=new Uint8Array([i]),s=101,a=new Uint8Array([s]),u=105,c=new Uint8Array([u]),h=58,l=new Uint8Array([h]),f=45,p=new Uint8Array([f]),d=48,g=new Uint8Array([d]);function w(e){return e>=d&&e<=d+9}function y(e,t,n){let r=0,i=e.length;for(;r<i;){const o=r+i>>>1,s=n(e[o],t);if(0===s)return{index:o,result:e[o]};s<0?r=o+1:i=o}return{index:r,result:void 0}}function m(e,t){const n=[];for(const r of e){const{index:e}=y(n,r,t);n.splice(e,0,r)}return n}function b(...e){const t=new Uint8Array(e.reduce(((e,t)=>e+t.byteLength),0));return e.reduce(((e,n)=>(t.set(n,e),e+n.byteLength)),0),t}function v(e){return 1<<32-Math.clz32(e-1)}async function L(e){if(0===e.length)throw new Error("Empty leaves");const t=new Uint8Array(64);for(;e.length>1;){let r=!1;const i=[];for(const o of e)if(r){let e;t.set(o,32);try{e=new Uint8Array(await crypto.subtle.digest("SHA-256",t))}catch{const{default:r}=await Promise.resolve().then(n.bind(n,673)),i=new r("SHA-256","UINT8ARRAY");i.update(t),e=i.getHash("UINT8ARRAY")}i.push(e),r=!1}else t.set(o),r=!0;e=i}return e[0]}const A=new WeakMap;class k{textEncoder=new TextEncoder;textDecoder=new TextDecoder;data;path=[];hooks;consumedHookHandler=new WeakMap;constructor(e,t){this.data=e,this.hooks=t,t&&A.set(t,!0)}start(e){if(this.encode(this.data,e),this.hooks)for(const e of this.hooks.values())this.consumedHookHandler.get(e)||e({value:void 0,done:!0});e.close()}encode(e,n){if(null!=e)if("boolean"==typeof e)this.encode(e?1:0,n);else if("number"==typeof e){const t=Math.round(e);n.enqueue(this.textEncoder.encode(`i${t}e`)),t!==e&&(console.warn(`WARNING: Possible data corruption detected with value "${e}":`,`Bencoding only defines support for integers, value was converted to "${t}"`),console.trace())}else if("bigint"==typeof e)n.enqueue(this.textEncoder.encode(`i${e}e`));else if("string"==typeof e){const t=this.textEncoder.encode(e),r=t.byteLength;n.enqueue(this.textEncoder.encode(`${r}:`)),n.enqueue(t)}else if(e instanceof ArrayBuffer){const t=new Uint8Array(e),r=t.byteLength;n.enqueue(this.textEncoder.encode(`${r}:`)),n.enqueue(t)}else if(Array.isArray(e)){n.enqueue(t);let r=0;for(const t of e){if(this.path.push(r),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0})}else this.encode(t,n)}this.path.pop(),++r}n.enqueue(a)}else if(e instanceof Map){n.enqueue(o);const t=m(e.keys(),((e,t)=>(e="string"==typeof e?e:this.textDecoder.decode(e))<(t="string"==typeof t?t:this.textDecoder.decode(t))?-1:e>t?1:0));for(const r of t){const t=e.get(r);if(void 0!==t&&null!==e)if(r instanceof ArrayBuffer)this.encode(r,n),this.encode(t,n);else{if(this.path.push(r),this.encode(r,n),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0}),this.consumedHookHandler.set(e,!0)}else this.encode(t,n)}this.path.pop()}}n.enqueue(a)}else{n.enqueue(o);const t=Object.keys(e).sort();for(const r of t){const t=e[r];if(void 0!==t&&null!==e){if(this.path.push(r),this.encode(r,n),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0}),this.consumedHookHandler.set(e,!0)}else this.encode(t,n)}this.path.pop()}}n.enqueue(a)}}}function E(e,t){return new ReadableStream(new k(e,t))}function R(e,t){return new Proxy(e,{get:function(e,n,r){return"enqueue"===n?(n=>{e.enqueue(n),t({value:n,done:!1})}).bind(e):Reflect.get(e,n,r)}})}function U(e,t){const n={controller:null},r=new ReadableStream({start(e){n.controller=e},pull(e){A.get(t)||(console.warn("You need to call encode() first and then consume hooks."),e.close(),n.controller=null)}});return t.set(e,(({value:e,done:t})=>{null!==n.controller&&(t?n.controller.close():n.controller.enqueue(e))})),[r]}function S(e,t){const[n]=U(e,t);return[new Response(n).arrayBuffer()]}function T(e,t){const[n]=U(e,t);return[new Response(n).text()]}var B;!function(e){e.Integer="Integer",e.ByteString="ByteString",e.ListStart="ListStart",e.ListEnd="ListEnd",e.DictionaryStart="DictionaryStart",e.DictionaryEnd="DictionaryEnd"}(B||(B={}));class P{endStack=[];token=null;byteStringLength=-1;byteStringOffset=0;transform(e,t){this.tokenize(e,t)}flush(){if(this.endStack.length||this.token||-1!==this.byteStringLength||this.byteStringOffset)throw new SyntaxError("Unexpected end of torrent stream")}tokenize(t,n){if(0!==t.byteLength)if(null===this.token&&-1===this.byteStringLength){const r=t[0];if(r===u)this.token={type:B.Integer,value:new Uint8Array};else if(w(r))this.byteStringLength=r-d;else if(r===e)this.endStack.push(B.ListEnd),n.enqueue({type:B.ListStart});else if(r===i)this.endStack.push(B.DictionaryEnd),n.enqueue({type:B.DictionaryStart});else{if(r!==s)throw new SyntaxError(`Unexpected byte: ${r}`);{const e=this.endStack.pop();if(!e)throw new SyntaxError("Unbalanced delimiter");n.enqueue({type:e})}}this.tokenize(t.subarray(1),n)}else if(this.token&&-1===this.byteStringLength)if(this.token.type===B.Integer){const e=t.indexOf(s);-1===e?this.token.value=this.token.value?b(this.token.value,t):t:(this.token.value=this.token.value?b(this.token.value,t.subarray(0,e)):t.subarray(0,e),n.enqueue(this.token),this.token=null,this.tokenize(t.subarray(e+1),n))}else{if(this.token.type!==B.ByteString)throw new Error("This is a bug");{const e=this.token.value.byteLength-this.byteStringOffset,r=t.byteLength;r<e?(this.token.value.set(t,this.byteStringOffset),this.byteStringOffset+=r):(this.token.value.set(t.subarray(0,e),this.byteStringOffset),this.byteStringOffset=0,n.enqueue(this.token),this.token=null,this.tokenize(t.subarray(e),n))}}else{if(!(this.byteStringLength>-1&&null===this.token))throw new Error("This is a bug");{let e=-1;for(const[n,r]of t.entries()){if(!w(r)){if(r===h){e=n;break}throw new SyntaxError(`Unexpected byte: ${r}`)}this.byteStringLength=10*this.byteStringLength-d+r}-1!==e&&(this.token={type:B.ByteString,value:new Uint8Array(this.byteStringLength)},this.byteStringLength=-1,this.tokenize(t.subarray(e+1),n))}}}}class F extends TransformStream{constructor(){super(new P)}}async function C(e){let t;const n=[],r=e.getReader();let i;for(;;){const{done:e,value:o}=await r.read();if(e)break;const s=n.at(-1);if(s)if(Array.isArray(s))switch(o.type){case B.Integer:s.push(N(o.value));break;case B.ByteString:s.push(H(o.value));break;case B.DictionaryStart:{const e=Object.create(null);s.push(e),n.push(e);break}case B.ListStart:{const e=[];s.push(e),n.push(e);break}case B.ListEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`)}else if(void 0===i)switch(o.type){case B.ByteString:i=H(o.value);break;case B.DictionaryEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`)}else{switch(o.type){case B.Integer:s[i]=N(o.value);break;case B.ByteString:s[i]=H(o.value);break;case B.DictionaryStart:{const e=Object.create(null);s[i]=e,n.push(e);break}case B.ListStart:{const e=[];s[i]=e,n.push(e);break}default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`)}i=void 0}else{if(void 0!==t)throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`);switch(o.type){case B.Integer:t=N(o.value);break;case B.ByteString:t=H(o.value);break;case B.DictionaryStart:{const e=Object.create(null);n.push(e),t=e;break}case B.ListStart:{const e=[];n.push(e),t=e;break}default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`)}}}if(n.length)throw new Error("Unexpected end of token stream");return t}async function x(e){const t=new F,n=e.pipeThrough(t);return await C(n)}function N(e){let t=0,n=!0;for(const[r,i]of e.entries()){if(0===r&&i===f){n=!1;continue}if(1===r&&!n&&i===d)throw new SyntaxError("Negative zero is not a valid integer");if(1===r&&0===t)throw new SyntaxError("Leading zeros are not allowed");if(!w(i))throw new SyntaxError(`Unexpected byte: ${i}`);const e=i-d;(n&&"number"==typeof t&&t>(Number.MAX_SAFE_INTEGER-e)/10||!n&&"number"==typeof t&&t<(Number.MIN_SAFE_INTEGER+e)/10)&&(t=BigInt(t)),t="number"==typeof t?n?10*t+e:10*t-e:n?10n*t+BigInt(e):10n*t-BigInt(e)}return t}function H(e){return(new TextDecoder).decode(e)}n(913);class I extends Error{constructor(e,t){super(((e,...t)=>{let n=e;return t.length>0&&(n+=` :: ${JSON.stringify(t)}`),n})(e,t)),this.name=e,this.details=t}}class M{constructor(){this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t}))}}function Y(e){const t=e.map((e=>Promise.resolve(e).then((e=>function(e){if(e instanceof Response){if(e.body)return e.body.getReader();throw new I("opaque-streams-source",{type:e.type})}return e instanceof ReadableStream?e.getReader():new Response(e).body.getReader()}(e))))),n=new M;let r=0;const i=new ReadableStream({pull(e){return t[r].then((e=>e.read())).then((i=>{if(i.done)return r++,r>=t.length?(e.close(),void n.resolve()):this.pull(e);e.enqueue(i.value)})).catch((e=>{throw n.reject(e),e}))},cancel(){n.resolve()}});return{done:n.promise,stream:i}}n(1);const D=new Uint8Array(32);class O{blockCount=0;merkleLeaves=[];blocksPerPiece;constructor(e){this.blocksPerPiece=e}async transform(e,t){let r;++this.blockCount;try{r=new Uint8Array(await crypto.subtle.digest("SHA-256",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,673)),i=new t("SHA-256","UINT8ARRAY");i.update(e),r=i.getHash("UINT8ARRAY")}this.merkleLeaves.push(r),this.merkleLeaves.length===this.blocksPerPiece&&(t.enqueue(this.merkleLeaves),this.merkleLeaves=[])}flush(e){if(0===this.blockCount)return;let t=0;if(this.blockCount<this.blocksPerPiece)t=v(this.blockCount)-this.blockCount;else{const e=this.blockCount%this.blocksPerPiece;e>0&&(t=this.blocksPerPiece-e)}if(t>0)for(let e=0;e<t;++e)this.merkleLeaves.push(D);this.merkleLeaves.length>0&&e.enqueue(this.merkleLeaves)}}class q extends TransformStream{constructor(e){super(new O(e))}}class z{residuePointer=0;chunkLength;residue;opts;constructor(e,t={padding:!1}){this.chunkLength=e,this.opts=t,this.residue=new Uint8Array(this.chunkLength)}transform(e,t){for(;this.residuePointer+e.byteLength>=this.chunkLength;){const n=this.chunkLength-this.residuePointer;this.residue.set(e.subarray(0,n),this.residuePointer),this.residuePointer=0,t.enqueue(new Uint8Array(this.residue)),e=e.subarray(n)}this.residue.set(e,this.residuePointer),this.residuePointer+=e.byteLength}flush(e){this.residuePointer<=0||(this.opts.padding?(this.residue.set(new Uint8Array(this.chunkLength-this.residuePointer),this.residuePointer),e.enqueue(this.residue)):e.enqueue(this.residue.subarray(0,this.residuePointer)))}}class $ extends TransformStream{constructor(e,t={padding:!1}){super(new z(e,t))}}class _{updateProgress;constructor(e){this.updateProgress=e}async transform(e,t){t.enqueue(await L(e)),this.updateProgress&&await this.updateProgress()}}class K extends TransformStream{constructor(e){super(new _(e))}}class j{leafCount=0;merkleLeaves=[];blocksPerPiece;constructor(e){this.blocksPerPiece=e}transform(e){++this.leafCount,this.merkleLeaves.push(e)}async flush(e){const t=v(this.leafCount)-this.leafCount;if(t>0){const e=await this.padLeafPromise;for(let n=0;n<t;++n)this.merkleLeaves.push(e)}e.enqueue(this.merkleLeaves)}get padLeafPromise(){return L(Array(this.blocksPerPiece).fill(new Uint8Array(32)))}}class X extends TransformStream{constructor(e){super(new j(e))}}class V{updateProgress;constructor(e){this.updateProgress=e}async transform(e,t){let r;try{r=new Uint8Array(await crypto.subtle.digest("SHA-1",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,211)),i=new t("SHA-1","UINT8ARRAY");i.update(e),r=i.getHash("UINT8ARRAY")}t.enqueue(r),this.updateProgress&&await this.updateProgress()}}class W extends TransformStream{constructor(e){super(new V(e))}}function J(e){return e instanceof File}function G(e){return!Q(e)&&!J(e)&&e.isDirectory}function Z(e){return!Q(e)&&!J(e)&&e.isFile}function Q(e){try{if(e instanceof FileSystemHandle&&"directory"===e.kind)return!0}catch(e){}return!1}function ee(e){try{if(e instanceof FileSystemHandle&&"file"===e.kind)return!0}catch(e){}return!1}function te(e){return new Promise(((t,n)=>{e.readEntries(t,n)}))}async function*ne(e){const t=e.createReader();let n=[];do{n=await te(t);for(const e of n)yield e}while(n.length>0)}function re(e){return new Promise(((t,n)=>{e.file(t,n)}))}const ie={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let oe;const se=new Uint8Array(16);function ae(){if(!oe&&(oe="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!oe))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return oe(se)}const ue=[];for(let e=0;e<256;++e)ue.push((e+256).toString(16).slice(1));const ce=function(e,t,n){if(ie.randomUUID&&!t&&!e)return ie.randomUUID();const r=(e=e||{}).random||(e.rng||ae)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return(ue[e[t+0]]+ue[e[t+1]]+ue[e[t+2]]+ue[e[t+3]]+"-"+ue[e[t+4]]+ue[e[t+5]]+"-"+ue[e[t+6]]+ue[e[t+7]]+"-"+ue[e[t+8]]+ue[e[t+9]]+"-"+ue[e[t+10]]+ue[e[t+11]]+ue[e[t+12]]+ue[e[t+13]]+ue[e[t+14]]+ue[e[t+15]]).toLowerCase()}(r)};function he(e,t){if(t.size>1||0===t.size)return{name:e??ce(),commonDir:void 0};const[n,r]=t.entries().next().value;return de(r)?{name:n,commonDir:void 0}:{name:e??n,commonDir:n}}async function le(e,{sort:t=!0,compareFunction:n=me,polyfillWebkitRelativePath:r=!0}={sort:!0,compareFunction:me,polyfillWebkitRelativePath:!0}){let i=0,o=0;const s=new WeakMap,a=new WeakMap,u=new WeakMap,c=["file tree",[]],h=[c];let l=!1;for await(const t of e)await f(t);return{fileTree:fe(c[1],l),traverseTree:function*e(t){if(ge(t))for(const n of t.values())yield*e(n);else yield[t,u.get(t)]},totalFileSize:i,totalFileCount:o};async function f(e){const p=h.at(-1);if(!p)throw new Error("This is a bug");const d=J(e),g=Q(e),w=G(e),m=ee(e),b=Z(e);if(g||w){const r=e.name,{index:i,result:o}=y(p[1],r,n);let s=o;if(we(s))throw new Error("A same name file already exists");if(ye(s)&&g){const t=a.get(s);if(!t||!await e.isSameEntry(t))throw new Error("File system handle not match")}s||(s=[r,[]],t?p[1].splice(i,0,s):p[1].push(s),g&&a.set(s,e)),h.push(s);for await(const t of g?e.values():ne(e))await f(t);s[1]=new Map(s[1]),h.pop()}else if(m||b){const a=e.name,{index:c,result:l}=y(p[1],a,n);let f=l;if(we(f)&&m){const t=s.get(f);if(!t||!await e.isSameEntry(t))throw new Error("A same name file already exists")}if(ye(f))throw new Error("A same name directory already exists");if(f)return;const d=await(m?e.getFile():re(e)),g=d.size;if(r){const e=h.reduce(((e,t,n)=>0===n?e:e+t[0]+"/"),"")+d.name;Object.defineProperty(d,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>e})}const w={"":{length:g}};f=[a,w],t?p[1].splice(c,0,f):p[1].push(f),m&&s.set(f,e),u.set(w,d),i+=g,o+=1}else{if(!d)throw new Error("Unrecognized type of input");{r&&""===e.webkitRelativePath&&Object.defineProperty(e,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>e.name});const s=(e.webkitRelativePath||e.name).split("/"),a=[c];for(const[r,c]of s.entries()){r>=1&&(l=!0);const h=a.at(-1);if(!h)throw new Error("This is a bug");const{index:f,result:p}=y(h[1],c,n);if(r<s.length-1){let e=p;if(we(e))throw new Error("A same name file already exists");e||(e=[c,[]],t?h[1].splice(f,0,e):h[1].push(e)),a.push(e)}else{let n=p;if(ye(n))throw new Error("A same name directory already exists");if(n)return;const r=e.size,s={"":{length:r}};n=[c,s],t?h[1].splice(f,0,n):h[1].push(n),u.set(s,e),i+=r,o+=1}}}}}}function fe(e,t=!1){return t&&pe(e),new Map(e)}function pe(e){for(const t of e)if(ye(t)){const e=t[1];pe(e),t[1]=new Map(e)}}function de(e){return!!e&&""in e}function ge(e){return e instanceof Map}function we(e){return!!e&&""in e[1]}function ye(e){return!!e&&!(""in e[1])}function me(e,t){return e[0]<t?-1:e[0]>t?1:0}var be;!function(e){e.V1="v1",e.V2="v2",e.HYBRID="hybrid"}(be||(be={}));const ve=16384;var Le;!function(e){e[e["16KB"]=16384]="16KB",e[e["32KB"]=32768]="32KB",e[e["64KB"]=65536]="64KB",e[e["128KB"]=131072]="128KB",e[e["256KB"]=262144]="256KB",e[e["512KB"]=524288]="512KB",e[e["1MB"]=1048576]="1MB",e[e["2MB"]=2097152]="2MB",e[e["4MB"]=4194304]="4MB",e[e["8MB"]=8388608]="8MB",e[e["16MB"]=16777216]="16MB",e[e["32MB"]=33554432]="32MB"}(Le||(Le={}));const Ae={type:be.V1,addCreatedBy:!0,addCreationDate:!0,addPaddingFiles:!1,blockLength:ve,pieceLength:NaN,sortFiles:!0,isPrivate:!1},ke={type:be.V2,addCreatedBy:!0,addCreationDate:!0,blockLength:ve,pieceLength:NaN,metaVersion:2,isPrivate:!1},Ee={type:be.HYBRID,addCreatedBy:!0,addCreationDate:!0,blockLength:ve,pieceLength:NaN,metaVersion:2,isPrivate:!1};function Re(e,t){let n=0;for(const r of e)n+=Math.ceil(r.size/t);return n}async function Ue(e,t={type:be.V1},n){switch(t.type){case be.V1:return await async function(e,t,n){const r={...Ae,...t},{fileTree:i,traverseTree:o,totalFileCount:s,totalFileSize:a}=await le(e,{sort:r.sortFiles});if(0===s)return;const u=[];for(const[,e]of o(i))u.push(e);isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),0!=(r.pieceLength&r.pieceLength-1)&&console.warn(`piece length ${r.pieceLength} is not a power of 2`),r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const[c,h]=Pe(0,n),{commonDir:l,name:f}=he(r.name,i);let p;if(r.name=f,r.addPaddingFiles){const e=Re(u,r.pieceLength);await h(e);const t=[],n=s-1;for(let e=n;e>=0;--e){const i=u[e];if(t.unshift(Promise.resolve(Te(i.stream(),{pieceLength:r.pieceLength,padding:e!==n,updateProgress:c}))),e===n)continue;const o=i.size%r.pieceLength;if(0===o)continue;const s=Be(r.pieceLength-o,l);u.splice(e+1,0,s)}p=Y(t).stream}else{const e=Math.ceil(a/r.pieceLength);await h(e);const{stream:t}=Y(u.map((e=>Promise.resolve(e.stream()))));p=Te(t,{pieceLength:r.pieceLength,padding:!1,updateProgress:c})}return{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.5"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{...s>1?{files:u.map((e=>{const t=(e.webkitRelativePath||e.name).split("/");return void 0!==l&&t.shift(),{...e.padding?{attr:"p"}:{},length:e.size,path:t}}))}:{length:a},name:r.name,"piece length":r.pieceLength,pieces:await new Response(p).arrayBuffer(),...r.isPrivate?{private:!0}:{}}}}(e,t,n);case be.V2:return await async function(e,t,n){const r={...ke,...t},{fileTree:i,traverseTree:o,totalFileCount:s,totalFileSize:a}=await le(e);if(0===s)return;const u=[],c=[];for(const[e,t]of o(i))u.push(t),c.push([e,t]);if(isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),r.pieceLength<r.blockLength)throw new Error(`piece length ${r.pieceLength} is smaller than block length ${r.blockLength}`);if(0!=(r.pieceLength&r.pieceLength-1))throw new Error(`piece length ${r.pieceLength} is not a power of 2`);const h=r.pieceLength/r.blockLength;r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const l=Re(u,r.pieceLength),[f]=Pe(l,n),{name:p}=he(r.name,i);r.name=p;const d=new Map;return await Promise.all(c.map((async([e,t])=>{await Se(t.stream(),d,e,{blockLength:r.blockLength,pieceLength:r.pieceLength,blocksPerPiece:h,updateProgress:f})}))),{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.5"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{"file tree":i,"meta version":r.metaVersion,name:r.name,"piece length":r.pieceLength,...r.isPrivate?{private:!0}:{}},"piece layers":d}}(e,t,n);case be.HYBRID:return await async function(e,t,n){const r={...Ee,...t},{fileTree:i,traverseTree:o,totalFileCount:s,totalFileSize:a}=await le(e);if(0===s)return;const u=[],c=[];for(const[e,t]of o(i))u.push(t),c.push([e,t]);if(isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),r.pieceLength<r.blockLength)throw new Error(`piece length ${r.pieceLength} is smaller than block length ${r.blockLength}`);if(0!=(r.pieceLength&r.pieceLength-1))throw new Error(`piece length ${r.pieceLength} is not a power of 2`);const h=r.pieceLength/r.blockLength;r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const[l]=Pe(2*Re(u,r.pieceLength),n),{commonDir:f,name:p}=he(r.name,i);r.name=p;const d=new Map,g=[],w=s-1;let y=-1;for(const[e,t]of c){++y;const[n,i]=t.stream().tee();if(g.unshift(Promise.resolve(Te(n,{pieceLength:r.pieceLength,padding:y!==w,updateProgress:l}))),await Se(i,d,e,{blockLength:r.blockLength,pieceLength:r.pieceLength,blocksPerPiece:h,updateProgress:l}),y===w)break;const o=t.size%r.pieceLength;if(0===o)continue;const s=Be(r.pieceLength-o,f);u.splice(y+1,0,s)}const m=Y(g).stream;return{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.5"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{"file tree":i,...s>1?{files:u.map((e=>{const t=(e.webkitRelativePath||e.name).split("/");return void 0!==f&&t.shift(),{...e.padding?{attr:"p"}:{},length:e.size,path:t}}))}:{length:a},"meta version":r.metaVersion,name:r.name,"piece length":r.pieceLength,pieces:await new Response(m).arrayBuffer(),...r.isPrivate?{private:!0}:{}},"piece layers":d}}(e,t,n)}}async function Se(e,t,n,r){const{piecesRootReadableStream:i,pieceLayerReadableStream:o}=function(e,t){const n=e.pipeThrough(new $(t.blockLength)).pipeThrough(new q(t.blocksPerPiece)).pipeThrough(new K(t.updateProgress)),[r,i]=n.tee();return{piecesRootReadableStream:i.pipeThrough(new X(t.blocksPerPiece)).pipeThrough(new K),pieceLayerReadableStream:r}}(e,r),s=new Response(i).arrayBuffer();if(n[""].length>r.pieceLength){const e=new Response(o).arrayBuffer();t.set(await s,await e)}n[""].length>0&&(n[""]["pieces root"]=await s)}function Te(e,t){return e.pipeThrough(new $(t.pieceLength,{padding:t.padding})).pipeThrough(new W(t.updateProgress))}function Be(e,t){const n=new File([new ArrayBuffer(e)],`${e}`,{type:"application/octet-stream"}),r=`.pad/${e}`,i=void 0===t?r:`${t}/${r}`;return Object.defineProperties(n,{webkitRelativePath:{configurable:!0,enumerable:!0,get:()=>i},padding:{configurable:!0,enumerable:!1,get:()=>!0}}),n}function Pe(e,t){const n={current:0,total:e};return[async()=>{t&&await t(++n.current,n.total)},async e=>{n.total="number"==typeof e?e:await e(n.total,n.current)}]}function Fe(e){if(void 0===e)return;const t=[];for(const n of e)0!==n.length&&t.push(n);return 0!==t.length?t:void 0}function Ce(e,t){return Math.max(t,v(e>>>10))}})(),r})()));
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.torrefy=t():e.torrefy=t()}(self,(()=>(()=>{"use strict";var e={913:()=>{try{self["workbox:core:6.5.3"]&&_()}catch(e){}},1:()=>{try{self["workbox:streams:6.5.3"]&&_()}catch(e){}},211:(e,t,n)=>{n.r(t),n.d(t,{default:()=>w});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(e,t,n,r){let i,o,s;const a=t||[0],u=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<e.length;i+=1)s=i+u,o=s>>>2,a.length<=o&&a.push(0),a[o]|=e[i]<<8*(c+r*(s%4));return{value:a,binLen:8*e.length+n}}function o(e,t,n){switch(t){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(e,t,r){return function(e,t,n,r){let i,o,s,a;if(0!=e.length%2)throw new Error("String of HEX type must be in byte increments");const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(i=0;i<e.length;i+=2){if(o=parseInt(e.substr(i,2),16),isNaN(o))throw new Error("String of HEX type contains invalid characters");for(a=(i>>>1)+c,s=a>>>2;u.length<=s;)u.push(0);u[s]|=o<<8*(h+r*(a%4))}return{value:u,binLen:4*e.length+n}}(e,t,r,n)};case"TEXT":return function(e,r,i){return function(e,t,n,r,i){let o,s,a,u,c,h,l,f,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===t)for(l=-1===i?3:0,a=0;a<e.length;a+=1)for(o=e.charCodeAt(a),s=[],128>o?s.push(o):2048>o?(s.push(192|o>>>6),s.push(128|63&o)):55296>o||57344<=o?s.push(224|o>>>12,128|o>>>6&63,128|63&o):(a+=1,o=65536+((1023&o)<<10|1023&e.charCodeAt(a)),s.push(240|o>>>18,128|o>>>12&63,128|o>>>6&63,128|63&o)),u=0;u<s.length;u+=1){for(h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=s[u]<<8*(l+i*(h%4)),p+=1}else for(l=-1===i?2:0,f="UTF16LE"===t&&1!==i||"UTF16LE"!==t&&1===i,a=0;a<e.length;a+=1){for(o=e.charCodeAt(a),!0===f&&(u=255&o,o=u<<8|o>>>8),h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=o<<8*(l+i*(h%4)),p+=2}return{value:d,binLen:8*p+r}}(e,t,r,i,n)};case"B64":return function(e,t,i){return function(e,t,n,i){let o,s,a,u,c,h,l,f=0;const p=t||[0],d=(n=n||0)>>>3,g=-1===i?3:0,w=e.indexOf("=");if(-1===e.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(e=e.replace(/=/g,""),-1!==w&&w<e.length)throw new Error("Invalid '=' found in base-64 string");for(s=0;s<e.length;s+=4){for(c=e.substr(s,4),u=0,a=0;a<c.length;a+=1)o=r.indexOf(c.charAt(a)),u|=o<<18-6*a;for(a=0;a<c.length-1;a+=1){for(l=f+d,h=l>>>2;p.length<=h;)p.push(0);p[h]|=(u>>>16-8*a&255)<<8*(g+i*(l%4)),f+=1}}return{value:p,binLen:8*f+n}}(e,t,i,n)};case"BYTES":return function(e,t,r){return function(e,t,n,r){let i,o,s,a;const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(o=0;o<e.length;o+=1)i=e.charCodeAt(o),a=o+c,s=a>>>2,u.length<=s&&u.push(0),u[s]|=i<<8*(h+r*(a%4));return{value:u,binLen:8*e.length+n}}(e,t,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e,t,r){return function(e,t,n,r){return i(new Uint8Array(e),t,n,r)}(e,t,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e,t,r){return i(e,t,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function s(e,t,n,i){switch(e){case"HEX":return function(e){return function(e,t,n,r){const i="0123456789abcdef";let o,s,a="";const u=t/8,c=-1===n?3:0;for(o=0;o<u;o+=1)s=e[o>>>2]>>>8*(c+n*(o%4)),a+=i.charAt(s>>>4&15)+i.charAt(15&s);return r.outputUpper?a.toUpperCase():a}(e,t,n,i)};case"B64":return function(e){return function(e,t,n,i){let o,s,a,u,c,h="";const l=t/8,f=-1===n?3:0;for(o=0;o<l;o+=3)for(u=o+1<l?e[o+1>>>2]:0,c=o+2<l?e[o+2>>>2]:0,a=(e[o>>>2]>>>8*(f+n*(o%4))&255)<<16|(u>>>8*(f+n*((o+1)%4))&255)<<8|c>>>8*(f+n*((o+2)%4))&255,s=0;s<4;s+=1)h+=8*o+6*s<=t?r.charAt(a>>>6*(3-s)&63):i.b64Pad;return h}(e,t,n,i)};case"BYTES":return function(e){return function(e,t,n){let r,i,o="";const s=t/8,a=-1===n?3:0;for(r=0;r<s;r+=1)i=e[r>>>2]>>>8*(a+n*(r%4))&255,o+=String.fromCharCode(i);return o}(e,t,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,o=new ArrayBuffer(i),s=new Uint8Array(o),a=-1===n?3:0;for(r=0;r<i;r+=1)s[r]=e[r>>>2]>>>8*(a+n*(r%4))&255;return o}(e,t,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,o=-1===n?3:0,s=new Uint8Array(i);for(r=0;r<i;r+=1)s[r]=e[r>>>2]>>>8*(o+n*(r%4))&255;return s}(e,t,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function a(e){const t={outputUpper:!1,b64Pad:"=",outputLen:-1},n=e||{},r="Output length must be a multiple of 8";if(t.outputUpper=n.outputUpper||!1,n.b64Pad&&(t.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);t.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);t.outputLen=n.shakeLen}if("boolean"!=typeof t.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof t.b64Pad)throw new Error("Invalid b64Pad formatting option");return t}function u(e,t){return e<<t|e>>>32-t}function c(e,t,n){return e^t^n}function h(e,t,n){return e&t^e&n^t&n}function l(e,t){const n=(65535&e)+(65535&t);return(65535&(e>>>16)+(t>>>16)+(n>>>16))<<16|65535&n}function f(e,t,n,r,i){const o=(65535&e)+(65535&t)+(65535&n)+(65535&r)+(65535&i);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16)+(o>>>16))<<16|65535&o}function p(e){return[1732584193,4023233417,2562383102,271733878,3285377520]}function d(e,t){let n,r,i,o,s,a,p;const d=[];for(n=t[0],r=t[1],i=t[2],o=t[3],s=t[4],p=0;p<80;p+=1)d[p]=p<16?e[p]:u(d[p-3]^d[p-8]^d[p-14]^d[p-16],1),a=p<20?f(u(n,5),(g=r)&i^~g&o,s,1518500249,d[p]):p<40?f(u(n,5),c(r,i,o),s,1859775393,d[p]):p<60?f(u(n,5),h(r,i,o),s,2400959708,d[p]):f(u(n,5),c(r,i,o),s,3395469782,d[p]),s=o,o=i,i=u(r,30),r=n,n=a;var g;return t[0]=l(n,t[0]),t[1]=l(r,t[1]),t[2]=l(i,t[2]),t[3]=l(o,t[3]),t[4]=l(s,t[4]),t}function g(e,t,n,r){let i;const o=15+(t+65>>>9<<4),s=t+n;for(;e.length<=o;)e.push(0);for(e[t>>>5]|=128<<24-t%32,e[o]=4294967295&s,e[o-1]=s/4294967296|0,i=0;i<e.length;i+=16)r=d(e.slice(i,i+16),r);return r}class w extends class{constructor(e,t,n){const r=n||{};if(this.t=t,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=e,this.h=[],this.u=0,this.l=!1,this.A=0,this.p=!1,this.R=[],this.U=[]}update(e){let t,n=0;const r=this.T>>>5,i=this.F(e,this.h,this.u),o=i.binLen,s=i.value,a=o>>>5;for(t=0;t<a;t+=r)n+this.T<=o&&(this.m=this.g(s.slice(t,t+r),this.m),n+=this.T);return this.A+=n,this.h=s.slice(n>>>5),this.u=o%this.T,this.l=!0,this}getHash(e,t){let n,r,i=this.B;const o=a(t);if(this.v){if(-1===o.outputLen)throw new Error("Output length must be specified in options");i=o.outputLen}const u=s(e,i,this.Y,o);if(this.p&&this.H)return u(this.H(o));for(r=this.C(this.h.slice(),this.u,this.A,this.I(this.m),i),n=1;n<this.numRounds;n+=1)this.v&&i%32!=0&&(r[r.length-1]&=16777215>>>24-i%32),r=this.C(r,i,0,this.L(this.o),i);return u(r)}setHMACKey(e,t,n){if(!this.M)throw new Error("Variant does not support HMAC");if(this.l)throw new Error("Cannot set MAC key after calling update");const r=o(t,(n||{}).encoding||"UTF8",this.Y);this.N(r(e))}N(e){const t=this.T>>>3,n=t/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(t<e.binLen/8&&(e.value=this.C(e.value,e.binLen,0,this.L(this.o),this.B));e.value.length<=n;)e.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^e.value[r],this.U[r]=1549556828^e.value[r];this.m=this.g(this.R,this.m),this.A=this.T,this.p=!0}getHMAC(e,t){const n=a(t);return s(e,this.B,this.Y,n)(this.S())}S(){let e;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const t=this.C(this.h.slice(),this.u,this.A,this.I(this.m),this.B);return e=this.g(this.U,this.L(this.o)),e=this.C(t,this.B,this.T,e,this.B),e}}{constructor(e,t,n){if("SHA-1"!==e)throw new Error("Chosen SHA variant is not supported");super(e,t,n);const r=n||{};this.M=!0,this.H=this.S,this.Y=-1,this.F=o(this.t,this.i,this.Y),this.g=d,this.I=function(e){return e.slice()},this.L=p,this.C=g,this.m=[1732584193,4023233417,2562383102,271733878,3285377520],this.T=512,this.B=160,this.v=!1,r.hmacKey&&this.N(function(e,t,n,r){const i="hmacKey must include a value and format";if(!t)throw new Error(i);if(void 0===t.value||!t.format)throw new Error(i);return o(t.format,t.encoding||"UTF8",n)(t.value)}(0,r.hmacKey,this.Y))}}},673:(e,t,n)=>{n.r(t),n.d(t,{default:()=>k});const r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function i(e,t,n,r){let i,o,s;const a=t||[0],u=(n=n||0)>>>3,c=-1===r?3:0;for(i=0;i<e.length;i+=1)s=i+u,o=s>>>2,a.length<=o&&a.push(0),a[o]|=e[i]<<8*(c+r*(s%4));return{value:a,binLen:8*e.length+n}}function o(e,t,n){switch(t){case"UTF8":case"UTF16BE":case"UTF16LE":break;default:throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE")}switch(e){case"HEX":return function(e,t,r){return function(e,t,n,r){let i,o,s,a;if(0!=e.length%2)throw new Error("String of HEX type must be in byte increments");const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(i=0;i<e.length;i+=2){if(o=parseInt(e.substr(i,2),16),isNaN(o))throw new Error("String of HEX type contains invalid characters");for(a=(i>>>1)+c,s=a>>>2;u.length<=s;)u.push(0);u[s]|=o<<8*(h+r*(a%4))}return{value:u,binLen:4*e.length+n}}(e,t,r,n)};case"TEXT":return function(e,r,i){return function(e,t,n,r,i){let o,s,a,u,c,h,l,f,p=0;const d=n||[0],g=(r=r||0)>>>3;if("UTF8"===t)for(l=-1===i?3:0,a=0;a<e.length;a+=1)for(o=e.charCodeAt(a),s=[],128>o?s.push(o):2048>o?(s.push(192|o>>>6),s.push(128|63&o)):55296>o||57344<=o?s.push(224|o>>>12,128|o>>>6&63,128|63&o):(a+=1,o=65536+((1023&o)<<10|1023&e.charCodeAt(a)),s.push(240|o>>>18,128|o>>>12&63,128|o>>>6&63,128|63&o)),u=0;u<s.length;u+=1){for(h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=s[u]<<8*(l+i*(h%4)),p+=1}else for(l=-1===i?2:0,f="UTF16LE"===t&&1!==i||"UTF16LE"!==t&&1===i,a=0;a<e.length;a+=1){for(o=e.charCodeAt(a),!0===f&&(u=255&o,o=u<<8|o>>>8),h=p+g,c=h>>>2;d.length<=c;)d.push(0);d[c]|=o<<8*(l+i*(h%4)),p+=2}return{value:d,binLen:8*p+r}}(e,t,r,i,n)};case"B64":return function(e,t,i){return function(e,t,n,i){let o,s,a,u,c,h,l,f=0;const p=t||[0],d=(n=n||0)>>>3,g=-1===i?3:0,w=e.indexOf("=");if(-1===e.search(/^[a-zA-Z0-9=+/]+$/))throw new Error("Invalid character in base-64 string");if(e=e.replace(/=/g,""),-1!==w&&w<e.length)throw new Error("Invalid '=' found in base-64 string");for(s=0;s<e.length;s+=4){for(c=e.substr(s,4),u=0,a=0;a<c.length;a+=1)o=r.indexOf(c.charAt(a)),u|=o<<18-6*a;for(a=0;a<c.length-1;a+=1){for(l=f+d,h=l>>>2;p.length<=h;)p.push(0);p[h]|=(u>>>16-8*a&255)<<8*(g+i*(l%4)),f+=1}}return{value:p,binLen:8*f+n}}(e,t,i,n)};case"BYTES":return function(e,t,r){return function(e,t,n,r){let i,o,s,a;const u=t||[0],c=(n=n||0)>>>3,h=-1===r?3:0;for(o=0;o<e.length;o+=1)i=e.charCodeAt(o),a=o+c,s=a>>>2,u.length<=s&&u.push(0),u[s]|=i<<8*(h+r*(a%4));return{value:u,binLen:8*e.length+n}}(e,t,r,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e,t,r){return function(e,t,n,r){return i(new Uint8Array(e),t,n,r)}(e,t,r,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e,t,r){return i(e,t,r,n)};default:throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}function s(e,t,n,i){switch(e){case"HEX":return function(e){return function(e,t,n,r){const i="0123456789abcdef";let o,s,a="";const u=t/8,c=-1===n?3:0;for(o=0;o<u;o+=1)s=e[o>>>2]>>>8*(c+n*(o%4)),a+=i.charAt(s>>>4&15)+i.charAt(15&s);return r.outputUpper?a.toUpperCase():a}(e,t,n,i)};case"B64":return function(e){return function(e,t,n,i){let o,s,a,u,c,h="";const l=t/8,f=-1===n?3:0;for(o=0;o<l;o+=3)for(u=o+1<l?e[o+1>>>2]:0,c=o+2<l?e[o+2>>>2]:0,a=(e[o>>>2]>>>8*(f+n*(o%4))&255)<<16|(u>>>8*(f+n*((o+1)%4))&255)<<8|c>>>8*(f+n*((o+2)%4))&255,s=0;s<4;s+=1)h+=8*o+6*s<=t?r.charAt(a>>>6*(3-s)&63):i.b64Pad;return h}(e,t,n,i)};case"BYTES":return function(e){return function(e,t,n){let r,i,o="";const s=t/8,a=-1===n?3:0;for(r=0;r<s;r+=1)i=e[r>>>2]>>>8*(a+n*(r%4))&255,o+=String.fromCharCode(i);return o}(e,t,n)};case"ARRAYBUFFER":try{new ArrayBuffer(0)}catch(e){throw new Error("ARRAYBUFFER not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,o=new ArrayBuffer(i),s=new Uint8Array(o),a=-1===n?3:0;for(r=0;r<i;r+=1)s[r]=e[r>>>2]>>>8*(a+n*(r%4))&255;return o}(e,t,n)};case"UINT8ARRAY":try{new Uint8Array(0)}catch(e){throw new Error("UINT8ARRAY not supported by this environment")}return function(e){return function(e,t,n){let r;const i=t/8,o=-1===n?3:0,s=new Uint8Array(i);for(r=0;r<i;r+=1)s[r]=e[r>>>2]>>>8*(o+n*(r%4))&255;return s}(e,t,n)};default:throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY")}}const a=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],u=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428],c=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225];function h(e){const t={outputUpper:!1,b64Pad:"=",outputLen:-1},n=e||{},r="Output length must be a multiple of 8";if(t.outputUpper=n.outputUpper||!1,n.b64Pad&&(t.b64Pad=n.b64Pad),n.outputLen){if(n.outputLen%8!=0)throw new Error(r);t.outputLen=n.outputLen}else if(n.shakeLen){if(n.shakeLen%8!=0)throw new Error(r);t.outputLen=n.shakeLen}if("boolean"!=typeof t.outputUpper)throw new Error("Invalid outputUpper formatting option");if("string"!=typeof t.b64Pad)throw new Error("Invalid b64Pad formatting option");return t}function l(e,t){return e>>>t|e<<32-t}function f(e,t){return e>>>t}function p(e,t,n){return e&t^~e&n}function d(e,t,n){return e&t^e&n^t&n}function g(e){return l(e,2)^l(e,13)^l(e,22)}function w(e,t){const n=(65535&e)+(65535&t);return(65535&(e>>>16)+(t>>>16)+(n>>>16))<<16|65535&n}function y(e,t,n,r){const i=(65535&e)+(65535&t)+(65535&n)+(65535&r);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16))<<16|65535&i}function m(e,t,n,r,i){const o=(65535&e)+(65535&t)+(65535&n)+(65535&r)+(65535&i);return(65535&(e>>>16)+(t>>>16)+(n>>>16)+(r>>>16)+(i>>>16)+(o>>>16))<<16|65535&o}function b(e){return l(e,7)^l(e,18)^f(e,3)}function v(e){return l(e,6)^l(e,11)^l(e,25)}function L(e){let t;return t="SHA-224"==e?u.slice():c.slice(),t}function A(e,t){let n,r,i,o,s,u,c,h,L,A,k;const E=[];for(n=t[0],r=t[1],i=t[2],o=t[3],s=t[4],u=t[5],c=t[6],h=t[7],k=0;k<64;k+=1)E[k]=k<16?e[k]:y(l(R=E[k-2],17)^l(R,19)^f(R,10),E[k-7],b(E[k-15]),E[k-16]),L=m(h,v(s),p(s,u,c),a[k],E[k]),A=w(g(n),d(n,r,i)),h=c,c=u,u=s,s=w(o,L),o=i,i=r,r=n,n=w(L,A);var R;return t[0]=w(n,t[0]),t[1]=w(r,t[1]),t[2]=w(i,t[2]),t[3]=w(o,t[3]),t[4]=w(s,t[4]),t[5]=w(u,t[5]),t[6]=w(c,t[6]),t[7]=w(h,t[7]),t}class k extends class{constructor(e,t,n){const r=n||{};if(this.t=t,this.i=r.encoding||"UTF8",this.numRounds=r.numRounds||1,isNaN(this.numRounds)||this.numRounds!==parseInt(this.numRounds,10)||1>this.numRounds)throw new Error("numRounds must a integer >= 1");this.o=e,this.h=[],this.u=0,this.A=!1,this.l=0,this.p=!1,this.R=[],this.U=[]}update(e){let t,n=0;const r=this.T>>>5,i=this.F(e,this.h,this.u),o=i.binLen,s=i.value,a=o>>>5;for(t=0;t<a;t+=r)n+this.T<=o&&(this.m=this.g(s.slice(t,t+r),this.m),n+=this.T);return this.l+=n,this.h=s.slice(n>>>5),this.u=o%this.T,this.A=!0,this}getHash(e,t){let n,r,i=this.B;const o=h(t);if(this.H){if(-1===o.outputLen)throw new Error("Output length must be specified in options");i=o.outputLen}const a=s(e,i,this.v,o);if(this.p&&this.Y)return a(this.Y(o));for(r=this.C(this.h.slice(),this.u,this.l,this.S(this.m),i),n=1;n<this.numRounds;n+=1)this.H&&i%32!=0&&(r[r.length-1]&=16777215>>>24-i%32),r=this.C(r,i,0,this.I(this.o),i);return a(r)}setHMACKey(e,t,n){if(!this.L)throw new Error("Variant does not support HMAC");if(this.A)throw new Error("Cannot set MAC key after calling update");const r=o(t,(n||{}).encoding||"UTF8",this.v);this.M(r(e))}M(e){const t=this.T>>>3,n=t/4-1;let r;if(1!==this.numRounds)throw new Error("Cannot set numRounds with MAC");if(this.p)throw new Error("MAC key already set");for(t<e.binLen/8&&(e.value=this.C(e.value,e.binLen,0,this.I(this.o),this.B));e.value.length<=n;)e.value.push(0);for(r=0;r<=n;r+=1)this.R[r]=909522486^e.value[r],this.U[r]=1549556828^e.value[r];this.m=this.g(this.R,this.m),this.l=this.T,this.p=!0}getHMAC(e,t){const n=h(t);return s(e,this.B,this.v,n)(this.N())}N(){let e;if(!this.p)throw new Error("Cannot call getHMAC without first setting MAC key");const t=this.C(this.h.slice(),this.u,this.l,this.S(this.m),this.B);return e=this.g(this.U,this.I(this.o)),e=this.C(t,this.B,this.T,e,this.B),e}}{constructor(e,t,n){if("SHA-224"!==e&&"SHA-256"!==e)throw new Error("Chosen SHA variant is not supported");super(e,t,n);const r=n||{};this.Y=this.N,this.L=!0,this.v=-1,this.F=o(this.t,this.i,this.v),this.g=A,this.S=function(e){return e.slice()},this.I=L,this.C=function(t,n,r,i){return function(e,t,n,r,i){let o,s;const a=15+(t+65>>>9<<4),u=t+n;for(;e.length<=a;)e.push(0);for(e[t>>>5]|=128<<24-t%32,e[a]=4294967295&u,e[a-1]=u/4294967296|0,o=0;o<e.length;o+=16)r=A(e.slice(o,o+16),r);return s="SHA-224"===i?[r[0],r[1],r[2],r[3],r[4],r[5],r[6]]:r,s}(t,n,r,i,e)},this.m=L(e),this.T=512,this.B="SHA-224"===e?224:256,this.H=!1,r.hmacKey&&this.M(function(e,t,n,r){const i="hmacKey must include a value and format";if(!t)throw new Error(i);if(void 0===t.value||!t.format)throw new Error(i);return o(t.format,t.encoding||"UTF8",n)(t.value)}(0,r.hmacKey,this.v))}}}},t={};function n(r){var i=t[r];if(void 0!==i)return i.exports;var o=t[r]={exports:{}};return e[r](o,o.exports,n),o.exports}n.d=(e,t)=>{for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{n.r(r),n.d(r,{BUFF_0:()=>g,BUFF_COLON:()=>l,BUFF_D:()=>o,BUFF_E:()=>a,BUFF_I:()=>c,BUFF_L:()=>t,BUFF_MINUS:()=>p,BYTE_0:()=>d,BYTE_COLON:()=>h,BYTE_D:()=>i,BYTE_E:()=>s,BYTE_I:()=>u,BYTE_L:()=>e,BYTE_MINUS:()=>f,BlockHasher:()=>q,ChunkSplitter:()=>$,CommonPieceLength:()=>Le,DEFAULT_BLOCK_LENGTH:()=>ve,MerkleRootCalculator:()=>K,MerkleTreeBalancer:()=>X,PieceHasher:()=>W,TokenType:()=>B,Tokenizer:()=>F,TorrentType:()=>be,compareEntryNames:()=>me,concatUint8Arrays:()=>b,create:()=>Ue,decode:()=>x,encode:()=>E,getEntriesOfDirEntry:()=>ne,getFileOfFileEntry:()=>re,getSortedIndex:()=>y,isDigitByte:()=>w,isFile:()=>J,isFileSystemDirectoryEntry:()=>G,isFileSystemDirectoryHandle:()=>Q,isFileSystemFileEntry:()=>Z,isFileSystemFileHandle:()=>ee,isFileTreeDirEntry:()=>ye,isFileTreeDirNode:()=>ge,isFileTreeFileEntry:()=>we,isFileTreeFileNode:()=>de,iterableSort:()=>m,merkleRoot:()=>L,nextPowerOfTwo:()=>v,packEntriesToDirNode:()=>fe,parse:()=>C,populateFileTree:()=>le,resolveCommonDirAndTorrentName:()=>he,useArrayBufferPromiseHook:()=>S,useTextPromiseHook:()=>T,useUint8ArrayStreamHook:()=>U});const e=108,t=new Uint8Array([e]),i=100,o=new Uint8Array([i]),s=101,a=new Uint8Array([s]),u=105,c=new Uint8Array([u]),h=58,l=new Uint8Array([h]),f=45,p=new Uint8Array([f]),d=48,g=new Uint8Array([d]);function w(e){return e>=d&&e<=d+9}function y(e,t,n){let r=0,i=e.length;for(;r<i;){const o=r+i>>>1,s=n(e[o],t);if(0===s)return{index:o,result:e[o]};s<0?r=o+1:i=o}return{index:r,result:void 0}}function m(e,t){const n=[];for(const r of e){const{index:e}=y(n,r,t);n.splice(e,0,r)}return n}function b(...e){const t=new Uint8Array(e.reduce(((e,t)=>e+t.byteLength),0));return e.reduce(((e,n)=>(t.set(n,e),e+n.byteLength)),0),t}function v(e){return 1<<32-Math.clz32(e-1)}async function L(e){if(0===e.length)throw new Error("Empty leaves");const t=new Uint8Array(64);for(;e.length>1;){let r=!1;const i=[];for(const o of e)if(r){let e;t.set(o,32);try{e=new Uint8Array(await crypto.subtle.digest("SHA-256",t))}catch{const{default:r}=await Promise.resolve().then(n.bind(n,673)),i=new r("SHA-256","UINT8ARRAY");i.update(t),e=i.getHash("UINT8ARRAY")}i.push(e),r=!1}else t.set(o),r=!0;e=i}return e[0]}const A=new WeakMap;class k{textEncoder=new TextEncoder;textDecoder=new TextDecoder;data;path=[];hooks;consumedHookHandler=new WeakMap;constructor(e,t){this.data=e,this.hooks=t,t&&A.set(t,!0)}start(e){if(this.encode(this.data,e),this.hooks)for(const e of this.hooks.values())this.consumedHookHandler.get(e)||e({value:void 0,done:!0});e.close()}encode(e,n){if(null!=e)if("boolean"==typeof e)this.encode(e?1:0,n);else if("number"==typeof e){const t=Math.round(e);n.enqueue(this.textEncoder.encode(`i${t}e`)),t!==e&&(console.warn(`WARNING: Possible data corruption detected with value "${e}":`,`Bencoding only defines support for integers, value was converted to "${t}"`),console.trace())}else if("bigint"==typeof e)n.enqueue(this.textEncoder.encode(`i${e}e`));else if("string"==typeof e){const t=this.textEncoder.encode(e),r=t.byteLength;n.enqueue(this.textEncoder.encode(`${r}:`)),n.enqueue(t)}else if(e instanceof ArrayBuffer){const t=new Uint8Array(e),r=t.byteLength;n.enqueue(this.textEncoder.encode(`${r}:`)),n.enqueue(t)}else if(Array.isArray(e)){n.enqueue(t);let r=0;for(const t of e){if(this.path.push(r),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0})}else this.encode(t,n)}this.path.pop(),++r}n.enqueue(a)}else if(e instanceof Map){n.enqueue(o);const t=m(e.keys(),((e,t)=>(e="string"==typeof e?e:this.textDecoder.decode(e))<(t="string"==typeof t?t:this.textDecoder.decode(t))?-1:e>t?1:0));for(const r of t){const t=e.get(r);if(void 0!==t&&null!==e)if(r instanceof ArrayBuffer)this.encode(r,n),this.encode(t,n);else{if(this.path.push(r),this.encode(r,n),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0}),this.consumedHookHandler.set(e,!0)}else this.encode(t,n)}this.path.pop()}}n.enqueue(a)}else{n.enqueue(o);const t=Object.keys(e).sort();for(const r of t){const t=e[r];if(void 0!==t&&null!==e){if(this.path.push(r),this.encode(r,n),this.hooks){const e=this.hooks.get(this.path);if(e){const r=R(n,e);this.encode(t,r),e({value:void 0,done:!0}),this.consumedHookHandler.set(e,!0)}else this.encode(t,n)}this.path.pop()}}n.enqueue(a)}}}function E(e,t){return new ReadableStream(new k(e,t))}function R(e,t){return new Proxy(e,{get:function(e,n,r){return"enqueue"===n?(n=>{e.enqueue(n),t({value:n,done:!1})}).bind(e):Reflect.get(e,n,r)}})}function U(e,t){const n={controller:null},r=new ReadableStream({start(e){n.controller=e},pull(e){A.get(t)||(console.warn("You need to call encode() first and then consume hooks."),e.close(),n.controller=null)}});return t.set(e,(({value:e,done:t})=>{null!==n.controller&&(t?n.controller.close():n.controller.enqueue(e))})),[r]}function S(e,t){const[n]=U(e,t);return[new Response(n).arrayBuffer()]}function T(e,t){const[n]=U(e,t);return[new Response(n).text()]}var B;!function(e){e.Integer="Integer",e.ByteString="ByteString",e.ListStart="ListStart",e.ListEnd="ListEnd",e.DictionaryStart="DictionaryStart",e.DictionaryEnd="DictionaryEnd"}(B||(B={}));class P{endStack=[];token=null;byteStringLength=-1;byteStringOffset=0;transform(e,t){this.tokenize(e,t)}flush(){if(this.endStack.length||this.token||-1!==this.byteStringLength||this.byteStringOffset)throw new SyntaxError("Unexpected end of torrent stream")}tokenize(t,n){if(0!==t.byteLength)if(null===this.token&&-1===this.byteStringLength){const r=t[0];if(r===u)this.token={type:B.Integer,value:new Uint8Array};else if(w(r))this.byteStringLength=r-d;else if(r===e)this.endStack.push(B.ListEnd),n.enqueue({type:B.ListStart});else if(r===i)this.endStack.push(B.DictionaryEnd),n.enqueue({type:B.DictionaryStart});else{if(r!==s)throw new SyntaxError(`Unexpected byte: ${r}`);{const e=this.endStack.pop();if(!e)throw new SyntaxError("Unbalanced delimiter");n.enqueue({type:e})}}this.tokenize(t.subarray(1),n)}else if(this.token&&-1===this.byteStringLength)if(this.token.type===B.Integer){const e=t.indexOf(s);-1===e?this.token.value=this.token.value?b(this.token.value,t):t:(this.token.value=this.token.value?b(this.token.value,t.subarray(0,e)):t.subarray(0,e),n.enqueue(this.token),this.token=null,this.tokenize(t.subarray(e+1),n))}else{if(this.token.type!==B.ByteString)throw new Error("This is a bug");{const e=this.token.value.byteLength-this.byteStringOffset,r=t.byteLength;r<e?(this.token.value.set(t,this.byteStringOffset),this.byteStringOffset+=r):(this.token.value.set(t.subarray(0,e),this.byteStringOffset),this.byteStringOffset=0,n.enqueue(this.token),this.token=null,this.tokenize(t.subarray(e),n))}}else{if(!(this.byteStringLength>-1&&null===this.token))throw new Error("This is a bug");{let e=-1;for(const[n,r]of t.entries()){if(!w(r)){if(r===h){e=n;break}throw new SyntaxError(`Unexpected byte: ${r}`)}this.byteStringLength=10*this.byteStringLength-d+r}-1!==e&&(this.token={type:B.ByteString,value:new Uint8Array(this.byteStringLength)},this.byteStringLength=-1,this.tokenize(t.subarray(e+1),n))}}}}class F extends TransformStream{constructor(){super(new P)}}async function C(e){let t;const n=[],r=e.getReader();let i;for(;;){const{done:e,value:o}=await r.read();if(e)break;const s=n.at(-1);if(s)if(Array.isArray(s))switch(o.type){case B.Integer:s.push(N(o.value));break;case B.ByteString:s.push(H(o.value));break;case B.DictionaryStart:{const e=Object.create(null);s.push(e),n.push(e);break}case B.ListStart:{const e=[];s.push(e),n.push(e);break}case B.ListEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`)}else if(void 0===i)switch(o.type){case B.ByteString:i=H(o.value);break;case B.DictionaryEnd:n.pop();break;default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`)}else{switch(o.type){case B.Integer:s[i]=N(o.value);break;case B.ByteString:s[i]=H(o.value);break;case B.DictionaryStart:{const e=Object.create(null);s[i]=e,n.push(e);break}case B.ListStart:{const e=[];s[i]=e,n.push(e);break}default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`)}i=void 0}else{if(void 0!==t)throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`);switch(o.type){case B.Integer:t=N(o.value);break;case B.ByteString:t=H(o.value);break;case B.DictionaryStart:{const e=Object.create(null);n.push(e),t=e;break}case B.ListStart:{const e=[];n.push(e),t=e;break}default:throw new SyntaxError(`Unexpected token: ${JSON.stringify(o)}`)}}}if(n.length)throw new Error("Unexpected end of token stream");return t}async function x(e){const t=new F,n=e.pipeThrough(t);return await C(n)}function N(e){let t=0,n=!0;for(const[r,i]of e.entries()){if(0===r&&i===f){n=!1;continue}if(1===r&&!n&&i===d)throw new SyntaxError("Negative zero is not a valid integer");if(1===r&&0===t)throw new SyntaxError("Leading zeros are not allowed");if(!w(i))throw new SyntaxError(`Unexpected byte: ${i}`);const e=i-d;(n&&"number"==typeof t&&t>(Number.MAX_SAFE_INTEGER-e)/10||!n&&"number"==typeof t&&t<(Number.MIN_SAFE_INTEGER+e)/10)&&(t=BigInt(t)),t="number"==typeof t?n?10*t+e:10*t-e:n?10n*t+BigInt(e):10n*t-BigInt(e)}return t}function H(e){return(new TextDecoder).decode(e)}n(913);class I extends Error{constructor(e,t){super(((e,...t)=>{let n=e;return t.length>0&&(n+=` :: ${JSON.stringify(t)}`),n})(e,t)),this.name=e,this.details=t}}class M{constructor(){this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t}))}}function Y(e){const t=e.map((e=>Promise.resolve(e).then((e=>function(e){if(e instanceof Response){if(e.body)return e.body.getReader();throw new I("opaque-streams-source",{type:e.type})}return e instanceof ReadableStream?e.getReader():new Response(e).body.getReader()}(e))))),n=new M;let r=0;const i=new ReadableStream({pull(e){return t[r].then((e=>e.read())).then((i=>{if(i.done)return r++,r>=t.length?(e.close(),void n.resolve()):this.pull(e);e.enqueue(i.value)})).catch((e=>{throw n.reject(e),e}))},cancel(){n.resolve()}});return{done:n.promise,stream:i}}n(1);const D=new Uint8Array(32);class O{blockCount=0;merkleLeaves=[];blocksPerPiece;constructor(e){this.blocksPerPiece=e}async transform(e,t){let r;++this.blockCount;try{r=new Uint8Array(await crypto.subtle.digest("SHA-256",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,673)),i=new t("SHA-256","UINT8ARRAY");i.update(e),r=i.getHash("UINT8ARRAY")}this.merkleLeaves.push(r),this.merkleLeaves.length===this.blocksPerPiece&&(t.enqueue(this.merkleLeaves),this.merkleLeaves=[])}flush(e){if(0===this.blockCount)return;let t=0;if(this.blockCount<this.blocksPerPiece)t=v(this.blockCount)-this.blockCount;else{const e=this.blockCount%this.blocksPerPiece;e>0&&(t=this.blocksPerPiece-e)}if(t>0)for(let e=0;e<t;++e)this.merkleLeaves.push(D);this.merkleLeaves.length>0&&e.enqueue(this.merkleLeaves)}}class q extends TransformStream{constructor(e){super(new O(e))}}class z{residuePointer=0;chunkLength;residue;opts;constructor(e,t={padding:!1}){this.chunkLength=e,this.opts=t,this.residue=new Uint8Array(this.chunkLength)}transform(e,t){for(;this.residuePointer+e.byteLength>=this.chunkLength;){const n=this.chunkLength-this.residuePointer;this.residue.set(e.subarray(0,n),this.residuePointer),this.residuePointer=0,t.enqueue(new Uint8Array(this.residue)),e=e.subarray(n)}this.residue.set(e,this.residuePointer),this.residuePointer+=e.byteLength}flush(e){this.residuePointer<=0||(this.opts.padding?(this.residue.set(new Uint8Array(this.chunkLength-this.residuePointer),this.residuePointer),e.enqueue(this.residue)):e.enqueue(this.residue.subarray(0,this.residuePointer)))}}class $ extends TransformStream{constructor(e,t={padding:!1}){super(new z(e,t))}}class _{updateProgress;constructor(e){this.updateProgress=e}async transform(e,t){t.enqueue(await L(e)),this.updateProgress&&await this.updateProgress()}}class K extends TransformStream{constructor(e){super(new _(e))}}class j{leafCount=0;merkleLeaves=[];blocksPerPiece;constructor(e){this.blocksPerPiece=e}transform(e){++this.leafCount,this.merkleLeaves.push(e)}async flush(e){const t=v(this.leafCount)-this.leafCount;if(t>0){const e=await this.padLeafPromise;for(let n=0;n<t;++n)this.merkleLeaves.push(e)}e.enqueue(this.merkleLeaves)}get padLeafPromise(){return L(Array(this.blocksPerPiece).fill(new Uint8Array(32)))}}class X extends TransformStream{constructor(e){super(new j(e))}}class V{updateProgress;constructor(e){this.updateProgress=e}async transform(e,t){let r;try{r=new Uint8Array(await crypto.subtle.digest("SHA-1",e))}catch{const{default:t}=await Promise.resolve().then(n.bind(n,211)),i=new t("SHA-1","UINT8ARRAY");i.update(e),r=i.getHash("UINT8ARRAY")}t.enqueue(r),this.updateProgress&&await this.updateProgress()}}class W extends TransformStream{constructor(e){super(new V(e))}}function J(e){return e instanceof File}function G(e){return!Q(e)&&!J(e)&&e.isDirectory}function Z(e){return!Q(e)&&!J(e)&&e.isFile}function Q(e){try{if(e instanceof FileSystemHandle&&"directory"===e.kind)return!0}catch(e){}return!1}function ee(e){try{if(e instanceof FileSystemHandle&&"file"===e.kind)return!0}catch(e){}return!1}function te(e){return new Promise(((t,n)=>{e.readEntries(t,n)}))}async function*ne(e){const t=e.createReader();let n=[];do{n=await te(t);for(const e of n)yield e}while(n.length>0)}function re(e){return new Promise(((t,n)=>{e.file(t,n)}))}const ie={randomUUID:"undefined"!=typeof crypto&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};let oe;const se=new Uint8Array(16);function ae(){if(!oe&&(oe="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!oe))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return oe(se)}const ue=[];for(let e=0;e<256;++e)ue.push((e+256).toString(16).slice(1));const ce=function(e,t,n){if(ie.randomUUID&&!t&&!e)return ie.randomUUID();const r=(e=e||{}).random||(e.rng||ae)();if(r[6]=15&r[6]|64,r[8]=63&r[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=r[e];return t}return function(e,t=0){return(ue[e[t+0]]+ue[e[t+1]]+ue[e[t+2]]+ue[e[t+3]]+"-"+ue[e[t+4]]+ue[e[t+5]]+"-"+ue[e[t+6]]+ue[e[t+7]]+"-"+ue[e[t+8]]+ue[e[t+9]]+"-"+ue[e[t+10]]+ue[e[t+11]]+ue[e[t+12]]+ue[e[t+13]]+ue[e[t+14]]+ue[e[t+15]]).toLowerCase()}(r)};function he(e,t){if(t.size>1||0===t.size)return{name:e??ce(),commonDir:void 0};const[n,r]=t.entries().next().value;return de(r)?{name:n,commonDir:void 0}:{name:e??n,commonDir:n}}async function le(e,{sort:t=!0,compareFunction:n=me,polyfillWebkitRelativePath:r=!0}={sort:!0,compareFunction:me,polyfillWebkitRelativePath:!0}){let i=0,o=0;const s=new WeakMap,a=new WeakMap,u=new WeakMap,c=["file tree",[]],h=[c];let l=!1;for await(const t of e)await f(t);return{fileTree:fe(c[1],l),traverseTree:function*e(t){if(ge(t))for(const n of t.values())yield*e(n);else yield[t,u.get(t)]},totalFileSize:i,totalFileCount:o};async function f(e){const p=h.at(-1);if(!p)throw new Error("This is a bug");const d=J(e),g=Q(e),w=G(e),m=ee(e),b=Z(e);if(g||w){const r=e.name,{index:i,result:o}=y(p[1],r,n);let s=o;if(we(s))throw new Error("A same name file already exists");if(ye(s)&&g){const t=a.get(s);if(!t||!await e.isSameEntry(t))throw new Error("File system handle not match")}s||(s=[r,[]],t?p[1].splice(i,0,s):p[1].push(s),g&&a.set(s,e)),h.push(s);for await(const t of g?e.values():ne(e))await f(t);s[1]=new Map(s[1]),h.pop()}else if(m||b){const a=e.name,{index:c,result:l}=y(p[1],a,n);let f=l;if(we(f)&&m){const t=s.get(f);if(!t||!await e.isSameEntry(t))throw new Error("A same name file already exists")}if(ye(f))throw new Error("A same name directory already exists");if(f)return;const d=await(m?e.getFile():re(e)),g=d.size;if(r){const e=h.reduce(((e,t,n)=>0===n?e:e+t[0]+"/"),"")+d.name;Object.defineProperty(d,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>e})}const w={"":{length:g}};f=[a,w],t?p[1].splice(c,0,f):p[1].push(f),m&&s.set(f,e),u.set(w,d),i+=g,o+=1}else{if(!d)throw new Error("Unrecognized type of input");{r&&""===e.webkitRelativePath&&Object.defineProperty(e,"webkitRelativePath",{configurable:!0,enumerable:!0,get:()=>e.name});const s=(e.webkitRelativePath||e.name).split("/"),a=[c];for(const[r,c]of s.entries()){r>=1&&(l=!0);const h=a.at(-1);if(!h)throw new Error("This is a bug");const{index:f,result:p}=y(h[1],c,n);if(r<s.length-1){let e=p;if(we(e))throw new Error("A same name file already exists");e||(e=[c,[]],t?h[1].splice(f,0,e):h[1].push(e)),a.push(e)}else{let n=p;if(ye(n))throw new Error("A same name directory already exists");if(n)return;const r=e.size,s={"":{length:r}};n=[c,s],t?h[1].splice(f,0,n):h[1].push(n),u.set(s,e),i+=r,o+=1}}}}}}function fe(e,t=!1){return t&&pe(e),new Map(e)}function pe(e){for(const t of e)if(ye(t)){const e=t[1];pe(e),t[1]=new Map(e)}}function de(e){return!!e&&""in e}function ge(e){return e instanceof Map}function we(e){return!!e&&""in e[1]}function ye(e){return!!e&&!(""in e[1])}function me(e,t){return e[0]<t?-1:e[0]>t?1:0}var be;!function(e){e.V1="v1",e.V2="v2",e.HYBRID="hybrid"}(be||(be={}));const ve=16384;var Le;!function(e){e[e["16KB"]=16384]="16KB",e[e["32KB"]=32768]="32KB",e[e["64KB"]=65536]="64KB",e[e["128KB"]=131072]="128KB",e[e["256KB"]=262144]="256KB",e[e["512KB"]=524288]="512KB",e[e["1MB"]=1048576]="1MB",e[e["2MB"]=2097152]="2MB",e[e["4MB"]=4194304]="4MB",e[e["8MB"]=8388608]="8MB",e[e["16MB"]=16777216]="16MB",e[e["32MB"]=33554432]="32MB"}(Le||(Le={}));const Ae={type:be.V1,addCreatedBy:!0,addCreationDate:!0,addPaddingFiles:!1,blockLength:ve,pieceLength:NaN,sortFiles:!0,isPrivate:!1},ke={type:be.V2,addCreatedBy:!0,addCreationDate:!0,blockLength:ve,pieceLength:NaN,metaVersion:2,isPrivate:!1},Ee={type:be.HYBRID,addCreatedBy:!0,addCreationDate:!0,blockLength:ve,pieceLength:NaN,metaVersion:2,isPrivate:!1};function Re(e,t){let n=0;for(const r of e)n+=Math.ceil(r.size/t);return n}async function Ue(e,t={type:be.V1},n){switch(t.type){case be.V1:return await async function(e,t,n){const r={...Ae,...t},{fileTree:i,traverseTree:o,totalFileCount:s,totalFileSize:a}=await le(e,{sort:r.sortFiles});if(0===s)return;const u=[];for(const[,e]of o(i))u.push(e);isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),0!=(r.pieceLength&r.pieceLength-1)&&console.warn(`piece length ${r.pieceLength} is not a power of 2`),r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const[c,h]=Pe(0,n),{commonDir:l,name:f}=he(r.name,i);let p;if(r.name=f,r.addPaddingFiles){const e=Re(u,r.pieceLength);await h(e);const t=[],n=s-1;for(let e=n;e>=0;--e){const i=u[e];if(t.unshift(Promise.resolve(Te(i.stream(),{pieceLength:r.pieceLength,padding:e!==n,updateProgress:c}))),e===n)continue;const o=i.size%r.pieceLength;if(0===o)continue;const s=Be(r.pieceLength-o,l);u.splice(e+1,0,s)}p=Y(t).stream}else{const e=Math.ceil(a/r.pieceLength);await h(e);const{stream:t}=Y(u.map((e=>Promise.resolve(e.stream()))));p=Te(t,{pieceLength:r.pieceLength,padding:!1,updateProgress:c})}return{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.6"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{...s>1?{files:u.map((e=>{const t=(e.webkitRelativePath||e.name).split("/");return void 0!==l&&t.shift(),{...e.padding?{attr:"p"}:{},length:e.size,path:t}}))}:{length:a},name:r.name,"piece length":r.pieceLength,pieces:await new Response(p).arrayBuffer(),...r.isPrivate?{private:!0}:{}}}}(e,t,n);case be.V2:return await async function(e,t,n){const r={...ke,...t},{fileTree:i,traverseTree:o,totalFileCount:s,totalFileSize:a}=await le(e);if(0===s)return;const u=[],c=[];for(const[e,t]of o(i))u.push(t),c.push([e,t]);if(isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),r.pieceLength<r.blockLength)throw new Error(`piece length ${r.pieceLength} is smaller than block length ${r.blockLength}`);if(0!=(r.pieceLength&r.pieceLength-1))throw new Error(`piece length ${r.pieceLength} is not a power of 2`);const h=r.pieceLength/r.blockLength;r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const l=Re(u,r.pieceLength),[f]=Pe(l,n),{name:p}=he(r.name,i);r.name=p;const d=new Map;return await Promise.all(c.map((async([e,t])=>{await Se(t.stream(),d,e,{blockLength:r.blockLength,pieceLength:r.pieceLength,blocksPerPiece:h,updateProgress:f})}))),{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.6"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{"file tree":i,"meta version":r.metaVersion,name:r.name,"piece length":r.pieceLength,...r.isPrivate?{private:!0}:{}},"piece layers":d}}(e,t,n);case be.HYBRID:return await async function(e,t,n){const r={...Ee,...t},{fileTree:i,traverseTree:o,totalFileCount:s,totalFileSize:a}=await le(e);if(0===s)return;const u=[],c=[];for(const[e,t]of o(i))u.push(t),c.push([e,t]);if(isNaN(r.pieceLength)&&(r.pieceLength=Ce(a,r.blockLength)),r.pieceLength<r.blockLength)throw new Error(`piece length ${r.pieceLength} is smaller than block length ${r.blockLength}`);if(0!=(r.pieceLength&r.pieceLength-1))throw new Error(`piece length ${r.pieceLength} is not a power of 2`);const h=r.pieceLength/r.blockLength;r.announceList=Fe(r.announceList),void 0===r.announce&&void 0!==r.announceList&&(r.announce=r.announceList[0]?.[0]);const[l]=Pe(2*Re(u,r.pieceLength),n),{commonDir:f,name:p}=he(r.name,i);r.name=p;const d=new Map,g=[],w=s-1;let y=-1;for(const[e,t]of c){++y;const[n,i]=t.stream().tee();if(g.unshift(Promise.resolve(Te(n,{pieceLength:r.pieceLength,padding:y!==w,updateProgress:l}))),await Se(i,d,e,{blockLength:r.blockLength,pieceLength:r.pieceLength,blocksPerPiece:h,updateProgress:l}),y===w)break;const o=t.size%r.pieceLength;if(0===o)continue;const s=Be(r.pieceLength-o,f);u.splice(y+1,0,s)}const m=Y(g).stream;return{...void 0===r.announce?{}:{announce:r.announce},...void 0===r.announceList?{}:{"announce-list":r.announceList},...void 0===r.comment?{}:{comment:r.comment},...r.addCreatedBy?{"created by":"torrefy v2.0.6"}:{},...r.addCreationDate?{"creation date":Date.now()/1e3>>0}:{},info:{"file tree":i,...s>1?{files:u.map((e=>{const t=(e.webkitRelativePath||e.name).split("/");return void 0!==f&&t.shift(),{...e.padding?{attr:"p"}:{},length:e.size,path:t}}))}:{length:a},"meta version":r.metaVersion,name:r.name,"piece length":r.pieceLength,pieces:await new Response(m).arrayBuffer(),...r.isPrivate?{private:!0}:{}},"piece layers":d}}(e,t,n)}}async function Se(e,t,n,r){const{piecesRootReadableStream:i,pieceLayerReadableStream:o}=function(e,t){const n=e.pipeThrough(new $(t.blockLength)).pipeThrough(new q(t.blocksPerPiece)).pipeThrough(new K(t.updateProgress)),[r,i]=n.tee();return{piecesRootReadableStream:i.pipeThrough(new X(t.blocksPerPiece)).pipeThrough(new K),pieceLayerReadableStream:r}}(e,r),s=new Response(i).arrayBuffer();if(n[""].length>r.pieceLength){const e=new Response(o).arrayBuffer();t.set(await s,await e)}n[""].length>0&&(n[""]["pieces root"]=await s)}function Te(e,t){return e.pipeThrough(new $(t.pieceLength,{padding:t.padding})).pipeThrough(new W(t.updateProgress))}function Be(e,t){const n=new File([new ArrayBuffer(e)],`${e}`,{type:"application/octet-stream"}),r=`.pad/${e}`,i=void 0===t?r:`${t}/${r}`;return Object.defineProperties(n,{webkitRelativePath:{configurable:!0,enumerable:!0,get:()=>i},padding:{configurable:!0,enumerable:!1,get:()=>!0}}),n}function Pe(e,t){const n={current:0,total:e};return[async()=>{t&&await t(++n.current,n.total)},async e=>{n.total="number"==typeof e?e:await e(n.total,n.current)}]}function Fe(e){if(void 0===e)return;const t=[];for(const n of e)0!==n.length&&t.push(n);return 0!==t.length?t:void 0}function Ce(e,t){return Math.max(t,v(e>>>10))}})(),r})()));

@@ -148,3 +148,3 @@ import { FileDirLikes } from "./fileDirLike.js";

export declare function isFileTreeDirEntry(entry: FileTreeFileEntry | FileTreeDirEntry | undefined): entry is FileTreeDirEntry;
export declare function compareEntryNames(entry: FileTreeFileEntry | FileTreeDirEntry, name: string): 1 | -1 | 0;
export declare function compareEntryNames(entry: FileTreeFileEntry | FileTreeDirEntry, name: string): 1 | 0 | -1;
export {};
{
"name": "torrefy",
"version": "2.0.5",
"version": "2.0.6",
"description": "An ESM package that uses Web Streams API to create v1, v2 or hybrid torrents in your web browser.",
"type": "module",

@@ -16,2 +17,22 @@ "main": "./dist/index.js",

},
"repository": {
"type": "git",
"url": "https://github.com/Sec-ant/torrefy.git"
},
"homepage": "https://github.com/Sec-ant/torrefy",
"bugs": {
"url": "https://github.com/Sec-ant/torrefy/issues"
},
"keywords": [
"torrent",
"bittorrent",
"bencode",
"bdecode",
"metainfo",
"infohash",
"webtorrent",
"esm",
"webstream"
],
"author": "Ze-Zheng Wu",
"license": "MIT",

@@ -18,0 +39,0 @@ "scripts": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc