-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
3 lines (3 loc) · 45.2 KB
/
index.js
1
2
3
var Re=Object.create;var ie=Object.defineProperty;var Pe=Object.getOwnPropertyDescriptor;var Ne=Object.getOwnPropertyNames;var Ce=Object.getPrototypeOf,Ue=Object.prototype.hasOwnProperty;var ne=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Me=(t,e,r,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ne(e))!Ue.call(t,n)&&n!==r&&ie(t,n,{get:()=>e[n],enumerable:!(i=Pe(e,n))||i.enumerable});return t};var se=(t,e,r)=>(r=t!=null?Re(Ce(t)):{},Me(e||!t||!t.__esModule?ie(r,"default",{value:t,enumerable:!0}):r,t));var he=ne((ut,pe)=>{"use strict";var O={isString:t=>typeof t=="string",isObject:t=>typeof t=="object"};function le(t,e){for(var r=[],i=0;i<t.length;i++){var n=t[i];!n||n==="."||(n===".."?r.length&&r[r.length-1]!==".."?r.pop():e&&r.push(".."):r.push(n))}return r}function xe(t){for(var e=t.length-1,r=0;r<=e&&!t[r];r++);for(var i=e;i>=0&&!t[i];i--);return r===0&&i===e?t:r>i?[]:t.slice(r,i+1)}var $e=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,l={};function R(t){return $e.exec(t).slice(1)}l.resolve=function(){for(var t="",e=!1,r=arguments.length-1;r>=-1&&!e;r--){var i=r>=0?arguments[r]:process.cwd();if(O.isString(i)){if(!i)continue}else throw new TypeError("Arguments to path.resolve must be strings");t=i+"/"+t,e=i[0]==="/"}return t=le(t.split("/"),!e).join("/"),(e?"/":"")+t||"."};l.normalize=function(t){var e=l.isAbsolute(t),r=t&&t[t.length-1]==="/";return t=le(t.split("/"),!e).join("/"),!t&&!e&&(t="."),t&&r&&(t+="/"),(e?"/":"")+t};l.isAbsolute=function(t){return t.charAt(0)==="/"};l.join=function(){for(var t="",e=0;e<arguments.length;e++){var r=arguments[e];if(!O.isString(r))throw new TypeError("Arguments to path.join must be strings");r&&(t?t+="/"+r:t+=r)}return l.normalize(t)};l.relative=function(t,e){t=l.resolve(t).substr(1),e=l.resolve(e).substr(1);for(var r=xe(t.split("/")),i=xe(e.split("/")),n=Math.min(r.length,i.length),s=n,a=0;a<n;a++)if(r[a]!==i[a]){s=a;break}for(var f=[],a=s;a<r.length;a++)f.push("..");return f=f.concat(i.slice(s)),f.join("/")};l._makeLong=function(t){return t};l.dirname=function(t){var e=R(t),r=e[0],i=e[1];return!r&&!i?".":(i&&(i=i.substr(0,i.length-1)),r+i)};l.basename=function(t,e){var r=R(t)[2];return e&&r.substr(-1*e.length)===e&&(r=r.substr(0,r.length-e.length)),r};l.extname=function(t){return R(t)[3]};l.format=function(t){if(!O.isObject(t))throw new TypeError("Parameter 'pathObject' must be an object, not "+typeof t);var e=t.root||"";if(!O.isString(e))throw new TypeError("'pathObject.root' must be a string or undefined, not "+typeof t.root);var r=t.dir?t.dir+l.sep:"",i=t.base||"";return r+i};l.parse=function(t){if(!O.isString(t))throw new TypeError("Parameter 'pathString' must be a string, not "+typeof t);var e=R(t);if(!e||e.length!==4)throw new TypeError("Invalid path '"+t+"'");return e[1]=e[1]||"",e[2]=e[2]||"",e[3]=e[3]||"",{root:e[0],dir:e[0]+e[1].slice(0,-1),base:e[2],ext:e[3],name:e[2].slice(0,e[2].length-e[3].length)}};l.sep="/";l.delimiter=":";pe.exports=l});var we=ne(Q=>{"use strict";Q.read=function(t,e,r,i,n){var s,a,f=n*8-i-1,c=(1<<f)-1,o=c>>1,u=-7,m=r?n-1:0,B=r?-1:1,w=t[e+m];for(m+=B,s=w&(1<<-u)-1,w>>=-u,u+=f;u>0;s=s*256+t[e+m],m+=B,u-=8);for(a=s&(1<<-u)-1,s>>=-u,u+=i;u>0;a=a*256+t[e+m],m+=B,u-=8);if(s===0)s=1-o;else{if(s===c)return a?NaN:(w?-1:1)*(1/0);a=a+Math.pow(2,i),s=s-o}return(w?-1:1)*a*Math.pow(2,s-i)};Q.write=function(t,e,r,i,n,s){var a,f,c,o=s*8-n-1,u=(1<<o)-1,m=u>>1,B=n===23?Math.pow(2,-24)-Math.pow(2,-77):0,w=i?0:s-1,b=i?1:-1,z=e<0||e===0&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(f=isNaN(e)?1:0,a=u):(a=Math.floor(Math.log(e)/Math.LN2),e*(c=Math.pow(2,-a))<1&&(a--,c*=2),a+m>=1?e+=B/c:e+=B*Math.pow(2,1-m),e*c>=2&&(a++,c/=2),a+m>=u?(f=0,a=u):a+m>=1?(f=(e*c-1)*Math.pow(2,n),a=a+m):(f=e*Math.pow(2,m-1)*Math.pow(2,n),a=0));n>=8;t[r+w]=f&255,w+=b,f/=256,n-=8);for(a=a<<n|f,o+=n;o>0;t[r+w]=a&255,w+=b,a/=256,o-=8);t[r+w-b]|=z*128}});var h=typeof globalThis<"u"&&globalThis||typeof self<"u"&&self||typeof global<"u"&&global||{},d={searchParams:"URLSearchParams"in h,iterable:"Symbol"in h&&"iterator"in Symbol,blob:"FileReader"in h&&"Blob"in h&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in h,arrayBuffer:"ArrayBuffer"in h};function Le(t){return t&&DataView.prototype.isPrototypeOf(t)}d.arrayBuffer&&(ae=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],fe=ArrayBuffer.isView||function(t){return t&&ae.indexOf(Object.prototype.toString.call(t))>-1});var ae,fe;function _(t){if(typeof t!="string"&&(t=String(t)),/[^a-z0-9\-#$%&'*+.^_`|~!]/i.test(t)||t==="")throw new TypeError('Invalid character in header field name: "'+t+'"');return t.toLowerCase()}function H(t){return typeof t!="string"&&(t=String(t)),t}function V(t){var e={next:function(){var r=t.shift();return{done:r===void 0,value:r}}};return d.iterable&&(e[Symbol.iterator]=function(){return e}),e}function x(t){this.map={},t instanceof x?t.forEach(function(e,r){this.append(r,e)},this):Array.isArray(t)?t.forEach(function(e){if(e.length!=2)throw new TypeError("Headers constructor: expected name/value pair to be length 2, found"+e.length);this.append(e[0],e[1])},this):t&&Object.getOwnPropertyNames(t).forEach(function(e){this.append(e,t[e])},this)}x.prototype.append=function(t,e){t=_(t),e=H(e);var r=this.map[t];this.map[t]=r?r+", "+e:e};x.prototype.delete=function(t){delete this.map[_(t)]};x.prototype.get=function(t){return t=_(t),this.has(t)?this.map[t]:null};x.prototype.has=function(t){return this.map.hasOwnProperty(_(t))};x.prototype.set=function(t,e){this.map[_(t)]=H(e)};x.prototype.forEach=function(t,e){for(var r in this.map)this.map.hasOwnProperty(r)&&t.call(e,this.map[r],r,this)};x.prototype.keys=function(){var t=[];return this.forEach(function(e,r){t.push(r)}),V(t)};x.prototype.values=function(){var t=[];return this.forEach(function(e){t.push(e)}),V(t)};x.prototype.entries=function(){var t=[];return this.forEach(function(e,r){t.push([r,e])}),V(t)};d.iterable&&(x.prototype[Symbol.iterator]=x.prototype.entries);function q(t){if(!t._noBody){if(t.bodyUsed)return Promise.reject(new TypeError("Already read"));t.bodyUsed=!0}}function ce(t){return new Promise(function(e,r){t.onload=function(){e(t.result)},t.onerror=function(){r(t.error)}})}function ze(t){var e=new FileReader,r=ce(e);return e.readAsArrayBuffer(t),r}function qe(t){var e=new FileReader,r=ce(e),i=/charset=([A-Za-z0-9_-]+)/.exec(t.type),n=i?i[1]:"utf-8";return e.readAsText(t,n),r}function He(t){for(var e=new Uint8Array(t),r=new Array(e.length),i=0;i<e.length;i++)r[i]=String.fromCharCode(e[i]);return r.join("")}function oe(t){if(t.slice)return t.slice(0);var e=new Uint8Array(t.byteLength);return e.set(new Uint8Array(t)),e.buffer}function ue(){return this.bodyUsed=!1,this._initBody=function(t){this.bodyUsed=this.bodyUsed,this._bodyInit=t,t?typeof t=="string"?this._bodyText=t:d.blob&&Blob.prototype.isPrototypeOf(t)?this._bodyBlob=t:d.formData&&FormData.prototype.isPrototypeOf(t)?this._bodyFormData=t:d.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)?this._bodyText=t.toString():d.arrayBuffer&&d.blob&&Le(t)?(this._bodyArrayBuffer=oe(t.buffer),this._bodyInit=new Blob([this._bodyArrayBuffer])):d.arrayBuffer&&(ArrayBuffer.prototype.isPrototypeOf(t)||fe(t))?this._bodyArrayBuffer=oe(t):this._bodyText=t=Object.prototype.toString.call(t):(this._noBody=!0,this._bodyText=""),this.headers.get("content-type")||(typeof t=="string"?this.headers.set("content-type","text/plain;charset=UTF-8"):this._bodyBlob&&this._bodyBlob.type?this.headers.set("content-type",this._bodyBlob.type):d.searchParams&&URLSearchParams.prototype.isPrototypeOf(t)&&this.headers.set("content-type","application/x-www-form-urlencoded;charset=UTF-8"))},d.blob&&(this.blob=function(){var t=q(this);if(t)return t;if(this._bodyBlob)return Promise.resolve(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(new Blob([this._bodyArrayBuffer]));if(this._bodyFormData)throw new Error("could not read FormData body as blob");return Promise.resolve(new Blob([this._bodyText]))}),this.arrayBuffer=function(){if(this._bodyArrayBuffer){var t=q(this);return t||(ArrayBuffer.isView(this._bodyArrayBuffer)?Promise.resolve(this._bodyArrayBuffer.buffer.slice(this._bodyArrayBuffer.byteOffset,this._bodyArrayBuffer.byteOffset+this._bodyArrayBuffer.byteLength)):Promise.resolve(this._bodyArrayBuffer))}else{if(d.blob)return this.blob().then(ze);throw new Error("could not read as ArrayBuffer")}},this.text=function(){var t=q(this);if(t)return t;if(this._bodyBlob)return qe(this._bodyBlob);if(this._bodyArrayBuffer)return Promise.resolve(He(this._bodyArrayBuffer));if(this._bodyFormData)throw new Error("could not read FormData body as text");return Promise.resolve(this._bodyText)},d.formData&&(this.formData=function(){return this.text().then(Ge)}),this.json=function(){return this.text().then(JSON.parse)},this}var Ve=["CONNECT","DELETE","GET","HEAD","OPTIONS","PATCH","POST","PUT","TRACE"];function We(t){var e=t.toUpperCase();return Ve.indexOf(e)>-1?e:t}function A(t,e){if(!(this instanceof A))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');e=e||{};var r=e.body;if(t instanceof A){if(t.bodyUsed)throw new TypeError("Already read");this.url=t.url,this.credentials=t.credentials,e.headers||(this.headers=new x(t.headers)),this.method=t.method,this.mode=t.mode,this.signal=t.signal,!r&&t._bodyInit!=null&&(r=t._bodyInit,t.bodyUsed=!0)}else this.url=String(t);if(this.credentials=e.credentials||this.credentials||"same-origin",(e.headers||!this.headers)&&(this.headers=new x(e.headers)),this.method=We(e.method||this.method||"GET"),this.mode=e.mode||this.mode||null,this.signal=e.signal||this.signal||function(){if("AbortController"in h){var s=new AbortController;return s.signal}}(),this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&r)throw new TypeError("Body not allowed for GET or HEAD requests");if(this._initBody(r),(this.method==="GET"||this.method==="HEAD")&&(e.cache==="no-store"||e.cache==="no-cache")){var i=/([?&])_=[^&]*/;if(i.test(this.url))this.url=this.url.replace(i,"$1_="+new Date().getTime());else{var n=/\?/;this.url+=(n.test(this.url)?"&":"?")+"_="+new Date().getTime()}}}A.prototype.clone=function(){return new A(this,{body:this._bodyInit})};function Ge(t){var e=new FormData;return t.trim().split("&").forEach(function(r){if(r){var i=r.split("="),n=i.shift().replace(/\+/g," "),s=i.join("=").replace(/\+/g," ");e.append(decodeURIComponent(n),decodeURIComponent(s))}}),e}function Je(t){var e=new x,r=t.replace(/\r?\n[\t ]+/g," ");return r.split("\r").map(function(i){return i.indexOf(`
`)===0?i.substr(1,i.length):i}).forEach(function(i){var n=i.split(":"),s=n.shift().trim();if(s){var a=n.join(":").trim();try{e.append(s,a)}catch(f){console.warn("Response "+f.message)}}}),e}ue.call(A.prototype);function k(t,e){if(!(this instanceof k))throw new TypeError('Please use the "new" operator, this DOM object constructor cannot be called as a function.');if(e||(e={}),this.type="default",this.status=e.status===void 0?200:e.status,this.status<200||this.status>599)throw new RangeError("Failed to construct 'Response': The status provided (0) is outside the range [200, 599].");this.ok=this.status>=200&&this.status<300,this.statusText=e.statusText===void 0?"":""+e.statusText,this.headers=new x(e.headers),this.url=e.url||"",this._initBody(t)}ue.call(k.prototype);k.prototype.clone=function(){return new k(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new x(this.headers),url:this.url})};k.error=function(){var t=new k(null,{status:200,statusText:""});return t.status=0,t.type="error",t};var Ye=[301,302,303,307,308];k.redirect=function(t,e){if(Ye.indexOf(e)===-1)throw new RangeError("Invalid status code");return new k(null,{status:e,headers:{location:t}})};var F=h.DOMException;try{new F}catch{F=function(e,r){this.message=e,this.name=r;var i=Error(e);this.stack=i.stack},F.prototype=Object.create(Error.prototype),F.prototype.constructor=F}function I(t,e){return new Promise(function(r,i){var n=new A(t,e);if(n.signal&&n.signal.aborted)return i(new F("Aborted","AbortError"));var s=new XMLHttpRequest;function a(){s.abort()}s.onload=function(){var o={statusText:s.statusText,headers:Je(s.getAllResponseHeaders()||"")};n.url.startsWith("file://")&&(s.status<200||s.status>599)?o.status=200:o.status=s.status,o.url="responseURL"in s?s.responseURL:o.headers.get("X-Request-URL");var u="response"in s?s.response:s.responseText;setTimeout(function(){r(new k(u,o))},0)},s.onerror=function(){setTimeout(function(){i(new TypeError("Network request failed"))},0)},s.ontimeout=function(){setTimeout(function(){i(new TypeError("Network request timed out"))},0)},s.onabort=function(){setTimeout(function(){i(new F("Aborted","AbortError"))},0)};function f(o){try{return o===""&&h.location.href?h.location.href:o}catch{return o}}if(s.open(n.method,f(n.url),!0),n.credentials==="include"?s.withCredentials=!0:n.credentials==="omit"&&(s.withCredentials=!1),"responseType"in s&&(d.blob?s.responseType="blob":d.arrayBuffer&&(s.responseType="arraybuffer")),e&&typeof e.headers=="object"&&!(e.headers instanceof x||h.Headers&&e.headers instanceof h.Headers)){var c=[];Object.getOwnPropertyNames(e.headers).forEach(function(o){c.push(_(o)),s.setRequestHeader(o,H(e.headers[o]))}),n.headers.forEach(function(o,u){c.indexOf(u)===-1&&s.setRequestHeader(u,o)})}else n.headers.forEach(function(o,u){s.setRequestHeader(u,o)});n.signal&&(n.signal.addEventListener("abort",a),s.onreadystatechange=function(){s.readyState===4&&n.signal.removeEventListener("abort",a)}),s.send(typeof n._bodyInit>"u"?null:n._bodyInit)})}I.polyfill=!0;h.fetch||(h.fetch=I,h.Headers=x,h.Request=A,h.Response=k);var v=se(he(),1),G=1;var J=4;var j=16,Xe=32;function g(t,e){return"CBFS$"+t+":"+e}var P=new Map,D=t=>settings.settingsStorage.getItem(t),S=(t,e)=>settings.settingsStorage.setItem(t,e);function Qe(t){if(typeof t!="number"||!P.has(t))return;let e=P.get(t);return{...e,fileObj:X(e.path)}}function me(t,e){if(typeof e>"u"&&(e=G),typeof e!="number")return;let r=X(t);if(typeof r>"u"){if(e&j)r=tt(t);else return;if(typeof r>"u")return}else if(e&j&&e&Xe)return;let i=(new Date().getTime()+114514)%1919810;for(;P.has(i);)++i;return P.set(i,{path:t,flags:e}),i}function N(){return typeof D(g("config","head"))<"u"}function Y(){if(N())return;console.log("CBFS","Init CBFS FileSystem for app-side");let t={root:"/",nextFileBlockId:1},e=W({path:"/data",files:[],dirs:[]}),r=W({path:"/assets",files:[],dirs:[]}),i=W({path:"/",files:[],dirs:["data","assets"]});S(g("config","head"),JSON.stringify(t)),S(g("dir","/"),JSON.stringify(i)),S(g("dir","/data"),JSON.stringify(e)),S(g("dir","/assets"),JSON.stringify(r))}function $(t){if(typeof t!="string")return;N||Y();let{root:e}=JSON.parse(D(g("config","head"))),r=v.join(e,v.normalize(t));r!="/"&&r.endsWith("/")&&(r=r.slice(0,r.length-1));let i=D(g("dir",r));if(i)return JSON.parse(i)}function X(t){if(typeof t!="string"||t.endsWith("/"))return;let e=v.parse(v.join("/",t)),r=$(e.dir);if(!(typeof r>"u")){for(let i of r.files)if(i.name===e.base)return i}}function Ze(){let t=JSON.parse(D(g("config","head"))),e=t.nextFileBlockId++;return S(g("block",e),""),S(g("config","head"),JSON.stringify(t)),e}function Ke({name:t,path:e,size:r,utc:i,block:n}){return{name:t,path:e,size:r,utc:i,block:n}}function W({path:t,files:e,dirs:r}){return{path:t,files:e,dirs:r}}function et(t,e,{offset:r=0,length:i=Number.MAX_SAFE_INTEGER,position:n=0}){if(typeof t>"u")return;let s=null;if(e instanceof Buffer)s=e.buffer;else if(e instanceof ArrayBuffer)s=e;else if(ArrayBuffer.isView(e))s=e.buffer;else return;if(i>s.byteLength-r&&(i=s.byteLength-r),n!=0){let o=D(g("block",t.block));typeof o>"u"&&(o="");let u=o.length;u<n+i&&(u=n+i);let m=new ArrayBuffer(u),B=new Uint8Array(m);for(let b=0,z=o.length;b<z;++b)B[b]=o.charCodeAt(b);let w=new Uint8Array(s);for(let b=0;b<u;++b)B[n+b]=w[r+b];s=m}t.size=s.byteLength,t.utc=new Date().getTime();let a=$(t.path),f=0,c=a.files.length;for(;f<c&&a.files[f].name!==t.name;)++f;if(f!=c)return a.files[f]=t,S(g("dir",a.path),JSON.stringify(a)),S(g("block",t.block),Buffer.from(s).toString("binary")),{length:i}}function tt(t){if(typeof t!="string"||t.endsWith("/"))return;let e=v.parse(v.join("/",t)),r=$(e.dir);if(typeof r>"u")return;for(let s of r.files)if(s.name===t.base)return;for(let s of r.dirs)if(s===t.base)return;let i=Ze(),n=Ke({name:e.base,path:e.dir,size:0,utc:new Date().getTime(),block:i});return r.files.push(n),S(g("dir",r.path),JSON.stringify(r)),n}function de(t){if(typeof t>"u"||typeof t.path>"u"||typeof t.path!="string")throw new Error("[CBFS] Arg Type Error");if(typeof t.flag!="number")throw new Error("[CBFS] Arg Type Error");typeof t.flag>"u"&&(t.flag=G),N()||Y();let e=me(v.join("/data",t.path),t.flag);if(typeof e>"u")throw new Error("[CBFS] Operation Error");return e}function ge(t){if(typeof t>"u"||typeof t.path>"u"||typeof t.path!="string")throw new Error("[CBFS] Arg Type Error");if(typeof t.flag>"u")t.flag=G;else if(typeof t.flag!="number")throw new Error("[CBFS] Arg Type Error");N()||Y();let e=me(v.join("/assets",t.path),t.flag);if(typeof e>"u")throw new Error("[CBFS] Operation Error");return e}function ye(t){if(typeof t>"u"||typeof t.path>"u"||typeof t.path!="string")return;let e=X(v.join("/data/",t.path));if(!(typeof e>"u"))return{size:e.size,mtimeMs:e.utc}}function be(t){if(typeof t>"u"||typeof t.fd!="number"||!(t.buffer instanceof ArrayBuffer)||typeof t.options<"u"&&(t.options.offset&&typeof t.options.offset!="number"||t.options.length&&typeof t.options.length!="number"||t.options.position&&typeof t.options.position!="number"))return;let e=Qe(t.fd);if(typeof e>"u")return;let r=et(e.fileObj,t.buffer,{...t.options});if(!(typeof r>"u"))return r.length}var ve=se(we(),1);function y(t){return new DataView(t.buffer,t.byteOffset)}var ke={len:1,get(t,e){return y(t).getUint8(e)},put(t,e,r){return y(t).setUint8(e,r),e+1}},C={len:2,get(t,e){return y(t).getUint16(e,!0)},put(t,e,r){return y(t).setUint16(e,r,!0),e+2}},U={len:2,get(t,e){return y(t).getUint16(e)},put(t,e,r){return y(t).setUint16(e,r),e+2}};var Ee={len:4,get(t,e){return y(t).getUint32(e,!0)},put(t,e,r){return y(t).setUint32(e,r,!0),e+4}},Be={len:4,get(t,e){return y(t).getUint32(e)},put(t,e,r){return y(t).setUint32(e,r),e+4}};var Se={len:4,get(t,e){return y(t).getInt32(e)},put(t,e,r){return y(t).setInt32(e,r),e+4}};var Te={len:8,get(t,e){return y(t).getBigUint64(e,!0)},put(t,e,r){return y(t).setBigUint64(e,r,!0),e+8}};var T=class{constructor(e,r){this.len=e,this.encoding=r}get(e,r){return Buffer.from(e).toString(this.encoding,r,r+this.len)}},Z=class t{constructor(e){this.len=e}static decode(e,r,i){let n="";for(let s=r;s<i;++s)n+=t.codePointToString(t.singleByteDecoder(e[s]));return n}static inRange(e,r,i){return r<=e&&e<=i}static codePointToString(e){return e<=65535?String.fromCharCode(e):(e-=65536,String.fromCharCode((e>>10)+55296,(e&1023)+56320))}static singleByteDecoder(e){if(t.inRange(e,0,127))return e;let r=t.windows1252[e-128];if(r===null)throw Error("invaliding encoding");return r}get(e,r=0){return t.decode(e,r,r+this.len)}};Z.windows1252=[8364,129,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,141,381,143,144,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,157,382,376,160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255];var nt="End-Of-Stream",p=class extends Error{constructor(){super(nt)}};var gt=1*1024*1024;var M=class{constructor(e){this.position=0,this.numBuffer=new Uint8Array(8),this.fileInfo=e||{}}async readToken(e,r=this.position){let i=Buffer.alloc(e.len);if(await this.readBuffer(i,{position:r})<e.len)throw new p;return e.get(i,0)}async peekToken(e,r=this.position){let i=Buffer.alloc(e.len);if(await this.peekBuffer(i,{position:r})<e.len)throw new p;return e.get(i,0)}async readNumber(e){if(await this.readBuffer(this.numBuffer,{length:e.len})<e.len)throw new p;return e.get(this.numBuffer,0)}async peekNumber(e){if(await this.peekBuffer(this.numBuffer,{length:e.len})<e.len)throw new p;return e.get(this.numBuffer,0)}async ignore(e){if(this.fileInfo.size!==void 0){let r=this.fileInfo.size-this.position;if(e>r)return this.position+=r,r}return this.position+=e,e}async close(){}normalizeOptions(e,r){if(r&&r.position!==void 0&&r.position<this.position)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");return r?{mayBeLess:r.mayBeLess===!0,offset:r.offset?r.offset:0,length:r.length?r.length:e.length-(r.offset?r.offset:0),position:r.position?r.position:this.position}:{mayBeLess:!1,offset:0,length:e.length,position:this.position}}};var L=class extends M{constructor(e,r){super(r),this.uint8Array=e,this.fileInfo.size=this.fileInfo.size?this.fileInfo.size:e.length}async readBuffer(e,r){if(r&&r.position){if(r.position<this.position)throw new Error("`options.position` must be equal or greater than `tokenizer.position`");this.position=r.position}let i=await this.peekBuffer(e,r);return this.position+=i,i}async peekBuffer(e,r){let i=this.normalizeOptions(e,r),n=Math.min(this.uint8Array.length-i.position,i.length);if(!i.mayBeLess&&n<i.length)throw new p;return e.set(this.uint8Array.subarray(i.position,i.position+n),i.offset),n}async close(){}};function K(t,e){return new L(t,e)}function Fe(t){return[...t].map(e=>e.charCodeAt(0))}function Ae(t,e=0){let r=Number.parseInt(t.toString("utf8",148,154).replace(/\0.*$/,"").trim(),8);if(Number.isNaN(r))return!1;let i=8*32;for(let n=e;n<e+148;n++)i+=t[n];for(let n=e+156;n<e+512;n++)i+=t[n];return r===i}var _e={get:(t,e)=>t[e+3]&127|t[e+2]<<7|t[e+1]<<14|t[e]<<21,len:4};var Ie=["jpg","png","apng","gif","webp","flif","xcf","cr2","cr3","orf","arw","dng","nef","rw2","raf","tif","bmp","icns","jxr","psd","indd","zip","tar","rar","gz","bz2","7z","dmg","mp4","mid","mkv","webm","mov","avi","mpg","mp2","mp3","m4a","oga","ogg","ogv","opus","flac","wav","spx","amr","pdf","epub","elf","exe","swf","rtf","wasm","woff","woff2","eot","ttf","otf","ico","flv","ps","xz","sqlite","nes","crx","xpi","cab","deb","ar","rpm","Z","lz","cfb","mxf","mts","blend","bpg","docx","pptx","xlsx","3gp","3g2","j2c","jp2","jpm","jpx","mj2","aif","qcp","odt","ods","odp","xml","mobi","heic","cur","ktx","ape","wv","dcm","ics","glb","pcap","dsf","lnk","alias","voc","ac3","m4v","m4p","m4b","f4v","f4p","f4b","f4a","mie","asf","ogm","ogx","mpc","arrow","shp","aac","mp1","it","s3m","xm","ai","skp","avif","eps","lzh","pgp","asar","stl","chm","3mf","zst","jxl","vcf","jls","pst","dwg","parquet","class","arj","cpio","ace","avro","icc"],Oe=["image/jpeg","image/png","image/gif","image/webp","image/flif","image/x-xcf","image/x-canon-cr2","image/x-canon-cr3","image/tiff","image/bmp","image/vnd.ms-photo","image/vnd.adobe.photoshop","application/x-indesign","application/epub+zip","application/x-xpinstall","application/vnd.oasis.opendocument.text","application/vnd.oasis.opendocument.spreadsheet","application/vnd.oasis.opendocument.presentation","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/zip","application/x-tar","application/x-rar-compressed","application/gzip","application/x-bzip2","application/x-7z-compressed","application/x-apple-diskimage","application/x-apache-arrow","video/mp4","audio/midi","video/x-matroska","video/webm","video/quicktime","video/vnd.avi","audio/vnd.wave","audio/qcelp","audio/x-ms-asf","video/x-ms-asf","application/vnd.ms-asf","video/mpeg","video/3gpp","audio/mpeg","audio/mp4","audio/opus","video/ogg","audio/ogg","application/ogg","audio/x-flac","audio/ape","audio/wavpack","audio/amr","application/pdf","application/x-elf","application/x-msdownload","application/x-shockwave-flash","application/rtf","application/wasm","font/woff","font/woff2","application/vnd.ms-fontobject","font/ttf","font/otf","image/x-icon","video/x-flv","application/postscript","application/eps","application/x-xz","application/x-sqlite3","application/x-nintendo-nes-rom","application/x-google-chrome-extension","application/vnd.ms-cab-compressed","application/x-deb","application/x-unix-archive","application/x-rpm","application/x-compress","application/x-lzip","application/x-cfb","application/x-mie","application/mxf","video/mp2t","application/x-blender","image/bpg","image/j2c","image/jp2","image/jpx","image/jpm","image/mj2","audio/aiff","application/xml","application/x-mobipocket-ebook","image/heif","image/heif-sequence","image/heic","image/heic-sequence","image/icns","image/ktx","application/dicom","audio/x-musepack","text/calendar","text/vcard","model/gltf-binary","application/vnd.tcpdump.pcap","audio/x-dsf","application/x.ms.shortcut","application/x.apple.alias","audio/x-voc","audio/vnd.dolby.dd-raw","audio/x-m4a","image/apng","image/x-olympus-orf","image/x-sony-arw","image/x-adobe-dng","image/x-nikon-nef","image/x-panasonic-rw2","image/x-fujifilm-raf","video/x-m4v","video/3gpp2","application/x-esri-shape","audio/aac","audio/x-it","audio/x-s3m","audio/x-xm","video/MP1S","video/MP2P","application/vnd.sketchup.skp","image/avif","application/x-lzh-compressed","application/pgp-encrypted","application/x-asar","model/stl","application/vnd.ms-htmlhelp","model/3mf","image/jxl","application/zstd","image/jls","application/vnd.ms-outlook","image/vnd.dwg","application/x-parquet","application/java-vm","application/x-arj","application/x-cpio","application/x-ace-compressed","application/avro","application/vnd.iccprofile"];var at=4100;async function je(t){if(!(t instanceof Uint8Array||t instanceof ArrayBuffer))throw new TypeError(`Expected the \`input\` argument to be of type \`Uint8Array\` or \`Buffer\` or \`ArrayBuffer\`, got \`${typeof t}\``);let e=t instanceof Uint8Array?t:new Uint8Array(t);if(e?.length>1)return De(K(e))}function E(t,e,r){r={offset:0,...r};for(let[i,n]of e.entries())if(r.mask){if(n!==(r.mask[i]&t[i+r.offset]))return!1}else if(n!==t[i+r.offset])return!1;return!0}async function De(t){try{return new ee().parse(t)}catch(e){if(!(e instanceof p))throw e}}var ee=class{check(e,r){return E(this.buffer,e,r)}checkString(e,r){return this.check(Fe(e),r)}async parse(e){if(this.buffer=Buffer.alloc(at),e.fileInfo.size===void 0&&(e.fileInfo.size=Number.MAX_SAFE_INTEGER),this.tokenizer=e,await e.peekBuffer(this.buffer,{length:12,mayBeLess:!0}),this.check([66,77]))return{ext:"bmp",mime:"image/bmp"};if(this.check([11,119]))return{ext:"ac3",mime:"audio/vnd.dolby.dd-raw"};if(this.check([120,1]))return{ext:"dmg",mime:"application/x-apple-diskimage"};if(this.check([77,90]))return{ext:"exe",mime:"application/x-msdownload"};if(this.check([37,33]))return await e.peekBuffer(this.buffer,{length:24,mayBeLess:!0}),this.checkString("PS-Adobe-",{offset:2})&&this.checkString(" EPSF-",{offset:14})?{ext:"eps",mime:"application/eps"}:{ext:"ps",mime:"application/postscript"};if(this.check([31,160])||this.check([31,157]))return{ext:"Z",mime:"application/x-compress"};if(this.check([199,113]))return{ext:"cpio",mime:"application/x-cpio"};if(this.check([96,234]))return{ext:"arj",mime:"application/x-arj"};if(this.check([239,187,191]))return this.tokenizer.ignore(3),this.parse(e);if(this.check([71,73,70]))return{ext:"gif",mime:"image/gif"};if(this.check([73,73,188]))return{ext:"jxr",mime:"image/vnd.ms-photo"};if(this.check([31,139,8]))return{ext:"gz",mime:"application/gzip"};if(this.check([66,90,104]))return{ext:"bz2",mime:"application/x-bzip2"};if(this.checkString("ID3")){await e.ignore(6);let r=await e.readToken(_e);return e.position+r>e.fileInfo.size?{ext:"mp3",mime:"audio/mpeg"}:(await e.ignore(r),De(e))}if(this.checkString("MP+"))return{ext:"mpc",mime:"audio/x-musepack"};if((this.buffer[0]===67||this.buffer[0]===70)&&this.check([87,83],{offset:1}))return{ext:"swf",mime:"application/x-shockwave-flash"};if(this.check([255,216,255]))return this.check([247],{offset:3})?{ext:"jls",mime:"image/jls"}:{ext:"jpg",mime:"image/jpeg"};if(this.check([79,98,106,1]))return{ext:"avro",mime:"application/avro"};if(this.checkString("FLIF"))return{ext:"flif",mime:"image/flif"};if(this.checkString("8BPS"))return{ext:"psd",mime:"image/vnd.adobe.photoshop"};if(this.checkString("WEBP",{offset:8}))return{ext:"webp",mime:"image/webp"};if(this.checkString("MPCK"))return{ext:"mpc",mime:"audio/x-musepack"};if(this.checkString("FORM"))return{ext:"aif",mime:"audio/aiff"};if(this.checkString("icns",{offset:0}))return{ext:"icns",mime:"image/icns"};if(this.check([80,75,3,4])){try{for(;e.position+30<e.fileInfo.size;){await e.readBuffer(this.buffer,{length:30});let r={compressedSize:this.buffer.readUInt32LE(18),uncompressedSize:this.buffer.readUInt32LE(22),filenameLength:this.buffer.readUInt16LE(26),extraFieldLength:this.buffer.readUInt16LE(28)};if(r.filename=await e.readToken(new T(r.filenameLength,"utf-8")),await e.ignore(r.extraFieldLength),r.filename==="META-INF/mozilla.rsa")return{ext:"xpi",mime:"application/x-xpinstall"};if(r.filename.endsWith(".rels")||r.filename.endsWith(".xml"))switch(r.filename.split("/")[0]){case"_rels":break;case"word":return{ext:"docx",mime:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"};case"ppt":return{ext:"pptx",mime:"application/vnd.openxmlformats-officedocument.presentationml.presentation"};case"xl":return{ext:"xlsx",mime:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"};default:break}if(r.filename.startsWith("xl/"))return{ext:"xlsx",mime:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"};if(r.filename.startsWith("3D/")&&r.filename.endsWith(".model"))return{ext:"3mf",mime:"model/3mf"};if(r.filename==="mimetype"&&r.compressedSize===r.uncompressedSize){let i=await e.readToken(new T(r.compressedSize,"utf-8"));switch(i=i.trim(),i){case"application/epub+zip":return{ext:"epub",mime:"application/epub+zip"};case"application/vnd.oasis.opendocument.text":return{ext:"odt",mime:"application/vnd.oasis.opendocument.text"};case"application/vnd.oasis.opendocument.spreadsheet":return{ext:"ods",mime:"application/vnd.oasis.opendocument.spreadsheet"};case"application/vnd.oasis.opendocument.presentation":return{ext:"odp",mime:"application/vnd.oasis.opendocument.presentation"};default:}}if(r.compressedSize===0){let i=-1;for(;i<0&&e.position<e.fileInfo.size;)await e.peekBuffer(this.buffer,{mayBeLess:!0}),i=this.buffer.indexOf("504B0304",0,"hex"),await e.ignore(i>=0?i:this.buffer.length)}else await e.ignore(r.compressedSize)}}catch(r){if(!(r instanceof p))throw r}return{ext:"zip",mime:"application/zip"}}if(this.checkString("OggS")){await e.ignore(28);let r=Buffer.alloc(8);return await e.readBuffer(r),E(r,[79,112,117,115,72,101,97,100])?{ext:"opus",mime:"audio/opus"}:E(r,[128,116,104,101,111,114,97])?{ext:"ogv",mime:"video/ogg"}:E(r,[1,118,105,100,101,111,0])?{ext:"ogm",mime:"video/ogg"}:E(r,[127,70,76,65,67])?{ext:"oga",mime:"audio/ogg"}:E(r,[83,112,101,101,120,32,32])?{ext:"spx",mime:"audio/ogg"}:E(r,[1,118,111,114,98,105,115])?{ext:"ogg",mime:"audio/ogg"}:{ext:"ogx",mime:"application/ogg"}}if(this.check([80,75])&&(this.buffer[2]===3||this.buffer[2]===5||this.buffer[2]===7)&&(this.buffer[3]===4||this.buffer[3]===6||this.buffer[3]===8))return{ext:"zip",mime:"application/zip"};if(this.checkString("ftyp",{offset:4})&&this.buffer[8]&96){let r=this.buffer.toString("binary",8,12).replace("\0"," ").trim();switch(r){case"avif":case"avis":return{ext:"avif",mime:"image/avif"};case"mif1":return{ext:"heic",mime:"image/heif"};case"msf1":return{ext:"heic",mime:"image/heif-sequence"};case"heic":case"heix":return{ext:"heic",mime:"image/heic"};case"hevc":case"hevx":return{ext:"heic",mime:"image/heic-sequence"};case"qt":return{ext:"mov",mime:"video/quicktime"};case"M4V":case"M4VH":case"M4VP":return{ext:"m4v",mime:"video/x-m4v"};case"M4P":return{ext:"m4p",mime:"video/mp4"};case"M4B":return{ext:"m4b",mime:"audio/mp4"};case"M4A":return{ext:"m4a",mime:"audio/x-m4a"};case"F4V":return{ext:"f4v",mime:"video/mp4"};case"F4P":return{ext:"f4p",mime:"video/mp4"};case"F4A":return{ext:"f4a",mime:"audio/mp4"};case"F4B":return{ext:"f4b",mime:"audio/mp4"};case"crx":return{ext:"cr3",mime:"image/x-canon-cr3"};default:return r.startsWith("3g")?r.startsWith("3g2")?{ext:"3g2",mime:"video/3gpp2"}:{ext:"3gp",mime:"video/3gpp"}:{ext:"mp4",mime:"video/mp4"}}}if(this.checkString("MThd"))return{ext:"mid",mime:"audio/midi"};if(this.checkString("wOFF")&&(this.check([0,1,0,0],{offset:4})||this.checkString("OTTO",{offset:4})))return{ext:"woff",mime:"font/woff"};if(this.checkString("wOF2")&&(this.check([0,1,0,0],{offset:4})||this.checkString("OTTO",{offset:4})))return{ext:"woff2",mime:"font/woff2"};if(this.check([212,195,178,161])||this.check([161,178,195,212]))return{ext:"pcap",mime:"application/vnd.tcpdump.pcap"};if(this.checkString("DSD "))return{ext:"dsf",mime:"audio/x-dsf"};if(this.checkString("LZIP"))return{ext:"lz",mime:"application/x-lzip"};if(this.checkString("fLaC"))return{ext:"flac",mime:"audio/x-flac"};if(this.check([66,80,71,251]))return{ext:"bpg",mime:"image/bpg"};if(this.checkString("wvpk"))return{ext:"wv",mime:"audio/wavpack"};if(this.checkString("%PDF")){try{await e.ignore(1350);let r=10*1024*1024,i=Buffer.alloc(Math.min(r,e.fileInfo.size));if(await e.readBuffer(i,{mayBeLess:!0}),i.includes(Buffer.from("AIPrivateData")))return{ext:"ai",mime:"application/postscript"}}catch(r){if(!(r instanceof p))throw r}return{ext:"pdf",mime:"application/pdf"}}if(this.check([0,97,115,109]))return{ext:"wasm",mime:"application/wasm"};if(this.check([73,73])){let r=await this.readTiffHeader(!1);if(r)return r}if(this.check([77,77])){let r=await this.readTiffHeader(!0);if(r)return r}if(this.checkString("MAC "))return{ext:"ape",mime:"audio/ape"};if(this.check([26,69,223,163])){async function r(){let f=await e.peekNumber(ke),c=128,o=0;for(;!(f&c)&&c!==0;)++o,c>>=1;let u=Buffer.alloc(o+1);return await e.readBuffer(u),u}async function i(){let f=await r(),c=await r();c[0]^=128>>c.length-1;let o=Math.min(6,c.length);return{id:f.readUIntBE(0,f.length),len:c.readUIntBE(c.length-o,o)}}async function n(f){for(;f>0;){let c=await i();if(c.id===17026)return(await e.readToken(new T(c.len,"utf-8"))).replace(/\00.*$/g,"");await e.ignore(c.len),--f}}let s=await i();switch(await n(s.len)){case"webm":return{ext:"webm",mime:"video/webm"};case"matroska":return{ext:"mkv",mime:"video/x-matroska"};default:return}}if(this.check([82,73,70,70])){if(this.check([65,86,73],{offset:8}))return{ext:"avi",mime:"video/vnd.avi"};if(this.check([87,65,86,69],{offset:8}))return{ext:"wav",mime:"audio/vnd.wave"};if(this.check([81,76,67,77],{offset:8}))return{ext:"qcp",mime:"audio/qcelp"}}if(this.checkString("SQLi"))return{ext:"sqlite",mime:"application/x-sqlite3"};if(this.check([78,69,83,26]))return{ext:"nes",mime:"application/x-nintendo-nes-rom"};if(this.checkString("Cr24"))return{ext:"crx",mime:"application/x-google-chrome-extension"};if(this.checkString("MSCF")||this.checkString("ISc("))return{ext:"cab",mime:"application/vnd.ms-cab-compressed"};if(this.check([237,171,238,219]))return{ext:"rpm",mime:"application/x-rpm"};if(this.check([197,208,211,198]))return{ext:"eps",mime:"application/eps"};if(this.check([40,181,47,253]))return{ext:"zst",mime:"application/zstd"};if(this.check([127,69,76,70]))return{ext:"elf",mime:"application/x-elf"};if(this.check([33,66,68,78]))return{ext:"pst",mime:"application/vnd.ms-outlook"};if(this.checkString("PAR1"))return{ext:"parquet",mime:"application/x-parquet"};if(this.check([79,84,84,79,0]))return{ext:"otf",mime:"font/otf"};if(this.checkString("#!AMR"))return{ext:"amr",mime:"audio/amr"};if(this.checkString("{\\rtf"))return{ext:"rtf",mime:"application/rtf"};if(this.check([70,76,86,1]))return{ext:"flv",mime:"video/x-flv"};if(this.checkString("IMPM"))return{ext:"it",mime:"audio/x-it"};if(this.checkString("-lh0-",{offset:2})||this.checkString("-lh1-",{offset:2})||this.checkString("-lh2-",{offset:2})||this.checkString("-lh3-",{offset:2})||this.checkString("-lh4-",{offset:2})||this.checkString("-lh5-",{offset:2})||this.checkString("-lh6-",{offset:2})||this.checkString("-lh7-",{offset:2})||this.checkString("-lzs-",{offset:2})||this.checkString("-lz4-",{offset:2})||this.checkString("-lz5-",{offset:2})||this.checkString("-lhd-",{offset:2}))return{ext:"lzh",mime:"application/x-lzh-compressed"};if(this.check([0,0,1,186])){if(this.check([33],{offset:4,mask:[241]}))return{ext:"mpg",mime:"video/MP1S"};if(this.check([68],{offset:4,mask:[196]}))return{ext:"mpg",mime:"video/MP2P"}}if(this.checkString("ITSF"))return{ext:"chm",mime:"application/vnd.ms-htmlhelp"};if(this.check([202,254,186,190]))return{ext:"class",mime:"application/java-vm"};if(this.check([253,55,122,88,90,0]))return{ext:"xz",mime:"application/x-xz"};if(this.checkString("<?xml "))return{ext:"xml",mime:"application/xml"};if(this.check([55,122,188,175,39,28]))return{ext:"7z",mime:"application/x-7z-compressed"};if(this.check([82,97,114,33,26,7])&&(this.buffer[6]===0||this.buffer[6]===1))return{ext:"rar",mime:"application/x-rar-compressed"};if(this.checkString("solid "))return{ext:"stl",mime:"model/stl"};if(this.checkString("AC")){let r=this.buffer.toString("binary",2,6);if(r.match("^d*")&&r>=1e3&&r<=1050)return{ext:"dwg",mime:"image/vnd.dwg"}}if(this.checkString("070707"))return{ext:"cpio",mime:"application/x-cpio"};if(this.checkString("BLENDER"))return{ext:"blend",mime:"application/x-blender"};if(this.checkString("!<arch>"))return await e.ignore(8),await e.readToken(new T(13,"ascii"))==="debian-binary"?{ext:"deb",mime:"application/x-deb"}:{ext:"ar",mime:"application/x-unix-archive"};if(this.checkString("**ACE",{offset:7})&&(await e.peekBuffer(this.buffer,{length:14,mayBeLess:!0}),this.checkString("**",{offset:12})))return{ext:"ace",mime:"application/x-ace-compressed"};if(this.check([137,80,78,71,13,10,26,10])){await e.ignore(8);async function r(){return{length:await e.readToken(Se),type:await e.readToken(new T(4,"binary"))}}do{let i=await r();if(i.length<0)return;switch(i.type){case"IDAT":return{ext:"png",mime:"image/png"};case"acTL":return{ext:"apng",mime:"image/apng"};default:await e.ignore(i.length+4)}}while(e.position+8<e.fileInfo.size);return{ext:"png",mime:"image/png"}}if(this.check([65,82,82,79,87,49,0,0]))return{ext:"arrow",mime:"application/x-apache-arrow"};if(this.check([103,108,84,70,2,0,0,0]))return{ext:"glb",mime:"model/gltf-binary"};if(this.check([102,114,101,101],{offset:4})||this.check([109,100,97,116],{offset:4})||this.check([109,111,111,118],{offset:4})||this.check([119,105,100,101],{offset:4}))return{ext:"mov",mime:"video/quicktime"};if(this.check([73,73,82,79,8,0,0,0,24]))return{ext:"orf",mime:"image/x-olympus-orf"};if(this.checkString("gimp xcf "))return{ext:"xcf",mime:"image/x-xcf"};if(this.check([73,73,85,0,24,0,0,0,136,231,116,216]))return{ext:"rw2",mime:"image/x-panasonic-rw2"};if(this.check([48,38,178,117,142,102,207,17,166,217])){async function r(){let i=Buffer.alloc(16);return await e.readBuffer(i),{id:i,size:Number(await e.readToken(Te))}}for(await e.ignore(30);e.position+24<e.fileInfo.size;){let i=await r(),n=i.size-24;if(E(i.id,[145,7,220,183,183,169,207,17,142,230,0,192,12,32,83,101])){let s=Buffer.alloc(16);if(n-=await e.readBuffer(s),E(s,[64,158,105,248,77,91,207,17,168,253,0,128,95,92,68,43]))return{ext:"asf",mime:"audio/x-ms-asf"};if(E(s,[192,239,25,188,77,91,207,17,168,253,0,128,95,92,68,43]))return{ext:"asf",mime:"video/x-ms-asf"};break}await e.ignore(n)}return{ext:"asf",mime:"application/vnd.ms-asf"}}if(this.check([171,75,84,88,32,49,49,187,13,10,26,10]))return{ext:"ktx",mime:"image/ktx"};if((this.check([126,16,4])||this.check([126,24,4]))&&this.check([48,77,73,69],{offset:4}))return{ext:"mie",mime:"application/x-mie"};if(this.check([39,10,0,0,0,0,0,0,0,0,0,0],{offset:2}))return{ext:"shp",mime:"application/x-esri-shape"};if(this.check([255,79,255,81]))return{ext:"j2c",mime:"image/j2c"};if(this.check([0,0,0,12,106,80,32,32,13,10,135,10]))switch(await e.ignore(20),await e.readToken(new T(4,"ascii"))){case"jp2 ":return{ext:"jp2",mime:"image/jp2"};case"jpx ":return{ext:"jpx",mime:"image/jpx"};case"jpm ":return{ext:"jpm",mime:"image/jpm"};case"mjp2":return{ext:"mj2",mime:"image/mj2"};default:return}if(this.check([255,10])||this.check([0,0,0,12,74,88,76,32,13,10,135,10]))return{ext:"jxl",mime:"image/jxl"};if(this.check([254,255]))return this.check([0,60,0,63,0,120,0,109,0,108],{offset:2})?{ext:"xml",mime:"application/xml"}:void 0;if(this.check([0,0,1,186])||this.check([0,0,1,179]))return{ext:"mpg",mime:"video/mpeg"};if(this.check([0,1,0,0,0]))return{ext:"ttf",mime:"font/ttf"};if(this.check([0,0,1,0]))return{ext:"ico",mime:"image/x-icon"};if(this.check([0,0,2,0]))return{ext:"cur",mime:"image/x-icon"};if(this.check([208,207,17,224,161,177,26,225]))return{ext:"cfb",mime:"application/x-cfb"};if(await e.peekBuffer(this.buffer,{length:Math.min(256,e.fileInfo.size),mayBeLess:!0}),this.check([97,99,115,112],{offset:36}))return{ext:"icc",mime:"application/vnd.iccprofile"};if(this.checkString("BEGIN:")){if(this.checkString("VCARD",{offset:6}))return{ext:"vcf",mime:"text/vcard"};if(this.checkString("VCALENDAR",{offset:6}))return{ext:"ics",mime:"text/calendar"}}if(this.checkString("FUJIFILMCCD-RAW"))return{ext:"raf",mime:"image/x-fujifilm-raf"};if(this.checkString("Extended Module:"))return{ext:"xm",mime:"audio/x-xm"};if(this.checkString("Creative Voice File"))return{ext:"voc",mime:"audio/x-voc"};if(this.check([4,0,0,0])&&this.buffer.length>=16){let r=this.buffer.readUInt32LE(12);if(r>12&&this.buffer.length>=r+16)try{let i=this.buffer.slice(16,r+16).toString();if(JSON.parse(i).files)return{ext:"asar",mime:"application/x-asar"}}catch{}}if(this.check([6,14,43,52,2,5,1,1,13,1,2,1,1,2]))return{ext:"mxf",mime:"application/mxf"};if(this.checkString("SCRM",{offset:44}))return{ext:"s3m",mime:"audio/x-s3m"};if(this.check([71])&&this.check([71],{offset:188}))return{ext:"mts",mime:"video/mp2t"};if(this.check([71],{offset:4})&&this.check([71],{offset:196}))return{ext:"mts",mime:"video/mp2t"};if(this.check([66,79,79,75,77,79,66,73],{offset:60}))return{ext:"mobi",mime:"application/x-mobipocket-ebook"};if(this.check([68,73,67,77],{offset:128}))return{ext:"dcm",mime:"application/dicom"};if(this.check([76,0,0,0,1,20,2,0,0,0,0,0,192,0,0,0,0,0,0,70]))return{ext:"lnk",mime:"application/x.ms.shortcut"};if(this.check([98,111,111,107,0,0,0,0,109,97,114,107,0,0,0,0]))return{ext:"alias",mime:"application/x.apple.alias"};if(this.check([76,80],{offset:34})&&(this.check([0,0,1],{offset:8})||this.check([1,0,2],{offset:8})||this.check([2,0,2],{offset:8})))return{ext:"eot",mime:"application/vnd.ms-fontobject"};if(this.check([6,6,237,245,216,29,70,229,189,49,239,231,254,116,183,29]))return{ext:"indd",mime:"application/x-indesign"};if(await e.peekBuffer(this.buffer,{length:Math.min(512,e.fileInfo.size),mayBeLess:!0}),Ae(this.buffer))return{ext:"tar",mime:"application/x-tar"};if(this.check([255,254]))return this.check([60,0,63,0,120,0,109,0,108,0],{offset:2})?{ext:"xml",mime:"application/xml"}:this.check([255,14,83,0,107,0,101,0,116,0,99,0,104,0,85,0,112,0,32,0,77,0,111,0,100,0,101,0,108,0],{offset:2})?{ext:"skp",mime:"application/vnd.sketchup.skp"}:void 0;if(this.checkString("-----BEGIN PGP MESSAGE-----"))return{ext:"pgp",mime:"application/pgp-encrypted"};if(this.buffer.length>=2&&this.check([255,224],{offset:0,mask:[255,224]})){if(this.check([16],{offset:1,mask:[22]}))return this.check([8],{offset:1,mask:[8]})?{ext:"aac",mime:"audio/aac"}:{ext:"aac",mime:"audio/aac"};if(this.check([2],{offset:1,mask:[6]}))return{ext:"mp3",mime:"audio/mpeg"};if(this.check([4],{offset:1,mask:[6]}))return{ext:"mp2",mime:"audio/mpeg"};if(this.check([6],{offset:1,mask:[6]}))return{ext:"mp1",mime:"audio/mpeg"}}}async readTiffTag(e){let r=await this.tokenizer.readToken(e?U:C);switch(this.tokenizer.ignore(10),r){case 50341:return{ext:"arw",mime:"image/x-sony-arw"};case 50706:return{ext:"dng",mime:"image/x-adobe-dng"};default:}}async readTiffIFD(e){let r=await this.tokenizer.readToken(e?U:C);for(let i=0;i<r;++i){let n=await this.readTiffTag(e);if(n)return n}}async readTiffHeader(e){let r=(e?U:C).get(this.buffer,2),i=(e?Be:Ee).get(this.buffer,4);if(r===42){if(i>=6){if(this.checkString("CR",{offset:8}))return{ext:"cr2",mime:"image/x-canon-cr2"};if(i>=8&&(this.check([28,0,254,0],{offset:8})||this.check([31,0,11,0],{offset:8})))return{ext:"nef",mime:"image/x-nikon-nef"}}return await this.tokenizer.ignore(i),await this.readTiffIFD(e)??{ext:"tif",mime:"image/tiff"}}if(r===43)return{ext:"tif",mime:"image/tiff"}}};var Ct=new Set(Ie),Ut=new Set(Oe);function ot(t){t=t.trim();let e;if(t.startsWith("assets://"))t=t.substring(9),e=!0;else if(t.startsWith("data://"))t=t.substring(7),e=!1;else throw new Error("[@cuberqaq/transfer-file] Unexpected arg fileName");return{path:t,isAssets:e}}var te=class{downloadFile(e){let r=new re,i=!1;return(typeof e.headers>"u"?I(e.url):I(e.url,{headers:e.headers})).then(async n=>{let s=await n.arrayBuffer();if(console.warn("[@cuberqaq/download-side]","Fetch Success:",s,"File type:",await je(s)),i||r._canceled)return;let a;if(typeof e.filePath<"u")a=e.filePath;else{let o;do o=~~(Math.random()*11451419)+1e7;while(typeof ye({path:"$TMP_"+o+"$"})<"u");a="data://$TMP_"+o+"$"}let f=ot(a),c;f.isAssets?c=ge({path:f.path,flag:J|j}):c=de({path:f.path,flag:J|j}),be({fd:c,buffer:s}),r.onSuccess({statusCode:n.status,filePath:typeof e.filePath<"u"?e.filePath:void 0,tempFilePath:typeof e.filePath>"u"?a:void 0})}).catch(n=>{console.error("[@cuberqaq/download-side]","Fetch Error:",n),r.onFail({code:1,message:""+n})}),r}},re=class{constructor(){this.onComplete=()=>{},this.onSuccess=()=>{},this.onFail=()=>{},this.onProgress=()=>{},this._canceled=!1}cancel(){}},Vt={downloader:new te};export{ot as _parseHmPath,Vt as network};
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */