From 0fe41f6e5f71a46ac88f7ea4c35939b7f06498ed Mon Sep 17 00:00:00 2001 From: Gildas Date: Thu, 21 Jan 2021 04:32:12 +0100 Subject: [PATCH] bump to version 2.0.6 --- dist/zip-fs-full.min.js | 2 +- dist/zip-fs.js | 251 ++++++++++++++++++++-------------------- dist/zip-fs.min.js | 2 +- dist/zip.js | 251 ++++++++++++++++++++-------------------- dist/zip.min.js | 2 +- package.json | 2 +- 6 files changed, 260 insertions(+), 250 deletions(-) diff --git a/dist/zip-fs-full.min.js b/dist/zip-fs-full.min.js index 6e361944..7cc51e9e 100644 --- a/dist/zip-fs-full.min.js +++ b/dist/zip-fs-full.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).zip={})}(this,(function(t){"use strict";const e="HTTP error ",n="HTTP Range not supported",s="text/plain";class i{constructor(){this.size=0}init(){this.initialized=!0}}class r extends i{}class a extends i{writeUint8Array(t){this.size+=t.length}}class o extends r{constructor(t){super(),this.blobReader=new l(new Blob([t],{type:s}))}init(){super.init(),this.blobReader.init(),this.size=this.blobReader.size}readUint8Array(t,e){return this.blobReader.readUint8Array(t,e)}}class d extends a{constructor(t){super(),this.encoding=t,this.blob=new Blob([],{type:s})}writeUint8Array(t){super.writeUint8Array(t),this.blob=new Blob([this.blob,t.buffer],{type:s})}getData(){const t=new FileReader;return new Promise(((e,n)=>{t.onload=t=>e(t.target.result),t.onerror=n,t.readAsText(this.blob,this.encoding)}))}}class c extends r{constructor(t){super(),this.dataURI=t;let e=t.length;for(;"="==t.charAt(e-1);)e--;this.dataStart=t.indexOf(",")+1,this.size=Math.floor(.75*(e-this.dataStart))}readUint8Array(t,e){const n=new Uint8Array(e),s=4*Math.floor(t/3),i=atob(this.dataURI.substring(s+this.dataStart,4*Math.ceil((t+e)/3)+this.dataStart)),r=t-3*Math.floor(s/4);for(let t=r;t2?this.data+=btoa(n):this.pending=n}getData(){return this.data+btoa(this.pending)}}class l extends r{constructor(t){super(),this.blob=t,this.size=t.size}readUint8Array(t,e){const n=new FileReader;return new Promise(((s,i)=>{n.onload=t=>s(new Uint8Array(t.target.result)),n.onerror=i,n.readAsArrayBuffer(this.blob.slice(t,t+e))}))}}class m extends a{constructor(t){super(),this.offset=0,this.contentType=t,this.blob=new Blob([],{type:t})}writeUint8Array(t){super.writeUint8Array(t),this.blob=new Blob([this.blob,t.buffer],{type:this.contentType}),this.offset=this.blob.size}getData(){return this.blob}}class h extends r{constructor(t){super(),this.url=t}async init(){if(super.init(),function(t){if("undefined"!=typeof document){const e=document.createElement("a");return e.href=t,"http:"==e.protocol||"https:"==e.protocol}return/^https?:\/\//i.test(t)}(this.url))return new Promise(((t,n)=>{const s=new XMLHttpRequest;s.addEventListener("load",(()=>{s.status<400?(this.size=Number(s.getResponseHeader("Content-Length")),this.size?t():u().then((()=>t())).catch(n)):n(e+(s.statusText||s.status)+".")}),!1),s.addEventListener("error",n,!1),s.open("HEAD",this.url),s.send()}));await u()}async readUint8Array(t,e){return this.data||await u(this,this.url),new Uint8Array(this.data.subarray(t,t+e))}}class f extends r{constructor(t){super(),this.url=t}init(){return super.init(),new Promise(((t,s)=>{const i=new XMLHttpRequest;i.addEventListener("load",(()=>{i.status<400?(this.size=Number(i.getResponseHeader("Content-Length")),"bytes"==i.getResponseHeader("Accept-Ranges")?t():s(new Error(n))):s(e+(i.statusText||i.status)+".")}),!1),i.addEventListener("error",s,!1),i.open("HEAD",this.url),i.send()}))}readUint8Array(t,n){return new Promise(((s,i)=>{const r=new XMLHttpRequest;r.open("GET",this.url),r.responseType="arraybuffer",r.setRequestHeader("Range","bytes="+t+"-"+(t+n-1)),r.addEventListener("load",(()=>{r.status<400?s(new Uint8Array(r.response)):i(e+(r.statusText||r.status)+".")}),!1),r.addEventListener("error",i,!1),r.send()}))}}class x extends a{constructor(){super(),this.array=new Uint8Array(0)}writeUint8Array(t){super.writeUint8Array(t);const e=this.array;this.array=new Uint8Array(e.length+t.length),this.array.set(e),this.array.set(t,e.length)}getData(){return this.array}}function u(t,n){return new Promise(((s,i)=>{const r=new XMLHttpRequest;r.addEventListener("load",(()=>{r.status<400?(t.size||(t.size=Number(r.getResponseHeader("Content-Length"))||Number(r.response.byteLength)),t.data=new Uint8Array(r.response),s()):i(e+(r.statusText||r.status)+".")}),!1),r.addEventListener("error",i,!1),r.open("GET",n),r.responseType="arraybuffer",r.send()}))}const g=4294967295,v=65535,w=1347093252,y=1347094280,b=1347092738,k=1347093766,U=1347094022,z=1347094023,E=39169,A=45,R=51;class D{constructor(){this.crc=-1,this.table=(()=>{const t=[];for(let e=0;e<256;e++){let n=e;for(let t=0;t<8;t++)1&n?n=n>>>1^3988292384:n>>>=1;t[e]=n}return t})()}append(t){const e=this.table;let n=0|this.crc;for(let s=0,i=0|t.length;s>>8^e[255&(n^t[s])];this.crc=n}get(){return~this.crc}}const j="Invalid pasword",F=16,I="raw",S={name:"PBKDF2"},B={name:"HMAC"},T="SHA-1",L={name:"AES-CTR"},_=Object.assign({hash:B},S),q=Object.assign({iterations:1e3,hash:{name:T}},S),N=Object.assign({hash:T},B),O=Object.assign({length:F},L),M=["deriveBits"],C=["sign"],P=528,V=10,Z=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],W=crypto.subtle;class H{constructor(t,e){this.password=t,this.signed=e,this.input=e&&new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(t){const e=async(i=0)=>{if(i+F<=s.length-V){const t=s.subarray(i,i+F),r=await W.decrypt(Object.assign({counter:this.counter},O),this.keys.decrypt,t);return X(this.counter),n.set(new Uint8Array(r),i),e(i+F)}return this.pendingInput=s.subarray(i),this.signed&&(this.input=Y(this.input,t)),n};if(this.password){const e=t.subarray(0,18);await async function(t,e,n){t.counter=new Uint8Array(Z);const s=e.subarray(0,16),i=e.subarray(16),r=(new TextEncoder).encode(n),a=await W.importKey(I,r,_,!1,M),o=await W.deriveBits(Object.assign({salt:s},q),a,528),d=new Uint8Array(o),c=d.subarray(64);if(t.keys={decrypt:await W.importKey(I,d.subarray(0,32),L,!0,["decrypt"]),authentication:await W.importKey(I,d.subarray(32,64),N,!1,C),passwordVerification:c},c[0]!=i[0]||c[1]!=i[1])throw new Error(j)}(this,e,this.password),this.password=null,t=t.subarray(18)}let n=new Uint8Array(t.length-V-(t.length-V)%F),s=t;return this.pendingInput.length&&(s=Y(this.pendingInput,t),n=G(n,s.length-V-(s.length-V)%F)),e()}async flush(){const t=this.pendingInput,e=this.keys,n=t.subarray(0,t.length-V),s=t.subarray(t.length-V);let i=new Uint8Array(0);if(n.length){const t=await W.decrypt(Object.assign({counter:this.counter},O),e.decrypt,n);i=new Uint8Array(t)}let r=!0;if(this.signed){const t=await W.sign(B,e.authentication,this.input.subarray(0,this.input.length-V)),n=new Uint8Array(t);this.input=null;for(let t=0;t{if(i+F<=t.length){const r=t.subarray(i,i+F),a=await W.encrypt(Object.assign({counter:this.counter},O),this.keys.encrypt,r);return X(this.counter),s.set(new Uint8Array(a),i+n.length),e(i+F)}return this.pendingInput=t.subarray(i),this.output=Y(this.output,s),s};let n=new Uint8Array(0);this.password&&(n=await async function(t,e){t.counter=new Uint8Array(Z);const n=crypto.getRandomValues(new Uint8Array(16)),s=(new TextEncoder).encode(e),i=await W.importKey(I,s,_,!1,M),r=await W.deriveBits(Object.assign({salt:n},q),i,P),a=new Uint8Array(r);return t.keys={encrypt:await W.importKey(I,a.subarray(0,32),L,!0,["encrypt"]),authentication:await W.importKey(I,a.subarray(32,64),N,!1,C),passwordVerification:a.subarray(64)},Y(n,t.keys.passwordVerification)}(this,this.password),this.password=null);let s=new Uint8Array(n.length+t.length-t.length%F);return s.set(n,0),this.pendingInput.length&&(t=Y(this.pendingInput,t),s=G(s,t.length-t.length%F)),e()}async flush(){let t=new Uint8Array(0);if(this.pendingInput.length){const e=await W.encrypt(Object.assign({counter:this.counter},O),this.keys.encrypt,this.pendingInput);t=new Uint8Array(e),this.output=Y(this.output,t)}const e=await W.sign(B,this.keys.authentication,this.output.subarray(18));this.output=null;const n=new Uint8Array(e).subarray(0,V);return{data:Y(t,n),signature:n}}}function X(t){for(let e=0;e<16;e++){if(255!=t[e]){t[e]++;break}t[e]=0}}function Y(t,e){let n=t;return t.length+e.length&&(n=new Uint8Array(t.length+e.length),n.set(t,0),n.set(e,t.length)),n}function G(t,e){if(e&&e>t.length){const n=t;(t=new Uint8Array(e)).set(n,0)}return t}const J="deflate",Q="inflate",$="Invalid signature";class tt{constructor(t){this.signature=t.inputSignature,this.encrypted=Boolean(t.inputPassword),this.signed=t.inputSigned,this.compressed=t.inputCompressed,this.inflate=this.compressed&&new ZipInflate,this.crc32=this.signed&&this.signed&&new D,this.decrypt=this.encrypted&&new H(t.inputPassword)}async append(t){return this.encrypted&&(t=await this.decrypt.append(t)),this.compressed&&t.length&&(t=await this.inflate.append(t)),!this.encrypted&&this.signed&&this.crc32.append(t),t}async flush(){let t,e=new Uint8Array(0);if(this.encrypted){const t=await this.decrypt.flush();if(!t.valid)throw new Error($);e=t.data}else if(this.signed){const e=new DataView(new Uint8Array(4).buffer);if(t=this.crc32.get(),e.setUint32(0,t),this.signature!=e.getUint32(0,!1))throw new Error($)}return this.compressed&&(e=await this.inflate.append(e)||new Uint8Array(0),await this.inflate.flush()),{data:e,signature:t}}}class et{constructor(t){this.encrypted=t.outputEncrypted,this.signed=t.outputSigned,this.compressed=t.outputCompressed,this.deflate=this.compressed&&new ZipDeflate({level:t.level||5}),this.crc32=this.signed&&new D,this.encrypt=this.encrypted&&new K(t.outputPassword)}async append(t){let e=t;return this.compressed&&t.length&&(e=await this.deflate.append(t)),this.encrypted?e=await this.encrypt.append(e):this.signed&&this.crc32.append(t),e}async flush(){let t,e=new Uint8Array(0);if(this.compressed&&(e=await this.deflate.flush()||new Uint8Array(0)),this.encrypted){e=await this.encrypt.append(e);const n=await this.encrypt.flush();t=n.signature;const s=new Uint8Array(e.length+n.data.length);s.set(e,0),s.set(n.data,e.length),e=s}else this.signed&&(t=this.crc32.get());return{data:e,signature:t}}}const nt="init",st="append",it="flush",rt="message",at="z-worker.js",ot={deflate:[at,"deflate.js"],inflate:[at,"inflate.js"]},dt={pool:[],pendingRequests:[]};function ct(t,e){const n=dt.pool;let s;if(t.useWebWorkers){const n=e.codecType;if(null!=t.workerScripts&&null!=t.workerScriptsPath)throw new Error("Either workerScripts or workerScriptsPath may be set, not both");if(t.workerScripts){if(s=t.workerScripts[n],!Array.isArray(s))throw new Error("workerScripts."+n+" must be an array");i=s,s="undefined"!=typeof document?i.map((t=>new URL(t,document.baseURI).href)):i}else s=ot[n].slice(0),s[0]=(t.workerScriptsPath||"")+s[0]}var i;if(n.lengths({type:st,data:t}),flush:async()=>s({type:it})},t.interface;async function s(e){if(!n){const e=t.scripts.slice(1);await i(Object.assign({type:nt,options:t.options,scripts:e}))}return i(e)}function i(s){try{if(s.data)try{e.postMessage(s,[s.data.buffer])}catch(t){e.postMessage(s)}else e.postMessage(s)}catch(e){n.reject(e),n=null,mt(t)}return new Promise(((t,e)=>n={resolve:t,reject:e}))}function r(e){const s=e.data;if(n){const e=s.error;if(e){const s=new Error(e.message);s.stack=e.stack,n.reject(s),n=null,mt(t)}else s.type!=nt&&s.type!=it&&s.type!=st||(s.type==it?(n.resolve({data:new Uint8Array(s.data),signature:s.signature}),n=null,mt(t)):n.resolve(s.data&&new Uint8Array(s.data)))}}}(t):pt(t)}{const t=n.find((t=>!t.busy));return t?(t.busy=!0,t.options=e,t.scripts=s,s?t.interface:pt(t)):new Promise((t=>dt.pendingRequests.push({resolve:t,options:e,scripts:s})))}}function pt(t){const e=(n=t.options).codecType.startsWith(J)?new et(n):n.codecType.startsWith(Q)?new tt(n):void 0;var n;const s=e.append.bind(e),i=e.flush.bind(e);return e.append=async e=>{try{return await s(e)}catch(e){throw await lt(t),e}},e.flush=async()=>{try{return await i()}finally{await lt(t)}},e}async function lt(t){if(t.busy=!1,dt.pendingRequests.length){const[{resolve:e,options:n}]=dt.pendingRequests.splice(0,1);t.busy=!0,t.options=n,e(pt(t))}else dt.pool=dt.pool.filter((e=>e!=t))}function mt(t){if(t.busy=!1,dt.pendingRequests.length){const[{resolve:e,options:n,scripts:s}]=dt.pendingRequests.splice(0,1);t.busy=!0,t.options=n,t.scripts=s,e(t.interface)}else t.worker.terminate(),dt.pool=dt.pool.filter((e=>e!=t))}async function ht(t,e,n,s,i,r,a){const o=Math.max(r.chunkSize,64);return async function r(d=0,c=0){const p=d*o;if(p>1,dataDescriptor:8==(8&s),languageEncodingFlag:2048==(2048&s)},t.encrypted=t.bitFlag.encrypted,t.rawLastModDate=e.getUint32(n+6,!0),t.lastModDate=function(t){const e=(4294901760&t)>>16,n=65535&t;try{return new Date(1980+((65024&e)>>9),((480&e)>>5)-1,31&e,(63488&n)>>11,(2016&n)>>5,2*(31&n),0)}catch(t){}}(t.rawLastModDate),t.filenameLength=e.getUint16(n+22,!0),t.extraFieldLength=e.getUint16(n+24,!0)}function Ft(t,e,n,s){let i,r,a;const o=e.rawExtraField,d=e.extraField=new Map,c=new DataView(new Uint8Array(o).buffer);let p=0;try{for(;pe[t]==g));for(let e=0;e{if(e[n]==g){if(!t||void 0===t[n])throw new Error(bt);e[n]=t&&t[n]}}))}(i,e),a=e.extraFieldUnicodePath=d.get(28789),a&&function(t,e,n){const s=new DataView(t.data.buffer);t.version=s.getUint8(0),t.signature=s.getUint32(1,!0);const i=new D;i.append(n.rawFilename);const r=new DataView(new Uint8Array(4).buffer);r.setUint32(0,i.get()),t.filename=(new TextDecoder).decode(t.data.subarray(5)),t.signature==r.getUint32(0,!1)&&(e.filename=t.filename)}(a,e,t),r=e.extraFieldAES=d.get(39169),r?function(t,e,n){if(t){const s=new DataView(t.data.buffer);t.vendorVersion=s.getUint8(0),t.vendorId=s.getUint8(2);const i=s.getUint8(4);t.strength=i,t.originalCompressionMethod=n,e.compressionMethod=t.compressionMethod=s.getUint16(5,!0)}else e.compressionMethod=n}(r,e,l):e.compressionMethod=l,8==e.compressionMethod&&(e.bitFlag.enhancedDeflating=16!=(16&e.rawBitFlag))}function It(t,e){return new TextDecoder(e).decode(t)}const St="File already exists",Bt="Zip file comment exceeds 64KB",Tt="File entry comment exceeds 64KB",Lt="File entry name exceeds 64KB",_t="Version exceeds 65535",qt="Extra field type exceeds 65535",Nt="Extra field data exceeds 64KB",Ot=new Uint8Array([7,0,2,0,65,69,3,0,0]);function Mt(t){return unescape(encodeURIComponent(t))}function Ct(t){const e=[];for(let n=0;n{if(this.pendingData){const e=this.pendingData;this.pendingData=new Uint8Array(e.length+t.length),this.pendingData.set(e,0),this.pendingData.set(t,e.length)}else this.pendingData=new Uint8Array(t)};if(this.codec=new t(Object.assign({},e,n)),typeof this.codec.onData==Pt)this.codec.onData=s;else{if(typeof this.codec.on!=Pt)throw new Error("Cannot register the callback function");this.codec.on("data",s)}}async append(t){return this.codec.push(t),n(this)}async flush(){return this.codec.push(new Uint8Array(0),!0),n(this)}};function n(t){if(t.pendingData){const e=t.pendingData;return t.pendingData=null,e}return new Uint8Array(0)}}const Zt={chunkSize:524288,maxWorkers:"undefined"!=typeof navigator&&navigator.hardwareConcurrency||2,workerScriptsPath:void 0,useWebWorkers:!0};let Wt=Object.assign({},Zt);class Ht extends class{constructor(t,e={},n={}){this.reader=t,this.options=e,this.config=n}async getEntries(){const t=this.reader;t.initialized||await t.init();const e=await async function(t,e,n,s){const i=new Uint8Array(4);if(new DataView(i.buffer).setUint32(0,e),t.size=0;t--)if(r[t]==i[0]&&r[t+1]==i[1]&&r[t+2]==i[2]&&r[t+3]==i[3])return{offset:s,buffer:r.slice(t,t+n).buffer}}}(t,k,22,v);let n,s=new DataView(e.buffer),i=s.getUint32(16,!0),r=s.getUint16(8,!0);if(i==g||r==v){n=!0;const s=await t.readUint8Array(e.offset-20,20),a=new DataView(s.buffer);if(Number(a.getUint32(0,!1))!=z)throw new Error(gt);i=Number(a.getBigUint64(8,!0));const o=await t.readUint8Array(i,56),d=new DataView(o.buffer);if(Number(d.getUint32(0,!1))!=U)throw new Error(vt);r=Number(d.getBigUint64(24,!0)),i-=Number(d.getBigUint64(40,!0))}if(i<0||!n&&(i>=t.size||r>=v))throw new Error(xt);const a=await t.readUint8Array(i,t.size-i);s=new DataView(a.buffer);const o=[];let d=0;for(let t=0;tv)throw new Error(Tt);n.zip64=n.zip64||this.zip64,await async function(t,e,n,s){const i=t.files,r=t.writer;let a;i.set(e,null);try{let o,d;try{s.bufferedWrite||t.options.bufferedWrite||t.lockWrite?(o=new x,o.init()):(t.lockWrite=new Promise((t=>a=t)),r.initialized||await r.init(),o=r),(t.offset>=g||n&&(n.size>=g||t.offset+n.size>=g))&&(s.zip64=!0),d=await async function(t,e,n,s,i,r){const a=Ct(Mt(t)),o=r.lastModDate||new Date,d=new Uint8Array(26),c=new DataView(d.buffer),p=void 0===r.password?i.password:r.password,l=p&&p.length&&p,m=void 0===r.level?i.level:r.level,h=0!==m&&!r.directory,f=void 0===p||!p.length,x=r.zip64;let u;if(l){u=new Uint8Array(Ot.length+2);new DataView(u.buffer).setUint16(0,E,!0),u.set(Ot,2)}else u=new Uint8Array(0);const b={zip64:x,headerArray:d,directory:r.directory,filename:a,comment:r.comment,extraFieldZip64:x?new Uint8Array(28):new Uint8Array(0),extraFieldAES:u,rawExtraField:new Uint8Array(0)},k=r.extraField;if(a.length>v)throw new Error(Lt);if(k){let t=4,e=0;k.forEach((e=>t+=e.length));const n=b.rawExtraField=new Uint8Array(t);k.forEach(((t,s)=>{if(s>v)throw new Error(qt);if(t.length>v)throw new Error(Nt);n.set(new Uint16Array([s]),e),n.set(new Uint16Array([t.length]),e+2),n.set(t,e+4),e+=4+t.length}))}if(r.bitFlag=8,r.version=(void 0===r.version?i.version:r.version)||20,r.version>v)throw new Error(_t);r.compressionMethod=0,h&&(r.compressionMethod=8);x&&(r.version=r.version>A?r.version:A);l&&(b.encrypted=!0,r.version=r.version>R?r.version:R,r.bitFlag=1|r.bitFlag,r.compressionMethod=99,h&&(b.extraFieldAES[9]=8));c.setUint16(0,r.version,!0),c.setUint16(2,r.bitFlag,!0),c.setUint16(4,r.compressionMethod,!0),c.setUint16(6,(o.getHours()<<6|o.getMinutes())<<5|o.getSeconds()/2,!0),c.setUint16(8,(o.getFullYear()-1980<<4|o.getMonth()+1)<<5|o.getDate(),!0),c.setUint16(22,a.length,!0),c.setUint16(24,0,!0);const U=new Uint8Array(30+a.length);let z;if(new DataView(U.buffer).setUint32(0,w),U.set(d,4),U.set(a,30),e){e.initialized||await e.init();const t=await ct(s,{codecType:J,level:m,outputPassword:p,outputSigned:f,outputCompressed:h,outputEncrypted:Boolean(p)});await n.writeUint8Array(U),z=await ht(t,e,n,0,e.size,s,{onprogress:r.onprogress}),b.compressedSize=z.length}else await n.writeUint8Array(U);const D=new Uint8Array(x?24:16),j=new DataView(D.buffer);if(j.setUint32(0,y),e)if(l||void 0===z.signature||(c.setUint32(10,z.signature,!0),j.setUint32(4,z.signature,!0)),x){c.setUint32(14,g,!0),j.setBigUint64(8,BigInt(b.compressedSize),!0),c.setUint32(18,g,!0),j.setBigUint64(16,BigInt(e.size),!0);const t=new DataView(b.extraFieldZip64.buffer);t.setUint16(0,1,!0),t.setUint16(2,24,!0),t.setBigUint64(4,BigInt(e.size),!0),t.setBigUint64(12,BigInt(b.compressedSize),!0)}else c.setUint32(14,b.compressedSize,!0),j.setUint32(8,b.compressedSize,!0),c.setUint32(18,e.size,!0),j.setUint32(12,e.size,!0);return await n.writeUint8Array(D),b.length=U.length+(z?z.length:0)+D.length,b}(e,n,o,t.config,t.options,s)}catch(t){throw i.delete(e),t}if(i.set(e,d),o!=r&&(t.lockWrite&&await t.lockWrite,await r.writeUint8Array(o.getData())),d.offset=t.offset,d.zip64){new DataView(d.extraFieldZip64.buffer).setBigUint64(20,BigInt(d.offset),!0)}t.offset+=d.length}finally{a&&(t.lockWrite=null,a())}}(this,t,e,n)}async close(t){const e=this.writer,n=this.files;let s=0,i=0,r=this.offset,a=n.size;if(t&&t.length){if(!(t.length<=v))throw new Error(Bt);d.setUint16(s+20,t.length,!0)}for(const[,t]of n)i+=46+t.filename.length+t.comment.length+t.extraFieldZip64.length+t.extraFieldAES.length+t.rawExtraField.length;(r+i>=g||a>=v)&&(this.zip64=!0);const o=new Uint8Array(i+(this.zip64?98:22)),d=new DataView(o.buffer);this.options.version=this.options.version||20;for(const[,t]of n){const e=t.filename,n=t.extraFieldZip64,i=t.extraFieldAES,r=n.length+i.length+t.rawExtraField.length;d.setUint32(s,b),t.zip64&&d.setUint16(s+4,this.options.version>A?this.options:A,!0),t.encrypted?d.setUint16(s+4,this.options.version>R?this.options:R,!0):d.setUint16(s+4,this.options.version>20?this.options:20,!0),o.set(t.headerArray,s+6),d.setUint16(s+30,r,!0),d.setUint16(s+32,t.comment.length,!0),t.directory&&d.setUint8(s+38,16),t.zip64?d.setUint32(s+42,g,!0):d.setUint32(s+42,t.offset,!0),o.set(e,s+46),o.set(n,s+46+e.length),o.set(i,s+46+e.length+n.length),o.set(t.rawExtraField,46+e.length+n.length+i.length),o.set(t.comment,s+46+e.length+r),s+=46+e.length+r+t.comment.length}return this.zip64&&(d.setUint32(s,U),d.setBigUint64(s+4,BigInt(44),!0),d.setUint16(s+12,45,!0),d.setUint16(s+14,45,!0),d.setBigUint64(s+24,BigInt(a),!0),d.setBigUint64(s+32,BigInt(a),!0),d.setBigUint64(s+40,BigInt(i),!0),d.setBigUint64(s+48,BigInt(r),!0),d.setUint32(s+56,z),d.setBigUint64(s+64,BigInt(r+i),!0),d.setUint32(s+72,1,!0),a=v,r=g,s+=76),d.setUint32(s,k),d.setUint16(s+8,a,!0),d.setUint16(s+10,a,!0),d.setUint32(s+12,i,!0),d.setUint32(s+16,r,!0),await e.writeUint8Array(o),t&&t.length&&await e.writeUint8Array(t),e.getData()}}{constructor(t,e){super(t,e,Wt)}}const Xt=524288;class Yt{constructor(t,e,n,s){if(t.root&&s&&s.getChildByName(e))throw new Error("Entry filename already exists");n||(n={}),this.fs=t,this.name=e,this.id=t.entries.length,this.parent=s,this.children=[],this.zipVersion=n.zipVersion||20,this.uncompressedSize=0,t.entries.push(this),s&&this.parent.children.push(this)}moveTo(t){if(!t.directory)throw new Error("Target entry is not a directory");if(t.isDescendantOf(this))throw new Error("Entry is a ancestor of target entry");if(this!=t){if(t.getChildByName(this.name))throw new Error("Entry filename already exists");ne(this),this.parent=t,t.children.push(this)}}getFullname(){let t=this.name,e=this.parent;for(;e;)t=(e.name?e.name+"/":"")+t,e=e.parent;return t}isDescendantOf(t){let e=this.parent;for(;e&&e.id!=t.id;)e=e.parent;return Boolean(e)}}class Gt extends Yt{constructor(t,e,n,s){super(t,e,n,s),this.Reader=n.Reader,this.Writer=n.Writer,this.data=n.data,n.getData&&(this.getData=n.getData)}async getData(t,e={}){return!t||t.constructor==this.Writer&&this.data?this.data:(this.reader||(this.reader=new this.Reader(this.data)),await this.reader.init(),await t.init(),this.uncompressedSize=this.reader.size,async function(t,e,n){return s();async function s(i=0){const r=i*Xt;if(n.onprogress&&n.onprogress(r,t.size),r{e.file((s=>{t.addBlob(e.name,s),n()}),s)}));function n(t){return new Promise(((e,n)=>{let s=[];function i(t){t.readEntries((n=>{n.length?(s=s.concat(n),i(t)):e(s)}),n)}t.isDirectory&&i(t.createReader()),t.isFile&&e(s)}))}async function s(t,e){const i=await n(e);for(const e of i)e.isDirectory&&await s(t.addDirectory(e.name)),await new Promise(((n,s)=>{e.isFile&&e.file((s=>{const i=t.addBlob(e.name,s);i.uncompressedSize=s.size,n(i)}),s)}))}}(this,t)}async addData(t,e){return ie(this,t,e)}async importBlob(t,e={}){await this.importZip(new l(t),e)}async importData64URI(t,e={}){await this.importZip(new c(t),e)}async importHttpContent(t,e={}){await this.importZip(e.useRangeHeader?new f(t):new h(t),e)}async exportBlob(t={}){return this.exportZip(new m("application/zip"),t)}async exportData64URI(t={}){return this.exportZip(new p("application/zip"),t)}async importZip(t,e){await t.init();const n=new Ht(t),s=await n.getEntries();let i=0;const r=$t(s,"compressedSize");s.forEach((t=>{let n=this,s=t.filename.split("/"),a=s.pop();if(s.forEach((t=>n=n.getChildByName(t)||new Jt(this.fs,t,null,n))),!t.directory){let s=i;ie(n,a,{data:t,Reader:te(Object.assign({},e,{onprogress:t=>{e.onprogress&&e.onprogress(s+t,r)}}))}),i+=t.compressedSize}}))}async exportZip(t,e){await ee(this);const n=new Kt(t);return await async function(t,e,n,s){let i=0;async function r(t,e){async function a(){let a=0;for(const o of e.children){let e=i;await t.add(o.getFullname(),o.reader,Object.assign({directory:o.directory,version:o.zipVersion},s,{onprogress:t=>{s.onprogress&&s.onprogress(e+a+t,n)}})),i+=o.uncompressedSize,await r(t,o),a++}}await a()}await r(t,e)}(n,this,$t([this],"uncompressedSize"),e),await n.close(),t.getData()}getChildByName(t){for(let e=0;e{n.id==t.id&&e.splice(s,1)}))}function se(t){t.entries=[],t.root=new Jt(t)}function ie(t,e,n,s){if(t.directory)return s?new Jt(t.fs,e,n,t):new Gt(t.fs,e,n,t);throw new Error("Parent entry is not a directory")}const re={application:{"andrew-inset":"ez",annodex:"anx","atom+xml":"atom","atomcat+xml":"atomcat","atomserv+xml":"atomsrv",bbolin:"lin",cap:["cap","pcap"],"cu-seeme":"cu","davmount+xml":"davmount",dsptype:"tsp",ecmascript:["es","ecma"],futuresplash:"spl",hta:"hta","java-archive":"jar","java-serialized-object":"ser","java-vm":"class",javascript:"js",m3g:"m3g","mac-binhex40":"hqx",mathematica:["nb","ma","mb"],msaccess:"mdb",msword:["doc","dot"],mxf:"mxf",oda:"oda",ogg:"ogx",pdf:"pdf","pgp-keys":"key","pgp-signature":["asc","sig"],"pics-rules":"prf",postscript:["ps","ai","eps","epsi","epsf","eps2","eps3"],rar:"rar","rdf+xml":"rdf","rss+xml":"rss",rtf:"rtf",smil:["smi","smil"],"xhtml+xml":["xhtml","xht"],xml:["xml","xsl","xsd"],"xspf+xml":"xspf",zip:"zip","vnd.android.package-archive":"apk","vnd.cinderella":"cdy","vnd.google-earth.kml+xml":"kml","vnd.google-earth.kmz":"kmz","vnd.mozilla.xul+xml":"xul","vnd.ms-excel":["xls","xlb","xlt","xlm","xla","xlc","xlw"],"vnd.ms-pki.seccat":"cat","vnd.ms-pki.stl":"stl","vnd.ms-powerpoint":["ppt","pps","pot"],"vnd.oasis.opendocument.chart":"odc","vnd.oasis.opendocument.database":"odb","vnd.oasis.opendocument.formula":"odf","vnd.oasis.opendocument.graphics":"odg","vnd.oasis.opendocument.graphics-template":"otg","vnd.oasis.opendocument.image":"odi","vnd.oasis.opendocument.presentation":"odp","vnd.oasis.opendocument.presentation-template":"otp","vnd.oasis.opendocument.spreadsheet":"ods","vnd.oasis.opendocument.spreadsheet-template":"ots","vnd.oasis.opendocument.text":"odt","vnd.oasis.opendocument.text-master":"odm","vnd.oasis.opendocument.text-template":"ott","vnd.oasis.opendocument.text-web":"oth","vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","vnd.openxmlformats-officedocument.spreadsheetml.template":"xltx","vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","vnd.openxmlformats-officedocument.presentationml.slideshow":"ppsx","vnd.openxmlformats-officedocument.presentationml.template":"potx","vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","vnd.openxmlformats-officedocument.wordprocessingml.template":"dotx","vnd.smaf":"mmf","vnd.stardivision.calc":"sdc","vnd.stardivision.chart":"sds","vnd.stardivision.draw":"sda","vnd.stardivision.impress":"sdd","vnd.stardivision.math":["sdf","smf"],"vnd.stardivision.writer":["sdw","vor"],"vnd.stardivision.writer-global":"sgl","vnd.sun.xml.calc":"sxc","vnd.sun.xml.calc.template":"stc","vnd.sun.xml.draw":"sxd","vnd.sun.xml.draw.template":"std","vnd.sun.xml.impress":"sxi","vnd.sun.xml.impress.template":"sti","vnd.sun.xml.math":"sxm","vnd.sun.xml.writer":"sxw","vnd.sun.xml.writer.global":"sxg","vnd.sun.xml.writer.template":"stw","vnd.symbian.install":["sis","sisx"],"vnd.visio":["vsd","vst","vss","vsw"],"vnd.wap.wbxml":"wbxml","vnd.wap.wmlc":"wmlc","vnd.wap.wmlscriptc":"wmlsc","vnd.wordperfect":"wpd","vnd.wordperfect5.1":"wp5","x-123":"wk","x-7z-compressed":"7z","x-abiword":"abw","x-apple-diskimage":"dmg","x-bcpio":"bcpio","x-bittorrent":"torrent","x-cbr":["cbr","cba","cbt","cb7"],"x-cbz":"cbz","x-cdf":["cdf","cda"],"x-cdlink":"vcd","x-chess-pgn":"pgn","x-cpio":"cpio","x-csh":"csh","x-debian-package":["deb","udeb"],"x-director":["dcr","dir","dxr","cst","cct","cxt","w3d","fgd","swa"],"x-dms":"dms","x-doom":"wad","x-dvi":"dvi","x-httpd-eruby":"rhtml","x-font":"pcf.Z","x-freemind":"mm","x-gnumeric":"gnumeric","x-go-sgf":"sgf","x-graphing-calculator":"gcf","x-gtar":["gtar","taz"],"x-hdf":"hdf","x-httpd-php":["phtml","pht","php"],"x-httpd-php-source":"phps","x-httpd-php3":"php3","x-httpd-php3-preprocessed":"php3p","x-httpd-php4":"php4","x-httpd-php5":"php5","x-ica":"ica","x-info":"info","x-internet-signup":["ins","isp"],"x-iphone":"iii","x-iso9660-image":"iso","x-java-jnlp-file":"jnlp","x-jmol":"jmz","x-killustrator":"kil","x-koan":["skp","skd","skt","skm"],"x-kpresenter":["kpr","kpt"],"x-kword":["kwd","kwt"],"x-latex":"latex","x-lha":"lha","x-lyx":"lyx","x-lzh":"lzh","x-lzx":"lzx","x-maker":["frm","maker","frame","fm","fb","book","fbdoc"],"x-ms-wmd":"wmd","x-ms-wmz":"wmz","x-msdos-program":["com","exe","bat","dll"],"x-msi":"msi","x-netcdf":["nc","cdf"],"x-ns-proxy-autoconfig":["pac","dat"],"x-nwc":"nwc","x-object":"o","x-oz-application":"oza","x-pkcs7-certreqresp":"p7r","x-python-code":["pyc","pyo"],"x-qgis":["qgs","shp","shx"],"x-quicktimeplayer":"qtl","x-redhat-package-manager":"rpm","x-ruby":"rb","x-sh":"sh","x-shar":"shar","x-shockwave-flash":["swf","swfl"],"x-silverlight":"scr","x-stuffit":"sit","x-sv4cpio":"sv4cpio","x-sv4crc":"sv4crc","x-tar":"tar","x-tcl":"tcl","x-tex-gf":"gf","x-tex-pk":"pk","x-texinfo":["texinfo","texi"],"x-trash":["~","%","bak","old","sik"],"x-troff":["t","tr","roff"],"x-troff-man":"man","x-troff-me":"me","x-troff-ms":"ms","x-ustar":"ustar","x-wais-source":"src","x-wingz":"wz","x-x509-ca-cert":["crt","der","cer"],"x-xcf":"xcf","x-xfig":"fig","x-xpinstall":"xpi",applixware:"aw","atomsvc+xml":"atomsvc","ccxml+xml":"ccxml","cdmi-capability":"cdmia","cdmi-container":"cdmic","cdmi-domain":"cdmid","cdmi-object":"cdmio","cdmi-queue":"cdmiq","docbook+xml":"dbk","dssc+der":"dssc","dssc+xml":"xdssc","emma+xml":"emma","epub+zip":"epub",exi:"exi","font-tdpfr":"pfr","gml+xml":"gml","gpx+xml":"gpx",gxf:"gxf",hyperstudio:"stk","inkml+xml":["ink","inkml"],ipfix:"ipfix",json:"json","jsonml+json":"jsonml","lost+xml":"lostxml","mads+xml":"mads",marc:"mrc","marcxml+xml":"mrcx","mathml+xml":"mathml",mbox:"mbox","mediaservercontrol+xml":"mscml","metalink+xml":"metalink","metalink4+xml":"meta4","mets+xml":"mets","mods+xml":"mods",mp21:["m21","mp21"],mp4:"mp4s","oebps-package+xml":"opf","omdoc+xml":"omdoc",onenote:["onetoc","onetoc2","onetmp","onepkg"],oxps:"oxps","patch-ops-error+xml":"xer","pgp-encrypted":"pgp",pkcs10:"p10","pkcs7-mime":["p7m","p7c"],"pkcs7-signature":"p7s",pkcs8:"p8","pkix-attr-cert":"ac","pkix-crl":"crl","pkix-pkipath":"pkipath",pkixcmp:"pki","pls+xml":"pls","prs.cww":"cww","pskc+xml":"pskcxml","reginfo+xml":"rif","relax-ng-compact-syntax":"rnc","resource-lists+xml":"rl","resource-lists-diff+xml":"rld","rls-services+xml":"rs","rpki-ghostbusters":"gbr","rpki-manifest":"mft","rpki-roa":"roa","rsd+xml":"rsd","sbml+xml":"sbml","scvp-cv-request":"scq","scvp-cv-response":"scs","scvp-vp-request":"spq","scvp-vp-response":"spp",sdp:"sdp","set-payment-initiation":"setpay","set-registration-initiation":"setreg","shf+xml":"shf","sparql-query":"rq","sparql-results+xml":"srx",srgs:"gram","srgs+xml":"grxml","sru+xml":"sru","ssdl+xml":"ssdl","ssml+xml":"ssml","tei+xml":["tei","teicorpus"],"thraud+xml":"tfi","timestamped-data":"tsd","vnd.3gpp.pic-bw-large":"plb","vnd.3gpp.pic-bw-small":"psb","vnd.3gpp.pic-bw-var":"pvb","vnd.3gpp2.tcap":"tcap","vnd.3m.post-it-notes":"pwn","vnd.accpac.simply.aso":"aso","vnd.accpac.simply.imp":"imp","vnd.acucobol":"acu","vnd.acucorp":["atc","acutc"],"vnd.adobe.air-application-installer-package+zip":"air","vnd.adobe.formscentral.fcdt":"fcdt","vnd.adobe.fxp":["fxp","fxpl"],"vnd.adobe.xdp+xml":"xdp","vnd.adobe.xfdf":"xfdf","vnd.ahead.space":"ahead","vnd.airzip.filesecure.azf":"azf","vnd.airzip.filesecure.azs":"azs","vnd.amazon.ebook":"azw","vnd.americandynamics.acc":"acc","vnd.amiga.ami":"ami","vnd.anser-web-certificate-issue-initiation":"cii","vnd.anser-web-funds-transfer-initiation":"fti","vnd.antix.game-component":"atx","vnd.apple.installer+xml":"mpkg","vnd.apple.mpegurl":"m3u8","vnd.aristanetworks.swi":"swi","vnd.astraea-software.iota":"iota","vnd.audiograph":"aep","vnd.blueice.multipass":"mpm","vnd.bmi":"bmi","vnd.businessobjects":"rep","vnd.chemdraw+xml":"cdxml","vnd.chipnuts.karaoke-mmd":"mmd","vnd.claymore":"cla","vnd.cloanto.rp9":"rp9","vnd.clonk.c4group":["c4g","c4d","c4f","c4p","c4u"],"vnd.cluetrust.cartomobile-config":"c11amc","vnd.cluetrust.cartomobile-config-pkg":"c11amz","vnd.commonspace":"csp","vnd.contact.cmsg":"cdbcmsg","vnd.cosmocaller":"cmc","vnd.crick.clicker":"clkx","vnd.crick.clicker.keyboard":"clkk","vnd.crick.clicker.palette":"clkp","vnd.crick.clicker.template":"clkt","vnd.crick.clicker.wordbank":"clkw","vnd.criticaltools.wbs+xml":"wbs","vnd.ctc-posml":"pml","vnd.cups-ppd":"ppd","vnd.curl.car":"car","vnd.curl.pcurl":"pcurl","vnd.dart":"dart","vnd.data-vision.rdz":"rdz","vnd.dece.data":["uvf","uvvf","uvd","uvvd"],"vnd.dece.ttml+xml":["uvt","uvvt"],"vnd.dece.unspecified":["uvx","uvvx"],"vnd.dece.zip":["uvz","uvvz"],"vnd.denovo.fcselayout-link":"fe_launch","vnd.dna":"dna","vnd.dolby.mlp":"mlp","vnd.dpgraph":"dpg","vnd.dreamfactory":"dfac","vnd.ds-keypoint":"kpxx","vnd.dvb.ait":"ait","vnd.dvb.service":"svc","vnd.dynageo":"geo","vnd.ecowin.chart":"mag","vnd.enliven":"nml","vnd.epson.esf":"esf","vnd.epson.msf":"msf","vnd.epson.quickanime":"qam","vnd.epson.salt":"slt","vnd.epson.ssf":"ssf","vnd.eszigno3+xml":["es3","et3"],"vnd.ezpix-album":"ez2","vnd.ezpix-package":"ez3","vnd.fdf":"fdf","vnd.fdsn.mseed":"mseed","vnd.fdsn.seed":["seed","dataless"],"vnd.flographit":"gph","vnd.fluxtime.clip":"ftc","vnd.framemaker":["fm","frame","maker","book"],"vnd.frogans.fnc":"fnc","vnd.frogans.ltf":"ltf","vnd.fsc.weblaunch":"fsc","vnd.fujitsu.oasys":"oas","vnd.fujitsu.oasys2":"oa2","vnd.fujitsu.oasys3":"oa3","vnd.fujitsu.oasysgp":"fg5","vnd.fujitsu.oasysprs":"bh2","vnd.fujixerox.ddd":"ddd","vnd.fujixerox.docuworks":"xdw","vnd.fujixerox.docuworks.binder":"xbd","vnd.fuzzysheet":"fzs","vnd.genomatix.tuxedo":"txd","vnd.geogebra.file":"ggb","vnd.geogebra.tool":"ggt","vnd.geometry-explorer":["gex","gre"],"vnd.geonext":"gxt","vnd.geoplan":"g2w","vnd.geospace":"g3w","vnd.gmx":"gmx","vnd.grafeq":["gqf","gqs"],"vnd.groove-account":"gac","vnd.groove-help":"ghf","vnd.groove-identity-message":"gim","vnd.groove-injector":"grv","vnd.groove-tool-message":"gtm","vnd.groove-tool-template":"tpl","vnd.groove-vcard":"vcg","vnd.hal+xml":"hal","vnd.handheld-entertainment+xml":"zmm","vnd.hbci":"hbci","vnd.hhe.lesson-player":"les","vnd.hp-hpgl":"hpgl","vnd.hp-hpid":"hpid","vnd.hp-hps":"hps","vnd.hp-jlyt":"jlt","vnd.hp-pcl":"pcl","vnd.hp-pclxl":"pclxl","vnd.hydrostatix.sof-data":"sfd-hdstx","vnd.ibm.minipay":"mpy","vnd.ibm.modcap":["afp","listafp","list3820"],"vnd.ibm.rights-management":"irm","vnd.ibm.secure-container":"sc","vnd.iccprofile":["icc","icm"],"vnd.igloader":"igl","vnd.immervision-ivp":"ivp","vnd.immervision-ivu":"ivu","vnd.insors.igm":"igm","vnd.intercon.formnet":["xpw","xpx"],"vnd.intergeo":"i2g","vnd.intu.qbo":"qbo","vnd.intu.qfx":"qfx","vnd.ipunplugged.rcprofile":"rcprofile","vnd.irepository.package+xml":"irp","vnd.is-xpr":"xpr","vnd.isac.fcs":"fcs","vnd.jam":"jam","vnd.jcp.javame.midlet-rms":"rms","vnd.jisp":"jisp","vnd.joost.joda-archive":"joda","vnd.kahootz":["ktz","ktr"],"vnd.kde.karbon":"karbon","vnd.kde.kchart":"chrt","vnd.kde.kformula":"kfo","vnd.kde.kivio":"flw","vnd.kde.kontour":"kon","vnd.kde.kpresenter":["kpr","kpt"],"vnd.kde.kspread":"ksp","vnd.kde.kword":["kwd","kwt"],"vnd.kenameaapp":"htke","vnd.kidspiration":"kia","vnd.kinar":["kne","knp"],"vnd.koan":["skp","skd","skt","skm"],"vnd.kodak-descriptor":"sse","vnd.las.las+xml":"lasxml","vnd.llamagraphics.life-balance.desktop":"lbd","vnd.llamagraphics.life-balance.exchange+xml":"lbe","vnd.lotus-1-2-3":"123","vnd.lotus-approach":"apr","vnd.lotus-freelance":"pre","vnd.lotus-notes":"nsf","vnd.lotus-organizer":"org","vnd.lotus-screencam":"scm","vnd.lotus-wordpro":"lwp","vnd.macports.portpkg":"portpkg","vnd.mcd":"mcd","vnd.medcalcdata":"mc1","vnd.mediastation.cdkey":"cdkey","vnd.mfer":"mwf","vnd.mfmp":"mfm","vnd.micrografx.flo":"flo","vnd.micrografx.igx":"igx","vnd.mif":"mif","vnd.mobius.daf":"daf","vnd.mobius.dis":"dis","vnd.mobius.mbk":"mbk","vnd.mobius.mqy":"mqy","vnd.mobius.msl":"msl","vnd.mobius.plc":"plc","vnd.mobius.txf":"txf","vnd.mophun.application":"mpn","vnd.mophun.certificate":"mpc","vnd.ms-artgalry":"cil","vnd.ms-cab-compressed":"cab","vnd.ms-excel.addin.macroenabled.12":"xlam","vnd.ms-excel.sheet.binary.macroenabled.12":"xlsb","vnd.ms-excel.sheet.macroenabled.12":"xlsm","vnd.ms-excel.template.macroenabled.12":"xltm","vnd.ms-fontobject":"eot","vnd.ms-htmlhelp":"chm","vnd.ms-ims":"ims","vnd.ms-lrm":"lrm","vnd.ms-officetheme":"thmx","vnd.ms-powerpoint.addin.macroenabled.12":"ppam","vnd.ms-powerpoint.presentation.macroenabled.12":"pptm","vnd.ms-powerpoint.slide.macroenabled.12":"sldm","vnd.ms-powerpoint.slideshow.macroenabled.12":"ppsm","vnd.ms-powerpoint.template.macroenabled.12":"potm","vnd.ms-project":["mpp","mpt"],"vnd.ms-word.document.macroenabled.12":"docm","vnd.ms-word.template.macroenabled.12":"dotm","vnd.ms-works":["wps","wks","wcm","wdb"],"vnd.ms-wpl":"wpl","vnd.ms-xpsdocument":"xps","vnd.mseq":"mseq","vnd.musician":"mus","vnd.muvee.style":"msty","vnd.mynfc":"taglet","vnd.neurolanguage.nlu":"nlu","vnd.nitf":["ntf","nitf"],"vnd.noblenet-directory":"nnd","vnd.noblenet-sealer":"nns","vnd.noblenet-web":"nnw","vnd.nokia.n-gage.data":"ngdat","vnd.nokia.n-gage.symbian.install":"n-gage","vnd.nokia.radio-preset":"rpst","vnd.nokia.radio-presets":"rpss","vnd.novadigm.edm":"edm","vnd.novadigm.edx":"edx","vnd.novadigm.ext":"ext","vnd.oasis.opendocument.chart-template":"otc","vnd.oasis.opendocument.formula-template":"odft","vnd.oasis.opendocument.image-template":"oti","vnd.olpc-sugar":"xo","vnd.oma.dd2+xml":"dd2","vnd.openofficeorg.extension":"oxt","vnd.openxmlformats-officedocument.presentationml.slide":"sldx","vnd.osgeo.mapguide.package":"mgp","vnd.osgi.dp":"dp","vnd.osgi.subsystem":"esa","vnd.palm":["pdb","pqa","oprc"],"vnd.pawaafile":"paw","vnd.pg.format":"str","vnd.pg.osasli":"ei6","vnd.picsel":"efif","vnd.pmi.widget":"wg","vnd.pocketlearn":"plf","vnd.powerbuilder6":"pbd","vnd.previewsystems.box":"box","vnd.proteus.magazine":"mgz","vnd.publishare-delta-tree":"qps","vnd.pvi.ptid1":"ptid","vnd.quark.quarkxpress":["qxd","qxt","qwd","qwt","qxl","qxb"],"vnd.realvnc.bed":"bed","vnd.recordare.musicxml":"mxl","vnd.recordare.musicxml+xml":"musicxml","vnd.rig.cryptonote":"cryptonote","vnd.rn-realmedia":"rm","vnd.rn-realmedia-vbr":"rmvb","vnd.route66.link66+xml":"link66","vnd.sailingtracker.track":"st","vnd.seemail":"see","vnd.sema":"sema","vnd.semd":"semd","vnd.semf":"semf","vnd.shana.informed.formdata":"ifm","vnd.shana.informed.formtemplate":"itp","vnd.shana.informed.interchange":"iif","vnd.shana.informed.package":"ipk","vnd.simtech-mindmapper":["twd","twds"],"vnd.smart.teacher":"teacher","vnd.solent.sdkm+xml":["sdkm","sdkd"],"vnd.spotfire.dxp":"dxp","vnd.spotfire.sfs":"sfs","vnd.stepmania.package":"smzip","vnd.stepmania.stepchart":"sm","vnd.sus-calendar":["sus","susp"],"vnd.svd":"svd","vnd.syncml+xml":"xsm","vnd.syncml.dm+wbxml":"bdm","vnd.syncml.dm+xml":"xdm","vnd.tao.intent-module-archive":"tao","vnd.tcpdump.pcap":["pcap","cap","dmp"],"vnd.tmobile-livetv":"tmo","vnd.trid.tpt":"tpt","vnd.triscape.mxs":"mxs","vnd.trueapp":"tra","vnd.ufdl":["ufd","ufdl"],"vnd.uiq.theme":"utz","vnd.umajin":"umj","vnd.unity":"unityweb","vnd.uoml+xml":"uoml","vnd.vcx":"vcx","vnd.visionary":"vis","vnd.vsf":"vsf","vnd.webturbo":"wtb","vnd.wolfram.player":"nbp","vnd.wqd":"wqd","vnd.wt.stf":"stf","vnd.xara":"xar","vnd.xfdl":"xfdl","vnd.yamaha.hv-dic":"hvd","vnd.yamaha.hv-script":"hvs","vnd.yamaha.hv-voice":"hvp","vnd.yamaha.openscoreformat":"osf","vnd.yamaha.openscoreformat.osfpvg+xml":"osfpvg","vnd.yamaha.smaf-audio":"saf","vnd.yamaha.smaf-phrase":"spf","vnd.yellowriver-custom-menu":"cmp","vnd.zul":["zir","zirz"],"vnd.zzazz.deck+xml":"zaz","voicexml+xml":"vxml",widget:"wgt",winhlp:"hlp","wsdl+xml":"wsdl","wspolicy+xml":"wspolicy","x-ace-compressed":"ace","x-authorware-bin":["aab","x32","u32","vox"],"x-authorware-map":"aam","x-authorware-seg":"aas","x-blorb":["blb","blorb"],"x-bzip":"bz","x-bzip2":["bz2","boz"],"x-cfs-compressed":"cfs","x-chat":"chat","x-conference":"nsc","x-dgc-compressed":"dgc","x-dtbncx+xml":"ncx","x-dtbook+xml":"dtb","x-dtbresource+xml":"res","x-eva":"eva","x-font-bdf":"bdf","x-font-ghostscript":"gsf","x-font-linux-psf":"psf","x-font-otf":"otf","x-font-pcf":"pcf","x-font-snf":"snf","x-font-ttf":["ttf","ttc"],"x-font-type1":["pfa","pfb","pfm","afm"],"x-font-woff":"woff","x-freearc":"arc","x-gca-compressed":"gca","x-glulx":"ulx","x-gramps-xml":"gramps","x-install-instructions":"install","x-lzh-compressed":["lzh","lha"],"x-mie":"mie","x-mobipocket-ebook":["prc","mobi"],"x-ms-application":"application","x-ms-shortcut":"lnk","x-ms-xbap":"xbap","x-msbinder":"obd","x-mscardfile":"crd","x-msclip":"clp","x-msdownload":["exe","dll","com","bat","msi"],"x-msmediaview":["mvb","m13","m14"],"x-msmetafile":["wmf","wmz","emf","emz"],"x-msmoney":"mny","x-mspublisher":"pub","x-msschedule":"scd","x-msterminal":"trm","x-mswrite":"wri","x-nzb":"nzb","x-pkcs12":["p12","pfx"],"x-pkcs7-certificates":["p7b","spc"],"x-research-info-systems":"ris","x-silverlight-app":"xap","x-sql":"sql","x-stuffitx":"sitx","x-subrip":"srt","x-t3vm-image":"t3","x-tads":"gam","x-tex":"tex","x-tex-tfm":"tfm","x-tgif":"obj","x-xliff+xml":"xlf","x-xz":"xz","x-zmachine":["z1","z2","z3","z4","z5","z6","z7","z8"],"xaml+xml":"xaml","xcap-diff+xml":"xdf","xenc+xml":"xenc","xml-dtd":"dtd","xop+xml":"xop","xproc+xml":"xpl","xslt+xml":"xslt","xv+xml":["mxml","xhvml","xvml","xvm"],yang:"yang","yin+xml":"yin",envoy:"evy",fractals:"fif","internet-property-stream":"acx",olescript:"axs","vnd.ms-outlook":"msg","vnd.ms-pkicertstore":"sst","x-compress":"z","x-compressed":"tgz","x-gzip":"gz","x-perfmon":["pma","pmc","pml","pmr","pmw"],"x-pkcs7-mime":["p7c","p7m"],"ynd.ms-pkipko":"pko"},audio:{amr:"amr","amr-wb":"awb",annodex:"axa",basic:["au","snd"],flac:"flac",midi:["mid","midi","kar","rmi"],mpeg:["mpga","mpega","mp2","mp3","m4a","mp2a","m2a","m3a"],mpegurl:"m3u",ogg:["oga","ogg","spx"],"prs.sid":"sid","x-aiff":["aif","aiff","aifc"],"x-gsm":"gsm","x-ms-wma":"wma","x-ms-wax":"wax","x-pn-realaudio":"ram","x-realaudio":"ra","x-sd2":"sd2","x-wav":"wav",adpcm:"adp",mp4:"mp4a",s3m:"s3m",silk:"sil","vnd.dece.audio":["uva","uvva"],"vnd.digital-winds":"eol","vnd.dra":"dra","vnd.dts":"dts","vnd.dts.hd":"dtshd","vnd.lucent.voice":"lvp","vnd.ms-playready.media.pya":"pya","vnd.nuera.ecelp4800":"ecelp4800","vnd.nuera.ecelp7470":"ecelp7470","vnd.nuera.ecelp9600":"ecelp9600","vnd.rip":"rip",webm:"weba","x-aac":"aac","x-caf":"caf","x-matroska":"mka","x-pn-realaudio-plugin":"rmp",xm:"xm",mid:["mid","rmi"]},chemical:{"x-alchemy":"alc","x-cache":["cac","cache"],"x-cache-csf":"csf","x-cactvs-binary":["cbin","cascii","ctab"],"x-cdx":"cdx","x-chem3d":"c3d","x-cif":"cif","x-cmdf":"cmdf","x-cml":"cml","x-compass":"cpa","x-crossfire":"bsd","x-csml":["csml","csm"],"x-ctx":"ctx","x-cxf":["cxf","cef"],"x-embl-dl-nucleotide":["emb","embl"],"x-gamess-input":["inp","gam","gamin"],"x-gaussian-checkpoint":["fch","fchk"],"x-gaussian-cube":"cub","x-gaussian-input":["gau","gjc","gjf"],"x-gaussian-log":"gal","x-gcg8-sequence":"gcg","x-genbank":"gen","x-hin":"hin","x-isostar":["istr","ist"],"x-jcamp-dx":["jdx","dx"],"x-kinemage":"kin","x-macmolecule":"mcm","x-macromodel-input":["mmd","mmod"],"x-mdl-molfile":"mol","x-mdl-rdfile":"rd","x-mdl-rxnfile":"rxn","x-mdl-sdfile":["sd","sdf"],"x-mdl-tgf":"tgf","x-mmcif":"mcif","x-mol2":"mol2","x-molconn-Z":"b","x-mopac-graph":"gpt","x-mopac-input":["mop","mopcrt","mpc","zmt"],"x-mopac-out":"moo","x-ncbi-asn1":"asn","x-ncbi-asn1-ascii":["prt","ent"],"x-ncbi-asn1-binary":["val","aso"],"x-pdb":["pdb","ent"],"x-rosdal":"ros","x-swissprot":"sw","x-vamas-iso14976":"vms","x-vmd":"vmd","x-xtel":"xtel","x-xyz":"xyz"},image:{gif:"gif",ief:"ief",jpeg:["jpeg","jpg","jpe"],pcx:"pcx",png:"png","svg+xml":["svg","svgz"],tiff:["tiff","tif"],"vnd.djvu":["djvu","djv"],"vnd.wap.wbmp":"wbmp","x-canon-cr2":"cr2","x-canon-crw":"crw","x-cmu-raster":"ras","x-coreldraw":"cdr","x-coreldrawpattern":"pat","x-coreldrawtemplate":"cdt","x-corelphotopaint":"cpt","x-epson-erf":"erf","x-icon":"ico","x-jg":"art","x-jng":"jng","x-nikon-nef":"nef","x-olympus-orf":"orf","x-photoshop":"psd","x-portable-anymap":"pnm","x-portable-bitmap":"pbm","x-portable-graymap":"pgm","x-portable-pixmap":"ppm","x-rgb":"rgb","x-xbitmap":"xbm","x-xpixmap":"xpm","x-xwindowdump":"xwd",bmp:"bmp",cgm:"cgm",g3fax:"g3",ktx:"ktx","prs.btif":"btif",sgi:"sgi","vnd.dece.graphic":["uvi","uvvi","uvg","uvvg"],"vnd.dwg":"dwg","vnd.dxf":"dxf","vnd.fastbidsheet":"fbs","vnd.fpx":"fpx","vnd.fst":"fst","vnd.fujixerox.edmics-mmr":"mmr","vnd.fujixerox.edmics-rlc":"rlc","vnd.ms-modi":"mdi","vnd.ms-photo":"wdp","vnd.net-fpx":"npx","vnd.xiff":"xif",webp:"webp","x-3ds":"3ds","x-cmx":"cmx","x-freehand":["fh","fhc","fh4","fh5","fh7"],"x-pict":["pic","pct"],"x-tga":"tga","cis-cod":"cod",pipeg:"jfif"},message:{rfc822:["eml","mime","mht","mhtml","nws"]},model:{iges:["igs","iges"],mesh:["msh","mesh","silo"],vrml:["wrl","vrml"],"x3d+vrml":["x3dv","x3dvz"],"x3d+xml":["x3d","x3dz"],"x3d+binary":["x3db","x3dbz"],"vnd.collada+xml":"dae","vnd.dwf":"dwf","vnd.gdl":"gdl","vnd.gtw":"gtw","vnd.mts":"mts","vnd.vtu":"vtu"},text:{"cache-manifest":["manifest","appcache"],calendar:["ics","icz","ifb"],css:"css",csv:"csv",h323:"323",html:["html","htm","shtml","stm"],iuls:"uls",mathml:"mml",plain:["txt","text","brf","conf","def","list","log","in","bas"],richtext:"rtx",scriptlet:["sct","wsc"],texmacs:["tm","ts"],"tab-separated-values":"tsv","vnd.sun.j2me.app-descriptor":"jad","vnd.wap.wml":"wml","vnd.wap.wmlscript":"wmls","x-bibtex":"bib","x-boo":"boo","x-c++hdr":["h++","hpp","hxx","hh"],"x-c++src":["c++","cpp","cxx","cc"],"x-component":"htc","x-dsrc":"d","x-diff":["diff","patch"],"x-haskell":"hs","x-java":"java","x-literate-haskell":"lhs","x-moc":"moc","x-pascal":["p","pas"],"x-pcs-gcd":"gcd","x-perl":["pl","pm"],"x-python":"py","x-scala":"scala","x-setext":"etx","x-tcl":["tcl","tk"],"x-tex":["tex","ltx","sty","cls"],"x-vcalendar":"vcs","x-vcard":"vcf",n3:"n3","prs.lines.tag":"dsc",sgml:["sgml","sgm"],troff:["t","tr","roff","man","me","ms"],turtle:"ttl","uri-list":["uri","uris","urls"],vcard:"vcard","vnd.curl":"curl","vnd.curl.dcurl":"dcurl","vnd.curl.scurl":"scurl","vnd.curl.mcurl":"mcurl","vnd.dvb.subtitle":"sub","vnd.fly":"fly","vnd.fmi.flexstor":"flx","vnd.graphviz":"gv","vnd.in3d.3dml":"3dml","vnd.in3d.spot":"spot","x-asm":["s","asm"],"x-c":["c","cc","cxx","cpp","h","hh","dic"],"x-fortran":["f","for","f77","f90"],"x-opml":"opml","x-nfo":"nfo","x-sfv":"sfv","x-uuencode":"uu",webviewhtml:"htt"},video:{avif:".avif","3gpp":"3gp",annodex:"axv",dl:"dl",dv:["dif","dv"],fli:"fli",gl:"gl",mpeg:["mpeg","mpg","mpe","m1v","m2v","mp2","mpa","mpv2"],mp4:["mp4","mp4v","mpg4"],quicktime:["qt","mov"],ogg:"ogv","vnd.mpegurl":["mxu","m4u"],"x-flv":"flv","x-la-asf":["lsf","lsx"],"x-mng":"mng","x-ms-asf":["asf","asx","asr"],"x-ms-wm":"wm","x-ms-wmv":"wmv","x-ms-wmx":"wmx","x-ms-wvx":"wvx","x-msvideo":"avi","x-sgi-movie":"movie","x-matroska":["mpv","mkv","mk3d","mks"],"3gpp2":"3g2",h261:"h261",h263:"h263",h264:"h264",jpeg:"jpgv",jpm:["jpm","jpgm"],mj2:["mj2","mjp2"],"vnd.dece.hd":["uvh","uvvh"],"vnd.dece.mobile":["uvm","uvvm"],"vnd.dece.pd":["uvp","uvvp"],"vnd.dece.sd":["uvs","uvvs"],"vnd.dece.video":["uvv","uvvv"],"vnd.dvb.file":"dvb","vnd.fvt":"fvt","vnd.ms-playready.media.pyv":"pyv","vnd.uvvu.mp4":["uvu","uvvu"],"vnd.vivo":"viv",webm:"webm","x-f4v":"f4v","x-m4v":"m4v","x-ms-vob":"vob","x-smv":"smv"},"x-conference":{"x-cooltalk":"ice"},"x-world":{"x-vrml":["vrm","vrml","wrl","flr","wrz","xaf","xof"]}},ae=(()=>{const t={};for(let e in re)if(re.hasOwnProperty(e))for(let n in re[e])if(re[e].hasOwnProperty(n)){const s=re[e][n];if("string"==typeof s)t[s]=e+"/"+n;else for(let i=0;i({ZipDeflate:Vt(t.Deflate,e.deflate),ZipInflate:Vt(t.Inflate,e.inflate)}),Object.defineProperty(t,"__esModule",{value:!0})})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).zip={})}(this,(function(e){"use strict";const t="HTTP error ",n="HTTP Range not supported",s="text/plain";class i{constructor(){this.size=0}init(){this.initialized=!0}}class r extends i{}class a extends i{writeUint8Array(e){this.size+=e.length}}class o extends r{constructor(e){super(),this.blobReader=new l(new Blob([e],{type:s}))}init(){super.init(),this.blobReader.init(),this.size=this.blobReader.size}readUint8Array(e,t){return this.blobReader.readUint8Array(e,t)}}class d extends a{constructor(e){super(),this.encoding=e,this.blob=new Blob([],{type:s})}writeUint8Array(e){super.writeUint8Array(e),this.blob=new Blob([this.blob,e.buffer],{type:s})}getData(){const e=new FileReader;return new Promise(((t,n)=>{e.onload=e=>t(e.target.result),e.onerror=n,e.readAsText(this.blob,this.encoding)}))}}class c extends r{constructor(e){super(),this.dataURI=e;let t=e.length;for(;"="==e.charAt(t-1);)t--;this.dataStart=e.indexOf(",")+1,this.size=Math.floor(.75*(t-this.dataStart))}readUint8Array(e,t){const n=new Uint8Array(t),s=4*Math.floor(e/3),i=atob(this.dataURI.substring(s+this.dataStart,4*Math.ceil((e+t)/3)+this.dataStart)),r=e-3*Math.floor(s/4);for(let e=r;e2?this.data+=btoa(n):this.pending=n}getData(){return this.data+btoa(this.pending)}}class l extends r{constructor(e){super(),this.blob=e,this.size=e.size}readUint8Array(e,t){const n=new FileReader;return new Promise(((s,i)=>{n.onload=e=>s(new Uint8Array(e.target.result)),n.onerror=i,n.readAsArrayBuffer(this.blob.slice(e,e+t))}))}}class m extends a{constructor(e){super(),this.offset=0,this.contentType=e,this.blob=new Blob([],{type:e})}writeUint8Array(e){super.writeUint8Array(e),this.blob=new Blob([this.blob,e.buffer],{type:this.contentType}),this.offset=this.blob.size}getData(){return this.blob}}class h extends r{constructor(e){super(),this.url=e}async init(){if(super.init(),function(e){if("undefined"!=typeof document){const t=document.createElement("a");return t.href=e,"http:"==t.protocol||"https:"==t.protocol}return/^https?:\/\//i.test(e)}(this.url))return new Promise(((e,n)=>{const s=new XMLHttpRequest;s.addEventListener("load",(()=>{s.status<400?(this.size=Number(s.getResponseHeader("Content-Length")),this.size?e():x().then((()=>e())).catch(n)):n(t+(s.statusText||s.status)+".")}),!1),s.addEventListener("error",n,!1),s.open("HEAD",this.url),s.send()}));await x()}async readUint8Array(e,t){return this.data||await x(this,this.url),new Uint8Array(this.data.subarray(e,e+t))}}class f extends r{constructor(e){super(),this.url=e}init(){return super.init(),new Promise(((e,s)=>{const i=new XMLHttpRequest;i.addEventListener("load",(()=>{i.status<400?(this.size=Number(i.getResponseHeader("Content-Length")),"bytes"==i.getResponseHeader("Accept-Ranges")?e():s(new Error(n))):s(t+(i.statusText||i.status)+".")}),!1),i.addEventListener("error",s,!1),i.open("HEAD",this.url),i.send()}))}readUint8Array(e,n){return new Promise(((s,i)=>{const r=new XMLHttpRequest;r.open("GET",this.url),r.responseType="arraybuffer",r.setRequestHeader("Range","bytes="+e+"-"+(e+n-1)),r.addEventListener("load",(()=>{r.status<400?s(new Uint8Array(r.response)):i(t+(r.statusText||r.status)+".")}),!1),r.addEventListener("error",i,!1),r.send()}))}}class u extends a{constructor(){super(),this.array=new Uint8Array(0)}writeUint8Array(e){super.writeUint8Array(e);const t=this.array;this.array=new Uint8Array(t.length+e.length),this.array.set(t),this.array.set(e,t.length)}getData(){return this.array}}function x(e,n){return new Promise(((s,i)=>{const r=new XMLHttpRequest;r.addEventListener("load",(()=>{r.status<400?(e.size||(e.size=Number(r.getResponseHeader("Content-Length"))||Number(r.response.byteLength)),e.data=new Uint8Array(r.response),s()):i(t+(r.statusText||r.status)+".")}),!1),r.addEventListener("error",i,!1),r.open("GET",n),r.responseType="arraybuffer",r.send()}))}const g=4294967295,v=65535,w=1347093252,y=1347094280,b=1347092738,k=1347093766,U=1347094022,z=1347094023,E=39169,A=2048,R=45,D=51;class j{constructor(){this.crc=-1,this.table=(()=>{const e=[];for(let t=0;t<256;t++){let n=t;for(let e=0;e<8;e++)1&n?n=n>>>1^3988292384:n>>>=1;e[t]=n}return e})()}append(e){const t=this.table;let n=0|this.crc;for(let s=0,i=0|e.length;s>>8^t[255&(n^e[s])];this.crc=n}get(){return~this.crc}}const F="Invalid pasword",I=16,S="raw",B={name:"PBKDF2"},T={name:"HMAC"},L="SHA-1",_={name:"AES-CTR"},q=Object.assign({hash:T},B),C=Object.assign({iterations:1e3,hash:{name:L}},B),N=Object.assign({hash:L},T),O=Object.assign({length:I},_),M=["deriveBits"],W=["sign"],P=528,V=10,Z=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],H=crypto.subtle;class K{constructor(e,t){this.password=e,this.signed=t,this.input=t&&new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(e){const t=async(i=0)=>{if(i+I<=s.length-V){const e=s.subarray(i,i+I),r=await H.decrypt(Object.assign({counter:this.counter},O),this.keys.decrypt,e);return Y(this.counter),n.set(new Uint8Array(r),i),t(i+I)}return this.pendingInput=s.subarray(i),this.signed&&(this.input=G(this.input,e)),n};if(this.password){const t=e.subarray(0,18);await async function(e,t,n){e.counter=new Uint8Array(Z);const s=t.subarray(0,16),i=t.subarray(16),r=(new TextEncoder).encode(n),a=await H.importKey(S,r,q,!1,M),o=await H.deriveBits(Object.assign({salt:s},C),a,528),d=new Uint8Array(o),c=d.subarray(64);if(e.keys={decrypt:await H.importKey(S,d.subarray(0,32),_,!0,["decrypt"]),authentication:await H.importKey(S,d.subarray(32,64),N,!1,W),passwordVerification:c},c[0]!=i[0]||c[1]!=i[1])throw new Error(F)}(this,t,this.password),this.password=null,e=e.subarray(18)}let n=new Uint8Array(e.length-V-(e.length-V)%I),s=e;return this.pendingInput.length&&(s=G(this.pendingInput,e),n=J(n,s.length-V-(s.length-V)%I)),t()}async flush(){const e=this.pendingInput,t=this.keys,n=e.subarray(0,e.length-V),s=e.subarray(e.length-V);let i=new Uint8Array(0);if(n.length){const e=await H.decrypt(Object.assign({counter:this.counter},O),t.decrypt,n);i=new Uint8Array(e)}let r=!0;if(this.signed){const e=await H.sign(T,t.authentication,this.input.subarray(0,this.input.length-V)),n=new Uint8Array(e);this.input=null;for(let e=0;e{if(i+I<=e.length){const r=e.subarray(i,i+I),a=await H.encrypt(Object.assign({counter:this.counter},O),this.keys.encrypt,r);return Y(this.counter),s.set(new Uint8Array(a),i+n.length),t(i+I)}return this.pendingInput=e.subarray(i),this.output=G(this.output,s),s};let n=new Uint8Array(0);this.password&&(n=await async function(e,t){e.counter=new Uint8Array(Z);const n=crypto.getRandomValues(new Uint8Array(16)),s=(new TextEncoder).encode(t),i=await H.importKey(S,s,q,!1,M),r=await H.deriveBits(Object.assign({salt:n},C),i,P),a=new Uint8Array(r);return e.keys={encrypt:await H.importKey(S,a.subarray(0,32),_,!0,["encrypt"]),authentication:await H.importKey(S,a.subarray(32,64),N,!1,W),passwordVerification:a.subarray(64)},G(n,e.keys.passwordVerification)}(this,this.password),this.password=null);let s=new Uint8Array(n.length+e.length-e.length%I);return s.set(n,0),this.pendingInput.length&&(e=G(this.pendingInput,e),s=J(s,e.length-e.length%I)),t()}async flush(){let e=new Uint8Array(0);if(this.pendingInput.length){const t=await H.encrypt(Object.assign({counter:this.counter},O),this.keys.encrypt,this.pendingInput);e=new Uint8Array(t),this.output=G(this.output,e)}const t=await H.sign(T,this.keys.authentication,this.output.subarray(18));this.output=null;const n=new Uint8Array(t).subarray(0,V);return{data:G(e,n),signature:n}}}function Y(e){for(let t=0;t<16;t++){if(255!=e[t]){e[t]++;break}e[t]=0}}function G(e,t){let n=e;return e.length+t.length&&(n=new Uint8Array(e.length+t.length),n.set(e,0),n.set(t,e.length)),n}function J(e,t){if(t&&t>e.length){const n=e;(e=new Uint8Array(t)).set(n,0)}return e}const Q="deflate",$="inflate",ee="Invalid signature";class te{constructor(e){this.signature=e.inputSignature,this.encrypted=Boolean(e.inputPassword),this.signed=e.inputSigned,this.compressed=e.inputCompressed,this.inflate=this.compressed&&new ZipInflate,this.crc32=this.signed&&this.signed&&new j,this.decrypt=this.encrypted&&new K(e.inputPassword)}async append(e){return this.encrypted&&(e=await this.decrypt.append(e)),this.compressed&&e.length&&(e=await this.inflate.append(e)),!this.encrypted&&this.signed&&this.crc32.append(e),e}async flush(){let e,t=new Uint8Array(0);if(this.encrypted){const e=await this.decrypt.flush();if(!e.valid)throw new Error(ee);t=e.data}else if(this.signed){const t=new DataView(new Uint8Array(4).buffer);if(e=this.crc32.get(),t.setUint32(0,e),this.signature!=t.getUint32(0,!1))throw new Error(ee)}return this.compressed&&(t=await this.inflate.append(t)||new Uint8Array(0),await this.inflate.flush()),{data:t,signature:e}}}class ne{constructor(e){this.encrypted=e.outputEncrypted,this.signed=e.outputSigned,this.compressed=e.outputCompressed,this.deflate=this.compressed&&new ZipDeflate({level:e.level||5}),this.crc32=this.signed&&new j,this.encrypt=this.encrypted&&new X(e.outputPassword)}async append(e){let t=e;return this.compressed&&e.length&&(t=await this.deflate.append(e)),this.encrypted?t=await this.encrypt.append(t):this.signed&&this.crc32.append(e),t}async flush(){let e,t=new Uint8Array(0);if(this.compressed&&(t=await this.deflate.flush()||new Uint8Array(0)),this.encrypted){t=await this.encrypt.append(t);const n=await this.encrypt.flush();e=n.signature;const s=new Uint8Array(t.length+n.data.length);s.set(t,0),s.set(n.data,t.length),t=s}else this.signed&&(e=this.crc32.get());return{data:t,signature:e}}}const se="init",ie="append",re="flush",ae="z-worker.js",oe={deflate:[ae,"deflate.js"],inflate:[ae,"inflate.js"]},de={pool:[],pendingRequests:[]};function ce(e,t){const n=de.pool,s=!(t.inputCompressed||t.inputSigned||t.inputEncrypted||t.outputCompressed||t.outputSigned||t.outputEncrypted);let i;if(t.useWebWorkers||void 0===t.useWebWorkers&&e.useWebWorkers&&!s){const n=t.codecType;if(null!=e.workerScripts&&null!=e.workerScriptsPath)throw new Error("Either workerScripts or workerScriptsPath may be set, not both");if(e.workerScripts){if(i=e.workerScripts[n],!Array.isArray(i))throw new Error("workerScripts."+n+" must be an array");r=i,i="undefined"!=typeof document?r.map((e=>new URL(e,document.baseURI).href)):r}else i=oe[n].slice(0),i[0]=(e.workerScriptsPath||"")+i[0]}var r;if(n.length!e.busy));return e?pe(e):new Promise((e=>de.pendingRequests.push({resolve:e,options:t,scripts:i})))}}function pe(e,t,n){return e.busy=!0,e.options=t,e.scripts=n,n?me(e):le(e)}function le(e){const t=(n=e.options).codecType.startsWith(Q)?new ne(n):n.codecType.startsWith($)?new te(n):void 0;var n;const s=t.append.bind(t),i=t.flush.bind(t);return t.append=async t=>{try{return await s(t)}catch(t){throw he(e),t}},t.flush=async()=>{try{return await i()}finally{he(e)}},t}function me(e){let t;return e.interface||(e.worker=new Worker(e.scripts[0]),e.worker.addEventListener("message",(function(n){const s=n.data;if(t){const n=s.error;if(n){const s=new Error(n.message);s.stack=n.stack,t.reject(s),t=null,he(e)}else s.type!=se&&s.type!=re&&s.type!=ie||(s.type==re?(t.resolve({data:new Uint8Array(s.data),signature:s.signature}),t=null,he(e)):t.resolve(s.data&&new Uint8Array(s.data)))}}),!1),e.interface={append:e=>n({type:ie,data:e}),flush:()=>n({type:re})}),e.interface;async function n(n){if(!t){const t=e.scripts.slice(1);await s(Object.assign({type:se,options:e.options,scripts:t}))}return s(n)}function s(n){const s=e.worker,i=new Promise(((e,n)=>t={resolve:e,reject:n}));try{if(n.data)try{s.postMessage(n,[n.data.buffer])}catch(e){s.postMessage(n)}else s.postMessage(n)}catch(n){t.reject(n),t=null,he(e)}return i}}function he(e){if(e.busy=!1,de.pendingRequests.length){const[{resolve:t,options:n,scripts:s}]=de.pendingRequests.splice(0,1);t(pe(e,n,s))}else e.worker&&e.worker.terminate(),de.pool=de.pool.filter((t=>t!=e))}async function fe(e,t,n,s,i,r,a){const o=Math.max(r.chunkSize,64);return async function r(d=0,c=0){const p=d*o;if(p>1,dataDescriptor:8==(8&s),languageEncodingFlag:(s&A)==A},e.encrypted=e.bitFlag.encrypted,e.rawLastModDate=t.getUint32(n+6,!0),e.lastModDate=function(e){const t=(4294901760&e)>>16,n=65535&e;try{return new Date(1980+((65024&t)>>9),((480&t)>>5)-1,31&t,(63488&n)>>11,(2016&n)>>5,2*(31&n),0)}catch(e){}}(e.rawLastModDate),e.filenameLength=t.getUint16(n+22,!0),e.extraFieldLength=t.getUint16(n+24,!0)}function Ie(e,t,n,s){const i=t.rawExtraField,r=t.extraField=new Map,a=new DataView(new Uint8Array(i).buffer);let o=0;try{for(;ot[e]==g));for(let t=0;t{if(t[n]==g){if(!e||void 0===e[n])throw new Error(ke);t[n]=e&&e[n]}}))}(c,t);const p=t.extraFieldUnicodePath=r.get(28789);p&&Se(p,"filename","rawFilename",t,e);let l=t.extraFieldUnicodeComment=r.get(25461);l&&Se(l,"comment","rawComment",t,e);const m=t.extraFieldAES=r.get(39169);m?function(e,t,n){if(e){const s=new DataView(e.data.buffer);e.vendorVersion=s.getUint8(0),e.vendorId=s.getUint8(2);const i=s.getUint8(4);e.strength=i,e.originalCompressionMethod=n,t.compressionMethod=e.compressionMethod=s.getUint16(5,!0)}else t.compressionMethod=n}(m,t,d):t.compressionMethod=d,8==t.compressionMethod&&(t.bitFlag.enhancedDeflating=16!=(16&t.rawBitFlag))}function Se(e,t,n,s,i){const r=new DataView(e.data.buffer);e.version=r.getUint8(0),e.signature=r.getUint32(1,!0);const a=new j;a.append(i[n]);const o=new DataView(new Uint8Array(4).buffer);o.setUint32(0,a.get()),e[t]=(new TextDecoder).decode(e.data.subarray(5)),e.signature==o.getUint32(0,!1)&&(s[t]=e[t])}function Be(e,t){return new TextDecoder(t).decode(e)}const Te="File already exists",Le="Zip file comment exceeds 64KB",_e="File entry comment exceeds 64KB",qe="File entry name exceeds 64KB",Ce="Version exceeds 65535",Ne="Extra field type exceeds 65535",Oe="Extra field data exceeds 64KB",Me=new Uint8Array([7,0,2,0,65,69,3,0,0]);function We(e){return unescape(encodeURIComponent(e))}function Pe(e){const t=[];for(let n=0;n{if(this.pendingData){const t=this.pendingData;this.pendingData=new Uint8Array(t.length+e.length),this.pendingData.set(t,0),this.pendingData.set(e,t.length)}else this.pendingData=new Uint8Array(e)};if(this.codec=new e(Object.assign({},t,n)),typeof this.codec.onData==Ve)this.codec.onData=s;else{if(typeof this.codec.on!=Ve)throw new Error("Cannot register the callback function");this.codec.on("data",s)}}async append(e){return this.codec.push(e),n(this)}async flush(){return this.codec.push(new Uint8Array(0),!0),n(this)}};function n(e){if(e.pendingData){const t=e.pendingData;return e.pendingData=null,t}return new Uint8Array(0)}}const He={chunkSize:524288,maxWorkers:"undefined"!=typeof navigator&&navigator.hardwareConcurrency||2,workerScriptsPath:void 0,useWebWorkers:!0};let Ke=Object.assign({},He);class Xe extends class{constructor(e,t={},n={}){this.reader=e,this.options=t,this.config=n}async getEntries(){const e=this.reader;e.initialized||await e.init();const t=await async function(e,t,n,s){const i=new Uint8Array(4);if(new DataView(i.buffer).setUint32(0,t),e.size=0;e--)if(r[e]==i[0]&&r[e+1]==i[1]&&r[e+2]==i[2]&&r[e+3]==i[3])return{offset:s,buffer:r.slice(e,e+n).buffer}}}(e,k,22,v);if(!t)throw new Error(ge);const n=new DataView(t.buffer);let s,i=n.getUint32(16,!0),r=n.getUint16(8,!0);if(i==g||r==v){s=!0;const n=await e.readUint8Array(t.offset-20,20),a=new DataView(n.buffer);if(Number(a.getUint32(0,!1))!=z)throw new Error(ve);i=Number(a.getBigUint64(8,!0));const o=await e.readUint8Array(i,56),d=new DataView(o.buffer);if(Number(d.getUint32(0,!1))!=U)throw new Error(we);r=Number(d.getBigUint64(24,!0)),i-=Number(d.getBigUint64(40,!0))}if(i<0||!s&&(i>=e.size||r>=v))throw new Error(xe);const a=await e.readUint8Array(i,e.size-i),o=new DataView(a.buffer),d=[];let c=0;for(let e=0;ev)throw new Error(_e);n.zip64=n.zip64||this.zip64,await async function(e,t,n,s){const i=e.files,r=e.writer;let a;i.set(t,null);try{let o,d;try{s.bufferedWrite||e.options.bufferedWrite||e.lockWrite?(o=new u,o.init()):(e.lockWrite=new Promise((e=>a=e)),r.initialized||await r.init(),o=r),(e.offset>=g||n&&(n.size>=g||e.offset+n.size>=g))&&(s.zip64=!0),d=await async function(e,t,n,s,i,r){const a=Pe(We(e)),o=r.lastModDate||new Date,d=new Uint8Array(26),c=new DataView(d.buffer),p=void 0===r.password?i.password:r.password,l=p&&p.length&&p,m=void 0===r.level?i.level:r.level,h=0!==m&&!r.directory,f=void 0===p||!p.length,u=r.zip64;let x;if(l){x=new Uint8Array(Me.length+2);new DataView(x.buffer).setUint16(0,E,!0),x.set(Me,2)}else x=new Uint8Array(0);const b={zip64:u,headerArray:d,directory:r.directory,filename:a,comment:r.comment,extraFieldZip64:u?new Uint8Array(28):new Uint8Array(0),extraFieldAES:x,rawExtraField:new Uint8Array(0)},k=r.extraField;if(a.length>v)throw new Error(qe);if(k){let e=4,t=0;k.forEach((t=>e+=t.length));const n=b.rawExtraField=new Uint8Array(e);k.forEach(((e,s)=>{if(s>v)throw new Error(Ne);if(e.length>v)throw new Error(Oe);n.set(new Uint16Array([s]),t),n.set(new Uint16Array([e.length]),t+2),n.set(e,t+4),t+=4+e.length}))}if(r.bitFlag=2056,r.version=(void 0===r.version?i.version:r.version)||20,r.version>v)throw new Error(Ce);r.compressionMethod=0,h&&(r.compressionMethod=8);u&&(r.version=r.version>R?r.version:R);l&&(b.encrypted=!0,r.version=r.version>D?r.version:D,r.bitFlag=1|r.bitFlag,r.compressionMethod=99,h&&(b.extraFieldAES[9]=8));c.setUint16(0,r.version,!0),c.setUint16(2,r.bitFlag,!0),c.setUint16(4,r.compressionMethod,!0),c.setUint16(6,(o.getHours()<<6|o.getMinutes())<<5|o.getSeconds()/2,!0),c.setUint16(8,(o.getFullYear()-1980<<4|o.getMonth()+1)<<5|o.getDate(),!0),c.setUint16(22,a.length,!0),c.setUint16(24,0,!0);const U=new Uint8Array(30+a.length);let z;if(new DataView(U.buffer).setUint32(0,w),U.set(d,4),U.set(a,30),t){t.initialized||await t.init();const e=await ce(s,{codecType:Q,level:m,outputPassword:p,outputSigned:f,outputCompressed:h,outputEncrypted:Boolean(p),useWebWorkers:void 0===r.useWebWorkers?i.useWebWorkers:r.useWebWorkers});await n.writeUint8Array(U),z=await fe(e,t,n,0,t.size,s,{onprogress:r.onprogress}),b.compressedSize=z.length}else await n.writeUint8Array(U);const A=new Uint8Array(u?24:16),j=new DataView(A.buffer);if(j.setUint32(0,y),t)if(l||void 0===z.signature||(c.setUint32(10,z.signature,!0),j.setUint32(4,z.signature,!0)),u){c.setUint32(14,g,!0),j.setBigUint64(8,BigInt(b.compressedSize),!0),c.setUint32(18,g,!0),j.setBigUint64(16,BigInt(t.size),!0);const e=new DataView(b.extraFieldZip64.buffer);e.setUint16(0,1,!0),e.setUint16(2,24,!0),e.setBigUint64(4,BigInt(t.size),!0),e.setBigUint64(12,BigInt(b.compressedSize),!0)}else c.setUint32(14,b.compressedSize,!0),j.setUint32(8,b.compressedSize,!0),c.setUint32(18,t.size,!0),j.setUint32(12,t.size,!0);return await n.writeUint8Array(A),b.length=U.length+(z?z.length:0)+A.length,b}(t,n,o,e.config,e.options,s)}catch(e){throw i.delete(t),e}if(i.set(t,d),o!=r&&(e.lockWrite&&await e.lockWrite,await r.writeUint8Array(o.getData())),d.offset=e.offset,d.zip64){new DataView(d.extraFieldZip64.buffer).setBigUint64(20,BigInt(d.offset),!0)}e.offset+=d.length}finally{a&&(e.lockWrite=null,a())}}(this,e,t,n)}async close(e){const t=this.writer,n=this.files;let s=0,i=0,r=this.offset,a=n.size;if(e&&e.length){if(!(e.length<=v))throw new Error(Le);d.setUint16(s+20,e.length,!0)}for(const[,e]of n)i+=46+e.filename.length+e.comment.length+e.extraFieldZip64.length+e.extraFieldAES.length+e.rawExtraField.length;(r+i>=g||a>=v)&&(this.zip64=!0);const o=new Uint8Array(i+(this.zip64?98:22)),d=new DataView(o.buffer);this.options.version=this.options.version||20;for(const[,e]of n){const t=e.filename,n=e.extraFieldZip64,i=e.extraFieldAES,r=n.length+i.length+e.rawExtraField.length;d.setUint32(s,b),e.zip64&&d.setUint16(s+4,this.options.version>R?this.options:R,!0),e.encrypted?d.setUint16(s+4,this.options.version>D?this.options:D,!0):d.setUint16(s+4,this.options.version>20?this.options:20,!0),o.set(e.headerArray,s+6),d.setUint16(s+30,r,!0),d.setUint16(s+32,e.comment.length,!0),e.directory&&d.setUint8(s+38,16),e.zip64?d.setUint32(s+42,g,!0):d.setUint32(s+42,e.offset,!0),o.set(t,s+46),o.set(n,s+46+t.length),o.set(i,s+46+t.length+n.length),o.set(e.rawExtraField,46+t.length+n.length+i.length),o.set(e.comment,s+46+t.length+r),s+=46+t.length+r+e.comment.length}return this.zip64&&(d.setUint32(s,U),d.setBigUint64(s+4,BigInt(44),!0),d.setUint16(s+12,45,!0),d.setUint16(s+14,45,!0),d.setBigUint64(s+24,BigInt(a),!0),d.setBigUint64(s+32,BigInt(a),!0),d.setBigUint64(s+40,BigInt(i),!0),d.setBigUint64(s+48,BigInt(r),!0),d.setUint32(s+56,z),d.setBigUint64(s+64,BigInt(r+i),!0),d.setUint32(s+72,1,!0),a=v,r=g,s+=76),d.setUint32(s,k),d.setUint16(s+8,a,!0),d.setUint16(s+10,a,!0),d.setUint32(s+12,i,!0),d.setUint32(s+16,r,!0),await t.writeUint8Array(o),e&&e.length&&await t.writeUint8Array(e),t.getData()}}{constructor(e,t){super(e,t,Ke)}}const Ge=524288;class Je{constructor(e,t,n,s){if(e.root&&s&&s.getChildByName(t))throw new Error("Entry filename already exists");n||(n={}),this.fs=e,this.name=t,this.id=e.entries.length,this.parent=s,this.children=[],this.zipVersion=n.zipVersion||20,this.uncompressedSize=0,e.entries.push(this),s&&this.parent.children.push(this)}moveTo(e){if(!e.directory)throw new Error("Target entry is not a directory");if(e.isDescendantOf(this))throw new Error("Entry is a ancestor of target entry");if(this!=e){if(e.getChildByName(this.name))throw new Error("Entry filename already exists");it(this),this.parent=e,e.children.push(this)}}getFullname(){let e=this.name,t=this.parent;for(;t;)e=(t.name?t.name+"/":"")+e,t=t.parent;return e}isDescendantOf(e){let t=this.parent;for(;t&&t.id!=e.id;)t=t.parent;return Boolean(t)}}class Qe extends Je{constructor(e,t,n,s){super(e,t,n,s),this.Reader=n.Reader,this.Writer=n.Writer,this.data=n.data,n.getData&&(this.getData=n.getData)}async getData(e,t={}){return!e||e.constructor==this.Writer&&this.data?this.data:(this.reader||(this.reader=new this.Reader(this.data)),await this.reader.init(),await e.init(),this.uncompressedSize=this.reader.size,async function(e,t,n){return s();async function s(i=0){const r=i*Ge;if(n.onprogress&&n.onprogress(r,e.size),r{t.file((s=>{e.addBlob(t.name,s),n()}),s)}));function n(e){return new Promise(((t,n)=>{let s=[];function i(e){e.readEntries((n=>{n.length?(s=s.concat(n),i(e)):t(s)}),n)}e.isDirectory&&i(e.createReader()),e.isFile&&t(s)}))}async function s(e,t){const i=await n(t);for(const t of i)t.isDirectory&&await s(e.addDirectory(t.name)),await new Promise(((n,s)=>{t.isFile&&t.file((s=>{const i=e.addBlob(t.name,s);i.uncompressedSize=s.size,n(i)}),s)}))}}(this,e)}async addData(e,t){return at(this,e,t)}async importBlob(e,t={}){await this.importZip(new l(e),t)}async importData64URI(e,t={}){await this.importZip(new c(e),t)}async importHttpContent(e,t={}){await this.importZip(t.useRangeHeader?new f(e):new h(e),t)}async exportBlob(e={}){return this.exportZip(new m("application/zip"),e)}async exportData64URI(e={}){return this.exportZip(new p("application/zip"),e)}async importZip(e,t){await e.init();const n=new Xe(e),s=await n.getEntries();let i=0;const r=tt(s,"compressedSize");s.forEach((e=>{let n=this,s=e.filename.split("/"),a=s.pop();if(s.forEach((e=>n=n.getChildByName(e)||new $e(this.fs,e,null,n))),!e.directory){let s=i;at(n,a,{data:e,Reader:nt(Object.assign({},t,{onprogress:e=>{t.onprogress&&t.onprogress(s+e,r)}}))}),i+=e.compressedSize}}))}async exportZip(e,t){await st(this);const n=new Ye(e);return await async function(e,t,n,s){let i=0;async function r(e,t){async function a(){let a=0;for(const o of t.children){let t=i;await e.add(o.getFullname(),o.reader,Object.assign({directory:o.directory,version:o.zipVersion},s,{onprogress:e=>{s.onprogress&&s.onprogress(t+a+e,n)}})),i+=o.uncompressedSize,await r(e,o),a++}}await a()}await r(e,t)}(n,this,tt([this],"uncompressedSize"),t),await n.close(),e.getData()}getChildByName(e){for(let t=0;t{n.id==e.id&&t.splice(s,1)}))}function rt(e){e.entries=[],e.root=new $e(e)}function at(e,t,n,s){if(e.directory)return s?new $e(e.fs,t,n,e):new Qe(e.fs,t,n,e);throw new Error("Parent entry is not a directory")}const ot={application:{"andrew-inset":"ez",annodex:"anx","atom+xml":"atom","atomcat+xml":"atomcat","atomserv+xml":"atomsrv",bbolin:"lin",cap:["cap","pcap"],"cu-seeme":"cu","davmount+xml":"davmount",dsptype:"tsp",ecmascript:["es","ecma"],futuresplash:"spl",hta:"hta","java-archive":"jar","java-serialized-object":"ser","java-vm":"class",javascript:"js",m3g:"m3g","mac-binhex40":"hqx",mathematica:["nb","ma","mb"],msaccess:"mdb",msword:["doc","dot"],mxf:"mxf",oda:"oda",ogg:"ogx",pdf:"pdf","pgp-keys":"key","pgp-signature":["asc","sig"],"pics-rules":"prf",postscript:["ps","ai","eps","epsi","epsf","eps2","eps3"],rar:"rar","rdf+xml":"rdf","rss+xml":"rss",rtf:"rtf",smil:["smi","smil"],"xhtml+xml":["xhtml","xht"],xml:["xml","xsl","xsd"],"xspf+xml":"xspf",zip:"zip","vnd.android.package-archive":"apk","vnd.cinderella":"cdy","vnd.google-earth.kml+xml":"kml","vnd.google-earth.kmz":"kmz","vnd.mozilla.xul+xml":"xul","vnd.ms-excel":["xls","xlb","xlt","xlm","xla","xlc","xlw"],"vnd.ms-pki.seccat":"cat","vnd.ms-pki.stl":"stl","vnd.ms-powerpoint":["ppt","pps","pot"],"vnd.oasis.opendocument.chart":"odc","vnd.oasis.opendocument.database":"odb","vnd.oasis.opendocument.formula":"odf","vnd.oasis.opendocument.graphics":"odg","vnd.oasis.opendocument.graphics-template":"otg","vnd.oasis.opendocument.image":"odi","vnd.oasis.opendocument.presentation":"odp","vnd.oasis.opendocument.presentation-template":"otp","vnd.oasis.opendocument.spreadsheet":"ods","vnd.oasis.opendocument.spreadsheet-template":"ots","vnd.oasis.opendocument.text":"odt","vnd.oasis.opendocument.text-master":"odm","vnd.oasis.opendocument.text-template":"ott","vnd.oasis.opendocument.text-web":"oth","vnd.openxmlformats-officedocument.spreadsheetml.sheet":"xlsx","vnd.openxmlformats-officedocument.spreadsheetml.template":"xltx","vnd.openxmlformats-officedocument.presentationml.presentation":"pptx","vnd.openxmlformats-officedocument.presentationml.slideshow":"ppsx","vnd.openxmlformats-officedocument.presentationml.template":"potx","vnd.openxmlformats-officedocument.wordprocessingml.document":"docx","vnd.openxmlformats-officedocument.wordprocessingml.template":"dotx","vnd.smaf":"mmf","vnd.stardivision.calc":"sdc","vnd.stardivision.chart":"sds","vnd.stardivision.draw":"sda","vnd.stardivision.impress":"sdd","vnd.stardivision.math":["sdf","smf"],"vnd.stardivision.writer":["sdw","vor"],"vnd.stardivision.writer-global":"sgl","vnd.sun.xml.calc":"sxc","vnd.sun.xml.calc.template":"stc","vnd.sun.xml.draw":"sxd","vnd.sun.xml.draw.template":"std","vnd.sun.xml.impress":"sxi","vnd.sun.xml.impress.template":"sti","vnd.sun.xml.math":"sxm","vnd.sun.xml.writer":"sxw","vnd.sun.xml.writer.global":"sxg","vnd.sun.xml.writer.template":"stw","vnd.symbian.install":["sis","sisx"],"vnd.visio":["vsd","vst","vss","vsw"],"vnd.wap.wbxml":"wbxml","vnd.wap.wmlc":"wmlc","vnd.wap.wmlscriptc":"wmlsc","vnd.wordperfect":"wpd","vnd.wordperfect5.1":"wp5","x-123":"wk","x-7z-compressed":"7z","x-abiword":"abw","x-apple-diskimage":"dmg","x-bcpio":"bcpio","x-bittorrent":"torrent","x-cbr":["cbr","cba","cbt","cb7"],"x-cbz":"cbz","x-cdf":["cdf","cda"],"x-cdlink":"vcd","x-chess-pgn":"pgn","x-cpio":"cpio","x-csh":"csh","x-debian-package":["deb","udeb"],"x-director":["dcr","dir","dxr","cst","cct","cxt","w3d","fgd","swa"],"x-dms":"dms","x-doom":"wad","x-dvi":"dvi","x-httpd-eruby":"rhtml","x-font":"pcf.Z","x-freemind":"mm","x-gnumeric":"gnumeric","x-go-sgf":"sgf","x-graphing-calculator":"gcf","x-gtar":["gtar","taz"],"x-hdf":"hdf","x-httpd-php":["phtml","pht","php"],"x-httpd-php-source":"phps","x-httpd-php3":"php3","x-httpd-php3-preprocessed":"php3p","x-httpd-php4":"php4","x-httpd-php5":"php5","x-ica":"ica","x-info":"info","x-internet-signup":["ins","isp"],"x-iphone":"iii","x-iso9660-image":"iso","x-java-jnlp-file":"jnlp","x-jmol":"jmz","x-killustrator":"kil","x-koan":["skp","skd","skt","skm"],"x-kpresenter":["kpr","kpt"],"x-kword":["kwd","kwt"],"x-latex":"latex","x-lha":"lha","x-lyx":"lyx","x-lzh":"lzh","x-lzx":"lzx","x-maker":["frm","maker","frame","fm","fb","book","fbdoc"],"x-ms-wmd":"wmd","x-ms-wmz":"wmz","x-msdos-program":["com","exe","bat","dll"],"x-msi":"msi","x-netcdf":["nc","cdf"],"x-ns-proxy-autoconfig":["pac","dat"],"x-nwc":"nwc","x-object":"o","x-oz-application":"oza","x-pkcs7-certreqresp":"p7r","x-python-code":["pyc","pyo"],"x-qgis":["qgs","shp","shx"],"x-quicktimeplayer":"qtl","x-redhat-package-manager":"rpm","x-ruby":"rb","x-sh":"sh","x-shar":"shar","x-shockwave-flash":["swf","swfl"],"x-silverlight":"scr","x-stuffit":"sit","x-sv4cpio":"sv4cpio","x-sv4crc":"sv4crc","x-tar":"tar","x-tcl":"tcl","x-tex-gf":"gf","x-tex-pk":"pk","x-texinfo":["texinfo","texi"],"x-trash":["~","%","bak","old","sik"],"x-troff":["t","tr","roff"],"x-troff-man":"man","x-troff-me":"me","x-troff-ms":"ms","x-ustar":"ustar","x-wais-source":"src","x-wingz":"wz","x-x509-ca-cert":["crt","der","cer"],"x-xcf":"xcf","x-xfig":"fig","x-xpinstall":"xpi",applixware:"aw","atomsvc+xml":"atomsvc","ccxml+xml":"ccxml","cdmi-capability":"cdmia","cdmi-container":"cdmic","cdmi-domain":"cdmid","cdmi-object":"cdmio","cdmi-queue":"cdmiq","docbook+xml":"dbk","dssc+der":"dssc","dssc+xml":"xdssc","emma+xml":"emma","epub+zip":"epub",exi:"exi","font-tdpfr":"pfr","gml+xml":"gml","gpx+xml":"gpx",gxf:"gxf",hyperstudio:"stk","inkml+xml":["ink","inkml"],ipfix:"ipfix",json:"json","jsonml+json":"jsonml","lost+xml":"lostxml","mads+xml":"mads",marc:"mrc","marcxml+xml":"mrcx","mathml+xml":"mathml",mbox:"mbox","mediaservercontrol+xml":"mscml","metalink+xml":"metalink","metalink4+xml":"meta4","mets+xml":"mets","mods+xml":"mods",mp21:["m21","mp21"],mp4:"mp4s","oebps-package+xml":"opf","omdoc+xml":"omdoc",onenote:["onetoc","onetoc2","onetmp","onepkg"],oxps:"oxps","patch-ops-error+xml":"xer","pgp-encrypted":"pgp",pkcs10:"p10","pkcs7-mime":["p7m","p7c"],"pkcs7-signature":"p7s",pkcs8:"p8","pkix-attr-cert":"ac","pkix-crl":"crl","pkix-pkipath":"pkipath",pkixcmp:"pki","pls+xml":"pls","prs.cww":"cww","pskc+xml":"pskcxml","reginfo+xml":"rif","relax-ng-compact-syntax":"rnc","resource-lists+xml":"rl","resource-lists-diff+xml":"rld","rls-services+xml":"rs","rpki-ghostbusters":"gbr","rpki-manifest":"mft","rpki-roa":"roa","rsd+xml":"rsd","sbml+xml":"sbml","scvp-cv-request":"scq","scvp-cv-response":"scs","scvp-vp-request":"spq","scvp-vp-response":"spp",sdp:"sdp","set-payment-initiation":"setpay","set-registration-initiation":"setreg","shf+xml":"shf","sparql-query":"rq","sparql-results+xml":"srx",srgs:"gram","srgs+xml":"grxml","sru+xml":"sru","ssdl+xml":"ssdl","ssml+xml":"ssml","tei+xml":["tei","teicorpus"],"thraud+xml":"tfi","timestamped-data":"tsd","vnd.3gpp.pic-bw-large":"plb","vnd.3gpp.pic-bw-small":"psb","vnd.3gpp.pic-bw-var":"pvb","vnd.3gpp2.tcap":"tcap","vnd.3m.post-it-notes":"pwn","vnd.accpac.simply.aso":"aso","vnd.accpac.simply.imp":"imp","vnd.acucobol":"acu","vnd.acucorp":["atc","acutc"],"vnd.adobe.air-application-installer-package+zip":"air","vnd.adobe.formscentral.fcdt":"fcdt","vnd.adobe.fxp":["fxp","fxpl"],"vnd.adobe.xdp+xml":"xdp","vnd.adobe.xfdf":"xfdf","vnd.ahead.space":"ahead","vnd.airzip.filesecure.azf":"azf","vnd.airzip.filesecure.azs":"azs","vnd.amazon.ebook":"azw","vnd.americandynamics.acc":"acc","vnd.amiga.ami":"ami","vnd.anser-web-certificate-issue-initiation":"cii","vnd.anser-web-funds-transfer-initiation":"fti","vnd.antix.game-component":"atx","vnd.apple.installer+xml":"mpkg","vnd.apple.mpegurl":"m3u8","vnd.aristanetworks.swi":"swi","vnd.astraea-software.iota":"iota","vnd.audiograph":"aep","vnd.blueice.multipass":"mpm","vnd.bmi":"bmi","vnd.businessobjects":"rep","vnd.chemdraw+xml":"cdxml","vnd.chipnuts.karaoke-mmd":"mmd","vnd.claymore":"cla","vnd.cloanto.rp9":"rp9","vnd.clonk.c4group":["c4g","c4d","c4f","c4p","c4u"],"vnd.cluetrust.cartomobile-config":"c11amc","vnd.cluetrust.cartomobile-config-pkg":"c11amz","vnd.commonspace":"csp","vnd.contact.cmsg":"cdbcmsg","vnd.cosmocaller":"cmc","vnd.crick.clicker":"clkx","vnd.crick.clicker.keyboard":"clkk","vnd.crick.clicker.palette":"clkp","vnd.crick.clicker.template":"clkt","vnd.crick.clicker.wordbank":"clkw","vnd.criticaltools.wbs+xml":"wbs","vnd.ctc-posml":"pml","vnd.cups-ppd":"ppd","vnd.curl.car":"car","vnd.curl.pcurl":"pcurl","vnd.dart":"dart","vnd.data-vision.rdz":"rdz","vnd.dece.data":["uvf","uvvf","uvd","uvvd"],"vnd.dece.ttml+xml":["uvt","uvvt"],"vnd.dece.unspecified":["uvx","uvvx"],"vnd.dece.zip":["uvz","uvvz"],"vnd.denovo.fcselayout-link":"fe_launch","vnd.dna":"dna","vnd.dolby.mlp":"mlp","vnd.dpgraph":"dpg","vnd.dreamfactory":"dfac","vnd.ds-keypoint":"kpxx","vnd.dvb.ait":"ait","vnd.dvb.service":"svc","vnd.dynageo":"geo","vnd.ecowin.chart":"mag","vnd.enliven":"nml","vnd.epson.esf":"esf","vnd.epson.msf":"msf","vnd.epson.quickanime":"qam","vnd.epson.salt":"slt","vnd.epson.ssf":"ssf","vnd.eszigno3+xml":["es3","et3"],"vnd.ezpix-album":"ez2","vnd.ezpix-package":"ez3","vnd.fdf":"fdf","vnd.fdsn.mseed":"mseed","vnd.fdsn.seed":["seed","dataless"],"vnd.flographit":"gph","vnd.fluxtime.clip":"ftc","vnd.framemaker":["fm","frame","maker","book"],"vnd.frogans.fnc":"fnc","vnd.frogans.ltf":"ltf","vnd.fsc.weblaunch":"fsc","vnd.fujitsu.oasys":"oas","vnd.fujitsu.oasys2":"oa2","vnd.fujitsu.oasys3":"oa3","vnd.fujitsu.oasysgp":"fg5","vnd.fujitsu.oasysprs":"bh2","vnd.fujixerox.ddd":"ddd","vnd.fujixerox.docuworks":"xdw","vnd.fujixerox.docuworks.binder":"xbd","vnd.fuzzysheet":"fzs","vnd.genomatix.tuxedo":"txd","vnd.geogebra.file":"ggb","vnd.geogebra.tool":"ggt","vnd.geometry-explorer":["gex","gre"],"vnd.geonext":"gxt","vnd.geoplan":"g2w","vnd.geospace":"g3w","vnd.gmx":"gmx","vnd.grafeq":["gqf","gqs"],"vnd.groove-account":"gac","vnd.groove-help":"ghf","vnd.groove-identity-message":"gim","vnd.groove-injector":"grv","vnd.groove-tool-message":"gtm","vnd.groove-tool-template":"tpl","vnd.groove-vcard":"vcg","vnd.hal+xml":"hal","vnd.handheld-entertainment+xml":"zmm","vnd.hbci":"hbci","vnd.hhe.lesson-player":"les","vnd.hp-hpgl":"hpgl","vnd.hp-hpid":"hpid","vnd.hp-hps":"hps","vnd.hp-jlyt":"jlt","vnd.hp-pcl":"pcl","vnd.hp-pclxl":"pclxl","vnd.hydrostatix.sof-data":"sfd-hdstx","vnd.ibm.minipay":"mpy","vnd.ibm.modcap":["afp","listafp","list3820"],"vnd.ibm.rights-management":"irm","vnd.ibm.secure-container":"sc","vnd.iccprofile":["icc","icm"],"vnd.igloader":"igl","vnd.immervision-ivp":"ivp","vnd.immervision-ivu":"ivu","vnd.insors.igm":"igm","vnd.intercon.formnet":["xpw","xpx"],"vnd.intergeo":"i2g","vnd.intu.qbo":"qbo","vnd.intu.qfx":"qfx","vnd.ipunplugged.rcprofile":"rcprofile","vnd.irepository.package+xml":"irp","vnd.is-xpr":"xpr","vnd.isac.fcs":"fcs","vnd.jam":"jam","vnd.jcp.javame.midlet-rms":"rms","vnd.jisp":"jisp","vnd.joost.joda-archive":"joda","vnd.kahootz":["ktz","ktr"],"vnd.kde.karbon":"karbon","vnd.kde.kchart":"chrt","vnd.kde.kformula":"kfo","vnd.kde.kivio":"flw","vnd.kde.kontour":"kon","vnd.kde.kpresenter":["kpr","kpt"],"vnd.kde.kspread":"ksp","vnd.kde.kword":["kwd","kwt"],"vnd.kenameaapp":"htke","vnd.kidspiration":"kia","vnd.kinar":["kne","knp"],"vnd.koan":["skp","skd","skt","skm"],"vnd.kodak-descriptor":"sse","vnd.las.las+xml":"lasxml","vnd.llamagraphics.life-balance.desktop":"lbd","vnd.llamagraphics.life-balance.exchange+xml":"lbe","vnd.lotus-1-2-3":"123","vnd.lotus-approach":"apr","vnd.lotus-freelance":"pre","vnd.lotus-notes":"nsf","vnd.lotus-organizer":"org","vnd.lotus-screencam":"scm","vnd.lotus-wordpro":"lwp","vnd.macports.portpkg":"portpkg","vnd.mcd":"mcd","vnd.medcalcdata":"mc1","vnd.mediastation.cdkey":"cdkey","vnd.mfer":"mwf","vnd.mfmp":"mfm","vnd.micrografx.flo":"flo","vnd.micrografx.igx":"igx","vnd.mif":"mif","vnd.mobius.daf":"daf","vnd.mobius.dis":"dis","vnd.mobius.mbk":"mbk","vnd.mobius.mqy":"mqy","vnd.mobius.msl":"msl","vnd.mobius.plc":"plc","vnd.mobius.txf":"txf","vnd.mophun.application":"mpn","vnd.mophun.certificate":"mpc","vnd.ms-artgalry":"cil","vnd.ms-cab-compressed":"cab","vnd.ms-excel.addin.macroenabled.12":"xlam","vnd.ms-excel.sheet.binary.macroenabled.12":"xlsb","vnd.ms-excel.sheet.macroenabled.12":"xlsm","vnd.ms-excel.template.macroenabled.12":"xltm","vnd.ms-fontobject":"eot","vnd.ms-htmlhelp":"chm","vnd.ms-ims":"ims","vnd.ms-lrm":"lrm","vnd.ms-officetheme":"thmx","vnd.ms-powerpoint.addin.macroenabled.12":"ppam","vnd.ms-powerpoint.presentation.macroenabled.12":"pptm","vnd.ms-powerpoint.slide.macroenabled.12":"sldm","vnd.ms-powerpoint.slideshow.macroenabled.12":"ppsm","vnd.ms-powerpoint.template.macroenabled.12":"potm","vnd.ms-project":["mpp","mpt"],"vnd.ms-word.document.macroenabled.12":"docm","vnd.ms-word.template.macroenabled.12":"dotm","vnd.ms-works":["wps","wks","wcm","wdb"],"vnd.ms-wpl":"wpl","vnd.ms-xpsdocument":"xps","vnd.mseq":"mseq","vnd.musician":"mus","vnd.muvee.style":"msty","vnd.mynfc":"taglet","vnd.neurolanguage.nlu":"nlu","vnd.nitf":["ntf","nitf"],"vnd.noblenet-directory":"nnd","vnd.noblenet-sealer":"nns","vnd.noblenet-web":"nnw","vnd.nokia.n-gage.data":"ngdat","vnd.nokia.n-gage.symbian.install":"n-gage","vnd.nokia.radio-preset":"rpst","vnd.nokia.radio-presets":"rpss","vnd.novadigm.edm":"edm","vnd.novadigm.edx":"edx","vnd.novadigm.ext":"ext","vnd.oasis.opendocument.chart-template":"otc","vnd.oasis.opendocument.formula-template":"odft","vnd.oasis.opendocument.image-template":"oti","vnd.olpc-sugar":"xo","vnd.oma.dd2+xml":"dd2","vnd.openofficeorg.extension":"oxt","vnd.openxmlformats-officedocument.presentationml.slide":"sldx","vnd.osgeo.mapguide.package":"mgp","vnd.osgi.dp":"dp","vnd.osgi.subsystem":"esa","vnd.palm":["pdb","pqa","oprc"],"vnd.pawaafile":"paw","vnd.pg.format":"str","vnd.pg.osasli":"ei6","vnd.picsel":"efif","vnd.pmi.widget":"wg","vnd.pocketlearn":"plf","vnd.powerbuilder6":"pbd","vnd.previewsystems.box":"box","vnd.proteus.magazine":"mgz","vnd.publishare-delta-tree":"qps","vnd.pvi.ptid1":"ptid","vnd.quark.quarkxpress":["qxd","qxt","qwd","qwt","qxl","qxb"],"vnd.realvnc.bed":"bed","vnd.recordare.musicxml":"mxl","vnd.recordare.musicxml+xml":"musicxml","vnd.rig.cryptonote":"cryptonote","vnd.rn-realmedia":"rm","vnd.rn-realmedia-vbr":"rmvb","vnd.route66.link66+xml":"link66","vnd.sailingtracker.track":"st","vnd.seemail":"see","vnd.sema":"sema","vnd.semd":"semd","vnd.semf":"semf","vnd.shana.informed.formdata":"ifm","vnd.shana.informed.formtemplate":"itp","vnd.shana.informed.interchange":"iif","vnd.shana.informed.package":"ipk","vnd.simtech-mindmapper":["twd","twds"],"vnd.smart.teacher":"teacher","vnd.solent.sdkm+xml":["sdkm","sdkd"],"vnd.spotfire.dxp":"dxp","vnd.spotfire.sfs":"sfs","vnd.stepmania.package":"smzip","vnd.stepmania.stepchart":"sm","vnd.sus-calendar":["sus","susp"],"vnd.svd":"svd","vnd.syncml+xml":"xsm","vnd.syncml.dm+wbxml":"bdm","vnd.syncml.dm+xml":"xdm","vnd.tao.intent-module-archive":"tao","vnd.tcpdump.pcap":["pcap","cap","dmp"],"vnd.tmobile-livetv":"tmo","vnd.trid.tpt":"tpt","vnd.triscape.mxs":"mxs","vnd.trueapp":"tra","vnd.ufdl":["ufd","ufdl"],"vnd.uiq.theme":"utz","vnd.umajin":"umj","vnd.unity":"unityweb","vnd.uoml+xml":"uoml","vnd.vcx":"vcx","vnd.visionary":"vis","vnd.vsf":"vsf","vnd.webturbo":"wtb","vnd.wolfram.player":"nbp","vnd.wqd":"wqd","vnd.wt.stf":"stf","vnd.xara":"xar","vnd.xfdl":"xfdl","vnd.yamaha.hv-dic":"hvd","vnd.yamaha.hv-script":"hvs","vnd.yamaha.hv-voice":"hvp","vnd.yamaha.openscoreformat":"osf","vnd.yamaha.openscoreformat.osfpvg+xml":"osfpvg","vnd.yamaha.smaf-audio":"saf","vnd.yamaha.smaf-phrase":"spf","vnd.yellowriver-custom-menu":"cmp","vnd.zul":["zir","zirz"],"vnd.zzazz.deck+xml":"zaz","voicexml+xml":"vxml",widget:"wgt",winhlp:"hlp","wsdl+xml":"wsdl","wspolicy+xml":"wspolicy","x-ace-compressed":"ace","x-authorware-bin":["aab","x32","u32","vox"],"x-authorware-map":"aam","x-authorware-seg":"aas","x-blorb":["blb","blorb"],"x-bzip":"bz","x-bzip2":["bz2","boz"],"x-cfs-compressed":"cfs","x-chat":"chat","x-conference":"nsc","x-dgc-compressed":"dgc","x-dtbncx+xml":"ncx","x-dtbook+xml":"dtb","x-dtbresource+xml":"res","x-eva":"eva","x-font-bdf":"bdf","x-font-ghostscript":"gsf","x-font-linux-psf":"psf","x-font-otf":"otf","x-font-pcf":"pcf","x-font-snf":"snf","x-font-ttf":["ttf","ttc"],"x-font-type1":["pfa","pfb","pfm","afm"],"x-font-woff":"woff","x-freearc":"arc","x-gca-compressed":"gca","x-glulx":"ulx","x-gramps-xml":"gramps","x-install-instructions":"install","x-lzh-compressed":["lzh","lha"],"x-mie":"mie","x-mobipocket-ebook":["prc","mobi"],"x-ms-application":"application","x-ms-shortcut":"lnk","x-ms-xbap":"xbap","x-msbinder":"obd","x-mscardfile":"crd","x-msclip":"clp","x-msdownload":["exe","dll","com","bat","msi"],"x-msmediaview":["mvb","m13","m14"],"x-msmetafile":["wmf","wmz","emf","emz"],"x-msmoney":"mny","x-mspublisher":"pub","x-msschedule":"scd","x-msterminal":"trm","x-mswrite":"wri","x-nzb":"nzb","x-pkcs12":["p12","pfx"],"x-pkcs7-certificates":["p7b","spc"],"x-research-info-systems":"ris","x-silverlight-app":"xap","x-sql":"sql","x-stuffitx":"sitx","x-subrip":"srt","x-t3vm-image":"t3","x-tads":"gam","x-tex":"tex","x-tex-tfm":"tfm","x-tgif":"obj","x-xliff+xml":"xlf","x-xz":"xz","x-zmachine":["z1","z2","z3","z4","z5","z6","z7","z8"],"xaml+xml":"xaml","xcap-diff+xml":"xdf","xenc+xml":"xenc","xml-dtd":"dtd","xop+xml":"xop","xproc+xml":"xpl","xslt+xml":"xslt","xv+xml":["mxml","xhvml","xvml","xvm"],yang:"yang","yin+xml":"yin",envoy:"evy",fractals:"fif","internet-property-stream":"acx",olescript:"axs","vnd.ms-outlook":"msg","vnd.ms-pkicertstore":"sst","x-compress":"z","x-compressed":"tgz","x-gzip":"gz","x-perfmon":["pma","pmc","pml","pmr","pmw"],"x-pkcs7-mime":["p7c","p7m"],"ynd.ms-pkipko":"pko"},audio:{amr:"amr","amr-wb":"awb",annodex:"axa",basic:["au","snd"],flac:"flac",midi:["mid","midi","kar","rmi"],mpeg:["mpga","mpega","mp2","mp3","m4a","mp2a","m2a","m3a"],mpegurl:"m3u",ogg:["oga","ogg","spx"],"prs.sid":"sid","x-aiff":["aif","aiff","aifc"],"x-gsm":"gsm","x-ms-wma":"wma","x-ms-wax":"wax","x-pn-realaudio":"ram","x-realaudio":"ra","x-sd2":"sd2","x-wav":"wav",adpcm:"adp",mp4:"mp4a",s3m:"s3m",silk:"sil","vnd.dece.audio":["uva","uvva"],"vnd.digital-winds":"eol","vnd.dra":"dra","vnd.dts":"dts","vnd.dts.hd":"dtshd","vnd.lucent.voice":"lvp","vnd.ms-playready.media.pya":"pya","vnd.nuera.ecelp4800":"ecelp4800","vnd.nuera.ecelp7470":"ecelp7470","vnd.nuera.ecelp9600":"ecelp9600","vnd.rip":"rip",webm:"weba","x-aac":"aac","x-caf":"caf","x-matroska":"mka","x-pn-realaudio-plugin":"rmp",xm:"xm",mid:["mid","rmi"]},chemical:{"x-alchemy":"alc","x-cache":["cac","cache"],"x-cache-csf":"csf","x-cactvs-binary":["cbin","cascii","ctab"],"x-cdx":"cdx","x-chem3d":"c3d","x-cif":"cif","x-cmdf":"cmdf","x-cml":"cml","x-compass":"cpa","x-crossfire":"bsd","x-csml":["csml","csm"],"x-ctx":"ctx","x-cxf":["cxf","cef"],"x-embl-dl-nucleotide":["emb","embl"],"x-gamess-input":["inp","gam","gamin"],"x-gaussian-checkpoint":["fch","fchk"],"x-gaussian-cube":"cub","x-gaussian-input":["gau","gjc","gjf"],"x-gaussian-log":"gal","x-gcg8-sequence":"gcg","x-genbank":"gen","x-hin":"hin","x-isostar":["istr","ist"],"x-jcamp-dx":["jdx","dx"],"x-kinemage":"kin","x-macmolecule":"mcm","x-macromodel-input":["mmd","mmod"],"x-mdl-molfile":"mol","x-mdl-rdfile":"rd","x-mdl-rxnfile":"rxn","x-mdl-sdfile":["sd","sdf"],"x-mdl-tgf":"tgf","x-mmcif":"mcif","x-mol2":"mol2","x-molconn-Z":"b","x-mopac-graph":"gpt","x-mopac-input":["mop","mopcrt","mpc","zmt"],"x-mopac-out":"moo","x-ncbi-asn1":"asn","x-ncbi-asn1-ascii":["prt","ent"],"x-ncbi-asn1-binary":["val","aso"],"x-pdb":["pdb","ent"],"x-rosdal":"ros","x-swissprot":"sw","x-vamas-iso14976":"vms","x-vmd":"vmd","x-xtel":"xtel","x-xyz":"xyz"},image:{gif:"gif",ief:"ief",jpeg:["jpeg","jpg","jpe"],pcx:"pcx",png:"png","svg+xml":["svg","svgz"],tiff:["tiff","tif"],"vnd.djvu":["djvu","djv"],"vnd.wap.wbmp":"wbmp","x-canon-cr2":"cr2","x-canon-crw":"crw","x-cmu-raster":"ras","x-coreldraw":"cdr","x-coreldrawpattern":"pat","x-coreldrawtemplate":"cdt","x-corelphotopaint":"cpt","x-epson-erf":"erf","x-icon":"ico","x-jg":"art","x-jng":"jng","x-nikon-nef":"nef","x-olympus-orf":"orf","x-photoshop":"psd","x-portable-anymap":"pnm","x-portable-bitmap":"pbm","x-portable-graymap":"pgm","x-portable-pixmap":"ppm","x-rgb":"rgb","x-xbitmap":"xbm","x-xpixmap":"xpm","x-xwindowdump":"xwd",bmp:"bmp",cgm:"cgm",g3fax:"g3",ktx:"ktx","prs.btif":"btif",sgi:"sgi","vnd.dece.graphic":["uvi","uvvi","uvg","uvvg"],"vnd.dwg":"dwg","vnd.dxf":"dxf","vnd.fastbidsheet":"fbs","vnd.fpx":"fpx","vnd.fst":"fst","vnd.fujixerox.edmics-mmr":"mmr","vnd.fujixerox.edmics-rlc":"rlc","vnd.ms-modi":"mdi","vnd.ms-photo":"wdp","vnd.net-fpx":"npx","vnd.xiff":"xif",webp:"webp","x-3ds":"3ds","x-cmx":"cmx","x-freehand":["fh","fhc","fh4","fh5","fh7"],"x-pict":["pic","pct"],"x-tga":"tga","cis-cod":"cod",pipeg:"jfif"},message:{rfc822:["eml","mime","mht","mhtml","nws"]},model:{iges:["igs","iges"],mesh:["msh","mesh","silo"],vrml:["wrl","vrml"],"x3d+vrml":["x3dv","x3dvz"],"x3d+xml":["x3d","x3dz"],"x3d+binary":["x3db","x3dbz"],"vnd.collada+xml":"dae","vnd.dwf":"dwf","vnd.gdl":"gdl","vnd.gtw":"gtw","vnd.mts":"mts","vnd.vtu":"vtu"},text:{"cache-manifest":["manifest","appcache"],calendar:["ics","icz","ifb"],css:"css",csv:"csv",h323:"323",html:["html","htm","shtml","stm"],iuls:"uls",mathml:"mml",plain:["txt","text","brf","conf","def","list","log","in","bas"],richtext:"rtx",scriptlet:["sct","wsc"],texmacs:["tm","ts"],"tab-separated-values":"tsv","vnd.sun.j2me.app-descriptor":"jad","vnd.wap.wml":"wml","vnd.wap.wmlscript":"wmls","x-bibtex":"bib","x-boo":"boo","x-c++hdr":["h++","hpp","hxx","hh"],"x-c++src":["c++","cpp","cxx","cc"],"x-component":"htc","x-dsrc":"d","x-diff":["diff","patch"],"x-haskell":"hs","x-java":"java","x-literate-haskell":"lhs","x-moc":"moc","x-pascal":["p","pas"],"x-pcs-gcd":"gcd","x-perl":["pl","pm"],"x-python":"py","x-scala":"scala","x-setext":"etx","x-tcl":["tcl","tk"],"x-tex":["tex","ltx","sty","cls"],"x-vcalendar":"vcs","x-vcard":"vcf",n3:"n3","prs.lines.tag":"dsc",sgml:["sgml","sgm"],troff:["t","tr","roff","man","me","ms"],turtle:"ttl","uri-list":["uri","uris","urls"],vcard:"vcard","vnd.curl":"curl","vnd.curl.dcurl":"dcurl","vnd.curl.scurl":"scurl","vnd.curl.mcurl":"mcurl","vnd.dvb.subtitle":"sub","vnd.fly":"fly","vnd.fmi.flexstor":"flx","vnd.graphviz":"gv","vnd.in3d.3dml":"3dml","vnd.in3d.spot":"spot","x-asm":["s","asm"],"x-c":["c","cc","cxx","cpp","h","hh","dic"],"x-fortran":["f","for","f77","f90"],"x-opml":"opml","x-nfo":"nfo","x-sfv":"sfv","x-uuencode":"uu",webviewhtml:"htt"},video:{avif:".avif","3gpp":"3gp",annodex:"axv",dl:"dl",dv:["dif","dv"],fli:"fli",gl:"gl",mpeg:["mpeg","mpg","mpe","m1v","m2v","mp2","mpa","mpv2"],mp4:["mp4","mp4v","mpg4"],quicktime:["qt","mov"],ogg:"ogv","vnd.mpegurl":["mxu","m4u"],"x-flv":"flv","x-la-asf":["lsf","lsx"],"x-mng":"mng","x-ms-asf":["asf","asx","asr"],"x-ms-wm":"wm","x-ms-wmv":"wmv","x-ms-wmx":"wmx","x-ms-wvx":"wvx","x-msvideo":"avi","x-sgi-movie":"movie","x-matroska":["mpv","mkv","mk3d","mks"],"3gpp2":"3g2",h261:"h261",h263:"h263",h264:"h264",jpeg:"jpgv",jpm:["jpm","jpgm"],mj2:["mj2","mjp2"],"vnd.dece.hd":["uvh","uvvh"],"vnd.dece.mobile":["uvm","uvvm"],"vnd.dece.pd":["uvp","uvvp"],"vnd.dece.sd":["uvs","uvvs"],"vnd.dece.video":["uvv","uvvv"],"vnd.dvb.file":"dvb","vnd.fvt":"fvt","vnd.ms-playready.media.pyv":"pyv","vnd.uvvu.mp4":["uvu","uvvu"],"vnd.vivo":"viv",webm:"webm","x-f4v":"f4v","x-m4v":"m4v","x-ms-vob":"vob","x-smv":"smv"},"x-conference":{"x-cooltalk":"ice"},"x-world":{"x-vrml":["vrm","vrml","wrl","flr","wrz","xaf","xof"]}},dt=(()=>{const e={};for(let t in ot)if(ot.hasOwnProperty(t))for(let n in ot[t])if(ot[t].hasOwnProperty(n)){const s=ot[t][n];if("string"==typeof s)e[s]=t+"/"+n;else for(let i=0;i({ZipDeflate:Ze(e.Deflate,t.deflate),ZipInflate:Ze(e.Inflate,t.inflate)}),Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/dist/zip-fs.js b/dist/zip-fs.js index b10c7dd2..ab3e1b20 100644 --- a/dist/zip-fs.js +++ b/dist/zip-fs.js @@ -392,6 +392,7 @@ const EXTRA_FIELD_TYPE_ZIP64 = 0x0001; const EXTRA_FIELD_TYPE_AES = 0x9901; const EXTRA_FIELD_TYPE_UNICODE_PATH = 0x7075; + const EXTRA_FIELD_TYPE_UNICODE_COMMENT = 0x6375; const BITFLAG_ENCRYPTED = 0x01; const BITFLAG_LEVEL = 0x06; @@ -882,8 +883,11 @@ function createWorkerCodec(config, options) { const pool = workers.pool; + const streamCopy = + !options.inputCompressed && !options.inputSigned && !options.inputEncrypted && + !options.outputCompressed && !options.outputSigned && !options.outputEncrypted; let scripts; - if (config.useWebWorkers) { + if (options.useWebWorkers || (options.useWebWorkers === undefined && config.useWebWorkers && !streamCopy)) { const codecType = options.codecType; if (config.workerScripts != null && config.workerScriptsPath != null) { throw new Error("Either workerScripts or workerScriptsPath may be set, not both"); @@ -900,22 +904,26 @@ } } if (pool.length < config.maxWorkers) { - const workerData = { worker: scripts && new Worker(scripts[0]), busy: true, options, scripts }; + const workerData = { busy: true, options, scripts }; pool.push(workerData); return scripts ? createWebWorkerInterface(workerData) : createWorkerInterface(workerData); } else { - const availableWorkerData = pool.find(workerData => !workerData.busy); - if (availableWorkerData) { - availableWorkerData.busy = true; - availableWorkerData.options = options; - availableWorkerData.scripts = scripts; - return scripts ? availableWorkerData.interface : createWorkerInterface(availableWorkerData); + const workerData = pool.find(workerData => !workerData.busy); + if (workerData) { + return getWorkerInterface(workerData); } else { return new Promise(resolve => workers.pendingRequests.push({ resolve, options, scripts })); } } } + function getWorkerInterface(workerData, options, scripts) { + workerData.busy = true; + workerData.options = options; + workerData.scripts = scripts; + return scripts ? createWebWorkerInterface(workerData) : createWorkerInterface(workerData); + } + function createWorkerInterface(workerData) { const interfaceCodec = createCodec(workerData.options); const append = interfaceCodec.append.bind(interfaceCodec); @@ -924,7 +932,7 @@ try { return await append(data); } catch (error) { - await onWorkerTaskFinished(workerData); + onTaskFinished(workerData); throw error; } }; @@ -932,36 +940,26 @@ try { return await flush(); } finally { - await onWorkerTaskFinished(workerData); + onTaskFinished(workerData); } }; return interfaceCodec; } - async function onWorkerTaskFinished(workerData) { - workerData.busy = false; - if (workers.pendingRequests.length) { - const [{ resolve, options }] = workers.pendingRequests.splice(0, 1); - workerData.busy = true; - workerData.options = options; - resolve(createWorkerInterface(workerData)); - } else { - workers.pool = workers.pool.filter(data => data != workerData); - } - } - function createWebWorkerInterface(workerData) { - const worker = workerData.worker; let task; - worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false); - workerData.interface = { - async append(data) { - return initAndSendMessage({ type: MESSAGE_APPEND, data }); - }, - async flush() { - return initAndSendMessage({ type: MESSAGE_FLUSH }); - } - }; + if (!workerData.interface) { + workerData.worker = new Worker(workerData.scripts[0]); + workerData.worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false); + workerData.interface = { + append(data) { + return initAndSendMessage({ type: MESSAGE_APPEND, data }); + }, + flush() { + return initAndSendMessage({ type: MESSAGE_FLUSH }); + } + }; + } return workerData.interface; async function initAndSendMessage(message) { @@ -973,6 +971,8 @@ } function sendMessage(message) { + const worker = workerData.worker; + const result = new Promise((resolve, reject) => task = { resolve, reject }); try { if (message.data) { try { @@ -986,9 +986,9 @@ } catch (error) { task.reject(error); task = null; - onWebWorkerTaskFinished(workerData); + onTaskFinished(workerData); } - return new Promise((resolve, reject) => task = { resolve, reject }); + return result; } function onMessage(event) { @@ -1000,12 +1000,12 @@ error.stack = reponseError.stack; task.reject(error); task = null; - onWebWorkerTaskFinished(workerData); + onTaskFinished(workerData); } else if (message.type == MESSAGE_INIT || message.type == MESSAGE_FLUSH || message.type == MESSAGE_APPEND) { if (message.type == MESSAGE_FLUSH) { task.resolve({ data: new Uint8Array(message.data), signature: message.signature }); task = null; - onWebWorkerTaskFinished(workerData); + onTaskFinished(workerData); } else { task.resolve(message.data && new Uint8Array(message.data)); } @@ -1014,16 +1014,15 @@ } } - function onWebWorkerTaskFinished(workerData) { + function onTaskFinished(workerData) { workerData.busy = false; if (workers.pendingRequests.length) { const [{ resolve, options, scripts }] = workers.pendingRequests.splice(0, 1); - workerData.busy = true; - workerData.options = options; - workerData.scripts = scripts; - resolve(workerData.interface); + resolve(getWorkerInterface(workerData, options, scripts)); } else { - workerData.worker.terminate(); + if (workerData.worker) { + workerData.worker.terminate(); + } workers.pool = workers.pool.filter(data => data != workerData); } } @@ -1150,52 +1149,56 @@ if (!reader.initialized) { await reader.init(); } - const directoryInfo = await seekSignature(reader, END_OF_CENTRAL_DIR_SIGNATURE, END_OF_CENTRAL_DIR_LENGTH, MAX_16_BITS); - let zip64, directoryDataView = new DataView(directoryInfo.buffer); - let directoryDataLength = directoryDataView.getUint32(16, true); - let filesLength = directoryDataView.getUint16(8, true); - if (directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS) { + const endOfDirectoryInfo = await seekSignature(reader, END_OF_CENTRAL_DIR_SIGNATURE, END_OF_CENTRAL_DIR_LENGTH, MAX_16_BITS); + if (!endOfDirectoryInfo) { + throw new Error(ERR_EOCDR_NOT_FOUND); + } + const endOfDirectoryView = new DataView(endOfDirectoryInfo.buffer); + let zip64; + let directoryDataOffset = endOfDirectoryView.getUint32(16, true); + let filesLength = endOfDirectoryView.getUint16(8, true); + if (directoryDataOffset == MAX_32_BITS || filesLength == MAX_16_BITS) { zip64 = true; - const directoryLocatorArray = await reader.readUint8Array(directoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH); - const directoryLocatorView = new DataView(directoryLocatorArray.buffer); - if (Number(directoryLocatorView.getUint32(0, false)) != ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) { + const endOfDirectoryLocatorArray = await reader.readUint8Array(endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH); + const endOfDirectoryLocatorView = new DataView(endOfDirectoryLocatorArray.buffer); + if (Number(endOfDirectoryLocatorView.getUint32(0, false)) != ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) { throw new Error(ERR_EOCDR_ZIP64_NOT_FOUND); } - directoryDataLength = Number(directoryLocatorView.getBigUint64(8, true)); - const directoryDataArray = await reader.readUint8Array(directoryDataLength, ZIP64_END_OF_CENTRAL_DIR_LENGTH); - const directoryDataView = new DataView(directoryDataArray.buffer); - if (Number(directoryDataView.getUint32(0, false)) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) { + directoryDataOffset = Number(endOfDirectoryLocatorView.getBigUint64(8, true)); + const endOfDirectoryArray = await reader.readUint8Array(directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH); + const endOfDirectoryView = new DataView(endOfDirectoryArray.buffer); + if (Number(endOfDirectoryView.getUint32(0, false)) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) { throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND); } - filesLength = Number(directoryDataView.getBigUint64(24, true)); - directoryDataLength -= Number(directoryDataView.getBigUint64(40, true)); + filesLength = Number(endOfDirectoryView.getBigUint64(24, true)); + directoryDataOffset -= Number(endOfDirectoryView.getBigUint64(40, true)); } - if (directoryDataLength < 0 || (!zip64 && (directoryDataLength >= reader.size || filesLength >= MAX_16_BITS))) { + if (directoryDataOffset < 0 || (!zip64 && (directoryDataOffset >= reader.size || filesLength >= MAX_16_BITS))) { throw new Error(ERR_BAD_FORMAT); } - const directoryDataArray = await reader.readUint8Array(directoryDataLength, reader.size - directoryDataLength); - directoryDataView = new DataView(directoryDataArray.buffer); + const directoryArray = await reader.readUint8Array(directoryDataOffset, reader.size - directoryDataOffset); + const directoryView = new DataView(directoryArray.buffer); const entries = []; let offset = 0; for (let indexFile = 0; indexFile < filesLength; indexFile++) { const fileEntry = new Entry(this.reader, this.config, this.options); - if (directoryDataView.getUint32(offset, false) != CENTRAL_FILE_HEADER_SIGNATURE) { + if (directoryView.getUint32(offset, false) != CENTRAL_FILE_HEADER_SIGNATURE) { throw new Error(ERR_CENTRAL_DIRECTORY_NOT_FOUND); } fileEntry.compressedSize = 0; fileEntry.uncompressedSize = 0; - readCommonHeader(fileEntry, directoryDataView, offset + 6); - fileEntry.commentLength = directoryDataView.getUint16(offset + 32, true); - fileEntry.directory = ((directoryDataView.getUint8(offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK); - fileEntry.offset = directoryDataView.getUint32(offset + 42, true); - fileEntry.rawFilename = directoryDataArray.subarray(offset + 46, offset + 46 + fileEntry.filenameLength); + readCommonHeader(fileEntry, directoryView, offset + 6); + fileEntry.commentLength = directoryView.getUint16(offset + 32, true); + fileEntry.directory = ((directoryView.getUint8(offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK); + fileEntry.offset = directoryView.getUint32(offset + 42, true); + fileEntry.rawFilename = directoryArray.subarray(offset + 46, offset + 46 + fileEntry.filenameLength); fileEntry.filename = decodeString(fileEntry.rawFilename, fileEntry.bitFlag.languageEncodingFlag ? CHARSET_UTF8 : this.options.filenameEncoding || CHARSET_WIN_1252); if (!fileEntry.directory && fileEntry.filename && fileEntry.filename.charAt(fileEntry.filename.length - 1) == DIRECTORY_SIGNATURE) { fileEntry.directory = true; } - fileEntry.rawExtraField = directoryDataArray.subarray(offset + 46 + fileEntry.filenameLength, offset + 46 + fileEntry.filenameLength + fileEntry.extraFieldLength); - readCommonFooter(fileEntry, fileEntry, directoryDataView, offset + 6); - fileEntry.rawComment = directoryDataArray.subarray(offset + 46 + fileEntry.filenameLength + fileEntry.extraFieldLength, offset + 46 + fileEntry.rawExtraField = directoryArray.subarray(offset + 46 + fileEntry.filenameLength, offset + 46 + fileEntry.filenameLength + fileEntry.extraFieldLength); + readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6); + fileEntry.rawComment = directoryArray.subarray(offset + 46 + fileEntry.filenameLength + fileEntry.extraFieldLength, offset + 46 + fileEntry.filenameLength + fileEntry.extraFieldLength + fileEntry.commentLength); fileEntry.comment = decodeString(fileEntry.rawComment, fileEntry.bitFlag.languageEncodingFlag ? CHARSET_UTF8 : this.options.commentEncoding || CHARSET_WIN_1252); entries.push(fileEntry); @@ -1254,7 +1257,8 @@ inputSigned: options.checkSignature === undefined ? this.options.checkSignature : options.checkSignature, inputSignature: this.signature, inputCompressed: this.compressionMethod != 0, - inputEncrypted + inputEncrypted, + useWebWorkers: options.useWebWorkers === undefined ? this.options.useWebWorkers : options.useWebWorkers }); if (!writer.initialized) { await writer.init(); @@ -1281,7 +1285,6 @@ } function readCommonFooter(fileEntry, directory, dataView, offset) { - let extraFieldZip64, extraFieldAES, extraFieldUnicodePath; const rawExtraField = directory.rawExtraField; const extraField = directory.extraField = new Map(); const rawExtraFieldView = new DataView(new Uint8Array(rawExtraField).buffer); @@ -1303,15 +1306,19 @@ directory.signature = dataView.getUint32(offset + 10, true); directory.uncompressedSize = dataView.getUint32(offset + 18, true); directory.compressedSize = dataView.getUint32(offset + 14, true); - extraFieldZip64 = directory.extraFieldZip64 = extraField.get(EXTRA_FIELD_TYPE_ZIP64); + const extraFieldZip64 = directory.extraFieldZip64 = extraField.get(EXTRA_FIELD_TYPE_ZIP64); if (extraFieldZip64) { readExtraFieldZip64(extraFieldZip64, directory); } - extraFieldUnicodePath = directory.extraFieldUnicodePath = extraField.get(EXTRA_FIELD_TYPE_UNICODE_PATH); + const extraFieldUnicodePath = directory.extraFieldUnicodePath = extraField.get(EXTRA_FIELD_TYPE_UNICODE_PATH); if (extraFieldUnicodePath) { - readExtraFieldUnicodePath(extraFieldUnicodePath, directory, fileEntry); + readExtraFieldUnicode(extraFieldUnicodePath, "filename", "rawFilename", directory, fileEntry); + } + let extraFieldUnicodeComment = directory.extraFieldUnicodeComment = extraField.get(EXTRA_FIELD_TYPE_UNICODE_COMMENT); + if (extraFieldUnicodeComment) { + readExtraFieldUnicode(extraFieldUnicodeComment, "comment", "rawComment", directory, fileEntry); } - extraFieldAES = directory.extraFieldAES = extraField.get(EXTRA_FIELD_TYPE_AES); + const extraFieldAES = directory.extraFieldAES = extraField.get(EXTRA_FIELD_TYPE_AES); if (extraFieldAES) { readExtraFieldAES(extraFieldAES, directory, compressionMethod); } else { @@ -1344,17 +1351,17 @@ }); } - function readExtraFieldUnicodePath(extraFieldUnicodePath, directory, fileEntry) { - const extraFieldView = new DataView(extraFieldUnicodePath.data.buffer); - extraFieldUnicodePath.version = extraFieldView.getUint8(0); - extraFieldUnicodePath.signature = extraFieldView.getUint32(1, true); + function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName, directory, fileEntry) { + const extraFieldView = new DataView(extraFieldUnicode.data.buffer); + extraFieldUnicode.version = extraFieldView.getUint8(0); + extraFieldUnicode.signature = extraFieldView.getUint32(1, true); const crc32 = new Crc32(); - crc32.append(fileEntry.rawFilename); + crc32.append(fileEntry[rawPropertyName]); const dataViewSignature = new DataView(new Uint8Array(4).buffer); dataViewSignature.setUint32(0, crc32.get()); - extraFieldUnicodePath.filename = (new TextDecoder()).decode(extraFieldUnicodePath.data.subarray(5)); - if (extraFieldUnicodePath.signature == dataViewSignature.getUint32(0, false)) { - directory.filename = extraFieldUnicodePath.filename; + extraFieldUnicode[propertyName] = (new TextDecoder()).decode(extraFieldUnicode.data.subarray(5)); + if (extraFieldUnicode.signature == dataViewSignature.getUint32(0, false)) { + directory[propertyName] = extraFieldUnicode[propertyName]; } } @@ -1385,9 +1392,6 @@ if (!dataInfo) { dataInfo = await seek(Math.min(maximumBytes, reader.size)); } - if (!dataInfo) { - throw new Error(ERR_EOCDR_NOT_FOUND); - } return dataInfo; async function seek(length) { @@ -1489,7 +1493,7 @@ let offset = 0, directoryDataLength = 0, directoryOffset = this.offset, filesLength = files.size; if (comment && comment.length) { if (comment.length <= MAX_16_BITS) { - directoryDataView.setUint16(offset + 20, comment.length, true); + directoryView.setUint16(offset + 20, comment.length, true); } else { throw new Error(ERR_INVALID_COMMENT); } @@ -1500,62 +1504,62 @@ if (directoryOffset + directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) { this.zip64 = true; } - const directoryDataArray = new Uint8Array(directoryDataLength + (this.zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH)); - const directoryDataView = new DataView(directoryDataArray.buffer); + const directoryArray = new Uint8Array(directoryDataLength + (this.zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH)); + const directoryView = new DataView(directoryArray.buffer); this.options.version = this.options.version || VERSION_DEFLATE; for (const [, fileEntry] of files) { const filename = fileEntry.filename; const extraFieldZip64 = fileEntry.extraFieldZip64; const extraFieldAES = fileEntry.extraFieldAES; const extraFieldLength = extraFieldZip64.length + extraFieldAES.length + fileEntry.rawExtraField.length; - directoryDataView.setUint32(offset, CENTRAL_FILE_HEADER_SIGNATURE); + directoryView.setUint32(offset, CENTRAL_FILE_HEADER_SIGNATURE); if (fileEntry.zip64) { - directoryDataView.setUint16(offset + 4, this.options.version > VERSION_ZIP64 ? this.options : VERSION_ZIP64, true); + directoryView.setUint16(offset + 4, this.options.version > VERSION_ZIP64 ? this.options : VERSION_ZIP64, true); } if (fileEntry.encrypted) { - directoryDataView.setUint16(offset + 4, this.options.version > VERSION_AES ? this.options : VERSION_AES, true); + directoryView.setUint16(offset + 4, this.options.version > VERSION_AES ? this.options : VERSION_AES, true); } else { - directoryDataView.setUint16(offset + 4, this.options.version > VERSION_DEFLATE ? this.options : VERSION_DEFLATE, true); + directoryView.setUint16(offset + 4, this.options.version > VERSION_DEFLATE ? this.options : VERSION_DEFLATE, true); } - directoryDataArray.set(fileEntry.headerArray, offset + 6); - directoryDataView.setUint16(offset + 30, extraFieldLength, true); - directoryDataView.setUint16(offset + 32, fileEntry.comment.length, true); + directoryArray.set(fileEntry.headerArray, offset + 6); + directoryView.setUint16(offset + 30, extraFieldLength, true); + directoryView.setUint16(offset + 32, fileEntry.comment.length, true); if (fileEntry.directory) { - directoryDataView.setUint8(offset + 38, FILE_ATTR_MSDOS_DIR_MASK); + directoryView.setUint8(offset + 38, FILE_ATTR_MSDOS_DIR_MASK); } if (fileEntry.zip64) { - directoryDataView.setUint32(offset + 42, MAX_32_BITS, true); + directoryView.setUint32(offset + 42, MAX_32_BITS, true); } else { - directoryDataView.setUint32(offset + 42, fileEntry.offset, true); + directoryView.setUint32(offset + 42, fileEntry.offset, true); } - directoryDataArray.set(filename, offset + 46); - directoryDataArray.set(extraFieldZip64, offset + 46 + filename.length); - directoryDataArray.set(extraFieldAES, offset + 46 + filename.length + extraFieldZip64.length); - directoryDataArray.set(fileEntry.rawExtraField, 46 + filename.length + extraFieldZip64.length + extraFieldAES.length); - directoryDataArray.set(fileEntry.comment, offset + 46 + filename.length + extraFieldLength); + directoryArray.set(filename, offset + 46); + directoryArray.set(extraFieldZip64, offset + 46 + filename.length); + directoryArray.set(extraFieldAES, offset + 46 + filename.length + extraFieldZip64.length); + directoryArray.set(fileEntry.rawExtraField, 46 + filename.length + extraFieldZip64.length + extraFieldAES.length); + directoryArray.set(fileEntry.comment, offset + 46 + filename.length + extraFieldLength); offset += 46 + filename.length + extraFieldLength + fileEntry.comment.length; } if (this.zip64) { - directoryDataView.setUint32(offset, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE); - directoryDataView.setBigUint64(offset + 4, BigInt(44), true); - directoryDataView.setUint16(offset + 12, 45, true); - directoryDataView.setUint16(offset + 14, 45, true); - directoryDataView.setBigUint64(offset + 24, BigInt(filesLength), true); - directoryDataView.setBigUint64(offset + 32, BigInt(filesLength), true); - directoryDataView.setBigUint64(offset + 40, BigInt(directoryDataLength), true); - directoryDataView.setBigUint64(offset + 48, BigInt(directoryOffset), true); - directoryDataView.setUint32(offset + 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE); - directoryDataView.setBigUint64(offset + 64, BigInt(directoryOffset + directoryDataLength), true); - directoryDataView.setUint32(offset + 72, 1, true); + directoryView.setUint32(offset, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE); + directoryView.setBigUint64(offset + 4, BigInt(44), true); + directoryView.setUint16(offset + 12, 45, true); + directoryView.setUint16(offset + 14, 45, true); + directoryView.setBigUint64(offset + 24, BigInt(filesLength), true); + directoryView.setBigUint64(offset + 32, BigInt(filesLength), true); + directoryView.setBigUint64(offset + 40, BigInt(directoryDataLength), true); + directoryView.setBigUint64(offset + 48, BigInt(directoryOffset), true); + directoryView.setUint32(offset + 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE); + directoryView.setBigUint64(offset + 64, BigInt(directoryOffset + directoryDataLength), true); + directoryView.setUint32(offset + 72, 1, true); filesLength = MAX_16_BITS; directoryOffset = MAX_32_BITS; offset += 76; } - directoryDataView.setUint32(offset, END_OF_CENTRAL_DIR_SIGNATURE); - directoryDataView.setUint16(offset + 8, filesLength, true); - directoryDataView.setUint16(offset + 10, filesLength, true); - directoryDataView.setUint32(offset + 12, directoryDataLength, true); - directoryDataView.setUint32(offset + 16, directoryOffset, true); - await writer.writeUint8Array(directoryDataArray); + directoryView.setUint32(offset, END_OF_CENTRAL_DIR_SIGNATURE); + directoryView.setUint16(offset + 8, filesLength, true); + directoryView.setUint16(offset + 10, filesLength, true); + directoryView.setUint32(offset + 12, directoryDataLength, true); + directoryView.setUint32(offset + 16, directoryOffset, true); + await writer.writeUint8Array(directoryArray); if (comment && comment.length) { await writer.writeUint8Array(comment); } @@ -1570,7 +1574,7 @@ try { let fileWriter, fileEntry; try { - if ((options.bufferedWrite || zipWriter.options.bufferedWrite) || zipWriter.lockWrite) { + if (options.bufferedWrite || zipWriter.options.bufferedWrite || zipWriter.lockWrite) { fileWriter = new Uint8ArrayWriter(); fileWriter.init(); } else { @@ -1660,7 +1664,7 @@ offset += 4 + data.length; }); } - options.bitFlag = BITFLAG_DATA_DESCRIPTOR; + options.bitFlag = BITFLAG_DATA_DESCRIPTOR | BITFLAG_LANG_ENCODING_FLAG; options.version = (options.version === undefined ? zipWriterOptions.version : options.version) || VERSION_DEFLATE; if (options.version > MAX_16_BITS) { throw new Error(ERR_INVALID_VERSION); @@ -1704,7 +1708,8 @@ outputPassword: password, outputSigned, outputCompressed: compressed, - outputEncrypted: Boolean(password) + outputEncrypted: Boolean(password), + useWebWorkers: options.useWebWorkers === undefined ? zipWriterOptions.useWebWorkers : options.useWebWorkers }); await writer.writeUint8Array(fileDataArray); result = await processData(codec, reader, writer, 0, reader.size, config, { onprogress: options.onprogress }); diff --git a/dist/zip-fs.min.js b/dist/zip-fs.min.js index a403c0b3..dc776126 100644 --- a/dist/zip-fs.min.js +++ b/dist/zip-fs.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).zip={})}(this,(function(t){"use strict";const e="HTTP error ",n="HTTP Range not supported",i="text/plain";class r{constructor(){this.size=0}init(){this.initialized=!0}}class s extends r{}class a extends r{writeUint8Array(t){this.size+=t.length}}class o extends s{constructor(t){super(),this.blobReader=new l(new Blob([t],{type:i}))}init(){super.init(),this.blobReader.init(),this.size=this.blobReader.size}readUint8Array(t,e){return this.blobReader.readUint8Array(t,e)}}class c extends a{constructor(t){super(),this.encoding=t,this.blob=new Blob([],{type:i})}writeUint8Array(t){super.writeUint8Array(t),this.blob=new Blob([this.blob,t.buffer],{type:i})}getData(){const t=new FileReader;return new Promise(((e,n)=>{t.onload=t=>e(t.target.result),t.onerror=n,t.readAsText(this.blob,this.encoding)}))}}class h extends s{constructor(t){super(),this.dataURI=t;let e=t.length;for(;"="==t.charAt(e-1);)e--;this.dataStart=t.indexOf(",")+1,this.size=Math.floor(.75*(e-this.dataStart))}readUint8Array(t,e){const n=new Uint8Array(e),i=4*Math.floor(t/3),r=atob(this.dataURI.substring(i+this.dataStart,4*Math.ceil((t+e)/3)+this.dataStart)),s=t-3*Math.floor(i/4);for(let t=s;t2?this.data+=btoa(n):this.pending=n}getData(){return this.data+btoa(this.pending)}}class l extends s{constructor(t){super(),this.blob=t,this.size=t.size}readUint8Array(t,e){const n=new FileReader;return new Promise(((i,r)=>{n.onload=t=>i(new Uint8Array(t.target.result)),n.onerror=r,n.readAsArrayBuffer(this.blob.slice(t,t+e))}))}}class p extends a{constructor(t){super(),this.offset=0,this.contentType=t,this.blob=new Blob([],{type:t})}writeUint8Array(t){super.writeUint8Array(t),this.blob=new Blob([this.blob,t.buffer],{type:this.contentType}),this.offset=this.blob.size}getData(){return this.blob}}class u extends s{constructor(t){super(),this.url=t}async init(){if(super.init(),function(t){if("undefined"!=typeof document){const e=document.createElement("a");return e.href=t,"http:"==e.protocol||"https:"==e.protocol}return/^https?:\/\//i.test(t)}(this.url))return new Promise(((t,n)=>{const i=new XMLHttpRequest;i.addEventListener("load",(()=>{i.status<400?(this.size=Number(i.getResponseHeader("Content-Length")),this.size?t():w().then((()=>t())).catch(n)):n(e+(i.statusText||i.status)+".")}),!1),i.addEventListener("error",n,!1),i.open("HEAD",this.url),i.send()}));await w()}async readUint8Array(t,e){return this.data||await w(this,this.url),new Uint8Array(this.data.subarray(t,t+e))}}class g extends s{constructor(t){super(),this.url=t}init(){return super.init(),new Promise(((t,i)=>{const r=new XMLHttpRequest;r.addEventListener("load",(()=>{r.status<400?(this.size=Number(r.getResponseHeader("Content-Length")),"bytes"==r.getResponseHeader("Accept-Ranges")?t():i(new Error(n))):i(e+(r.statusText||r.status)+".")}),!1),r.addEventListener("error",i,!1),r.open("HEAD",this.url),r.send()}))}readUint8Array(t,n){return new Promise(((i,r)=>{const s=new XMLHttpRequest;s.open("GET",this.url),s.responseType="arraybuffer",s.setRequestHeader("Range","bytes="+t+"-"+(t+n-1)),s.addEventListener("load",(()=>{s.status<400?i(new Uint8Array(s.response)):r(e+(s.statusText||s.status)+".")}),!1),s.addEventListener("error",r,!1),s.send()}))}}class f extends a{constructor(){super(),this.array=new Uint8Array(0)}writeUint8Array(t){super.writeUint8Array(t);const e=this.array;this.array=new Uint8Array(e.length+t.length),this.array.set(e),this.array.set(t,e.length)}getData(){return this.array}}function w(t,n){return new Promise(((i,r)=>{const s=new XMLHttpRequest;s.addEventListener("load",(()=>{s.status<400?(t.size||(t.size=Number(s.getResponseHeader("Content-Length"))||Number(s.response.byteLength)),t.data=new Uint8Array(s.response),i()):r(e+(s.statusText||s.status)+".")}),!1),s.addEventListener("error",r,!1),s.open("GET",n),s.responseType="arraybuffer",s.send()}))}const y=4294967295,U=65535,m=1347093252,b=1347094280,E=1347092738,A=1347093766,R=1347094022,D=1347094023,x=39169,z=45,F=51;class I{constructor(){this.crc=-1,this.table=(()=>{const t=[];for(let e=0;e<256;e++){let n=e;for(let t=0;t<8;t++)1&n?n=n>>>1^3988292384:n>>>=1;t[e]=n}return t})()}append(t){const e=this.table;let n=0|this.crc;for(let i=0,r=0|t.length;i>>8^e[255&(n^t[i])];this.crc=n}get(){return~this.crc}}const v="Invalid pasword",S=16,B="raw",T={name:"PBKDF2"},L={name:"HMAC"},_="SHA-1",N={name:"AES-CTR"},M=Object.assign({hash:L},T),O=Object.assign({iterations:1e3,hash:{name:_}},T),C=Object.assign({hash:_},L),P=Object.assign({length:S},N),k=["deriveBits"],V=["sign"],W=528,Z=10,H=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],j=crypto.subtle;class q{constructor(t,e){this.password=t,this.signed=e,this.input=e&&new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(t){const e=async(r=0)=>{if(r+S<=i.length-Z){const t=i.subarray(r,r+S),s=await j.decrypt(Object.assign({counter:this.counter},P),this.keys.decrypt,t);return X(this.counter),n.set(new Uint8Array(s),r),e(r+S)}return this.pendingInput=i.subarray(r),this.signed&&(this.input=Y(this.input,t)),n};if(this.password){const e=t.subarray(0,18);await async function(t,e,n){t.counter=new Uint8Array(H);const i=e.subarray(0,16),r=e.subarray(16),s=(new TextEncoder).encode(n),a=await j.importKey(B,s,M,!1,k),o=await j.deriveBits(Object.assign({salt:i},O),a,528),c=new Uint8Array(o),h=c.subarray(64);if(t.keys={decrypt:await j.importKey(B,c.subarray(0,32),N,!0,["decrypt"]),authentication:await j.importKey(B,c.subarray(32,64),C,!1,V),passwordVerification:h},h[0]!=r[0]||h[1]!=r[1])throw new Error(v)}(this,e,this.password),this.password=null,t=t.subarray(18)}let n=new Uint8Array(t.length-Z-(t.length-Z)%S),i=t;return this.pendingInput.length&&(i=Y(this.pendingInput,t),n=G(n,i.length-Z-(i.length-Z)%S)),e()}async flush(){const t=this.pendingInput,e=this.keys,n=t.subarray(0,t.length-Z),i=t.subarray(t.length-Z);let r=new Uint8Array(0);if(n.length){const t=await j.decrypt(Object.assign({counter:this.counter},P),e.decrypt,n);r=new Uint8Array(t)}let s=!0;if(this.signed){const t=await j.sign(L,e.authentication,this.input.subarray(0,this.input.length-Z)),n=new Uint8Array(t);this.input=null;for(let t=0;t{if(r+S<=t.length){const s=t.subarray(r,r+S),a=await j.encrypt(Object.assign({counter:this.counter},P),this.keys.encrypt,s);return X(this.counter),i.set(new Uint8Array(a),r+n.length),e(r+S)}return this.pendingInput=t.subarray(r),this.output=Y(this.output,i),i};let n=new Uint8Array(0);this.password&&(n=await async function(t,e){t.counter=new Uint8Array(H);const n=crypto.getRandomValues(new Uint8Array(16)),i=(new TextEncoder).encode(e),r=await j.importKey(B,i,M,!1,k),s=await j.deriveBits(Object.assign({salt:n},O),r,W),a=new Uint8Array(s);return t.keys={encrypt:await j.importKey(B,a.subarray(0,32),N,!0,["encrypt"]),authentication:await j.importKey(B,a.subarray(32,64),C,!1,V),passwordVerification:a.subarray(64)},Y(n,t.keys.passwordVerification)}(this,this.password),this.password=null);let i=new Uint8Array(n.length+t.length-t.length%S);return i.set(n,0),this.pendingInput.length&&(t=Y(this.pendingInput,t),i=G(i,t.length-t.length%S)),e()}async flush(){let t=new Uint8Array(0);if(this.pendingInput.length){const e=await j.encrypt(Object.assign({counter:this.counter},P),this.keys.encrypt,this.pendingInput);t=new Uint8Array(e),this.output=Y(this.output,t)}const e=await j.sign(L,this.keys.authentication,this.output.subarray(18));this.output=null;const n=new Uint8Array(e).subarray(0,Z);return{data:Y(t,n),signature:n}}}function X(t){for(let e=0;e<16;e++){if(255!=t[e]){t[e]++;break}t[e]=0}}function Y(t,e){let n=t;return t.length+e.length&&(n=new Uint8Array(t.length+e.length),n.set(t,0),n.set(e,t.length)),n}function G(t,e){if(e&&e>t.length){const n=t;(t=new Uint8Array(e)).set(n,0)}return t}const J="deflate",Q="inflate",$="Invalid signature";class tt{constructor(t){this.signature=t.inputSignature,this.encrypted=Boolean(t.inputPassword),this.signed=t.inputSigned,this.compressed=t.inputCompressed,this.inflate=this.compressed&&new ZipInflate,this.crc32=this.signed&&this.signed&&new I,this.decrypt=this.encrypted&&new q(t.inputPassword)}async append(t){return this.encrypted&&(t=await this.decrypt.append(t)),this.compressed&&t.length&&(t=await this.inflate.append(t)),!this.encrypted&&this.signed&&this.crc32.append(t),t}async flush(){let t,e=new Uint8Array(0);if(this.encrypted){const t=await this.decrypt.flush();if(!t.valid)throw new Error($);e=t.data}else if(this.signed){const e=new DataView(new Uint8Array(4).buffer);if(t=this.crc32.get(),e.setUint32(0,t),this.signature!=e.getUint32(0,!1))throw new Error($)}return this.compressed&&(e=await this.inflate.append(e)||new Uint8Array(0),await this.inflate.flush()),{data:e,signature:t}}}class et{constructor(t){this.encrypted=t.outputEncrypted,this.signed=t.outputSigned,this.compressed=t.outputCompressed,this.deflate=this.compressed&&new ZipDeflate({level:t.level||5}),this.crc32=this.signed&&new I,this.encrypt=this.encrypted&&new K(t.outputPassword)}async append(t){let e=t;return this.compressed&&t.length&&(e=await this.deflate.append(t)),this.encrypted?e=await this.encrypt.append(e):this.signed&&this.crc32.append(t),e}async flush(){let t,e=new Uint8Array(0);if(this.compressed&&(e=await this.deflate.flush()||new Uint8Array(0)),this.encrypted){e=await this.encrypt.append(e);const n=await this.encrypt.flush();t=n.signature;const i=new Uint8Array(e.length+n.data.length);i.set(e,0),i.set(n.data,e.length),e=i}else this.signed&&(t=this.crc32.get());return{data:e,signature:t}}}const nt="init",it="append",rt="flush",st="message",at="z-worker.js",ot={deflate:[at,"deflate.js"],inflate:[at,"inflate.js"]},ct={pool:[],pendingRequests:[]};function ht(t,e){const n=ct.pool;let i;if(t.useWebWorkers){const n=e.codecType;if(null!=t.workerScripts&&null!=t.workerScriptsPath)throw new Error("Either workerScripts or workerScriptsPath may be set, not both");if(t.workerScripts){if(i=t.workerScripts[n],!Array.isArray(i))throw new Error("workerScripts."+n+" must be an array");r=i,i="undefined"!=typeof document?r.map((t=>new URL(t,document.baseURI).href)):r}else i=ot[n].slice(0),i[0]=(t.workerScriptsPath||"")+i[0]}var r;if(n.lengthi({type:it,data:t}),flush:async()=>i({type:rt})},t.interface;async function i(e){if(!n){const e=t.scripts.slice(1);await r(Object.assign({type:nt,options:t.options,scripts:e}))}return r(e)}function r(i){try{if(i.data)try{e.postMessage(i,[i.data.buffer])}catch(t){e.postMessage(i)}else e.postMessage(i)}catch(e){n.reject(e),n=null,pt(t)}return new Promise(((t,e)=>n={resolve:t,reject:e}))}function s(e){const i=e.data;if(n){const e=i.error;if(e){const i=new Error(e.message);i.stack=e.stack,n.reject(i),n=null,pt(t)}else i.type!=nt&&i.type!=rt&&i.type!=it||(i.type==rt?(n.resolve({data:new Uint8Array(i.data),signature:i.signature}),n=null,pt(t)):n.resolve(i.data&&new Uint8Array(i.data)))}}}(t):dt(t)}{const t=n.find((t=>!t.busy));return t?(t.busy=!0,t.options=e,t.scripts=i,i?t.interface:dt(t)):new Promise((t=>ct.pendingRequests.push({resolve:t,options:e,scripts:i})))}}function dt(t){const e=(n=t.options).codecType.startsWith(J)?new et(n):n.codecType.startsWith(Q)?new tt(n):void 0;var n;const i=e.append.bind(e),r=e.flush.bind(e);return e.append=async e=>{try{return await i(e)}catch(e){throw await lt(t),e}},e.flush=async()=>{try{return await r()}finally{await lt(t)}},e}async function lt(t){if(t.busy=!1,ct.pendingRequests.length){const[{resolve:e,options:n}]=ct.pendingRequests.splice(0,1);t.busy=!0,t.options=n,e(dt(t))}else ct.pool=ct.pool.filter((e=>e!=t))}function pt(t){if(t.busy=!1,ct.pendingRequests.length){const[{resolve:e,options:n,scripts:i}]=ct.pendingRequests.splice(0,1);t.busy=!0,t.options=n,t.scripts=i,e(t.interface)}else t.worker.terminate(),ct.pool=ct.pool.filter((e=>e!=t))}async function ut(t,e,n,i,r,s,a){const o=Math.max(s.chunkSize,64);return async function s(c=0,h=0){const d=c*o;if(d>1,dataDescriptor:8==(8&i),languageEncodingFlag:2048==(2048&i)},t.encrypted=t.bitFlag.encrypted,t.rawLastModDate=e.getUint32(n+6,!0),t.lastModDate=function(t){const e=(4294901760&t)>>16,n=65535&t;try{return new Date(1980+((65024&e)>>9),((480&e)>>5)-1,31&e,(63488&n)>>11,(2016&n)>>5,2*(31&n),0)}catch(t){}}(t.rawLastModDate),t.filenameLength=e.getUint16(n+22,!0),t.extraFieldLength=e.getUint16(n+24,!0)}function St(t,e,n,i){let r,s,a;const o=e.rawExtraField,c=e.extraField=new Map,h=new DataView(new Uint8Array(o).buffer);let d=0;try{for(;de[t]==y));for(let e=0;e{if(e[n]==y){if(!t||void 0===t[n])throw new Error(Et);e[n]=t&&t[n]}}))}(r,e),a=e.extraFieldUnicodePath=c.get(28789),a&&function(t,e,n){const i=new DataView(t.data.buffer);t.version=i.getUint8(0),t.signature=i.getUint32(1,!0);const r=new I;r.append(n.rawFilename);const s=new DataView(new Uint8Array(4).buffer);s.setUint32(0,r.get()),t.filename=(new TextDecoder).decode(t.data.subarray(5)),t.signature==s.getUint32(0,!1)&&(e.filename=t.filename)}(a,e,t),s=e.extraFieldAES=c.get(39169),s?function(t,e,n){if(t){const i=new DataView(t.data.buffer);t.vendorVersion=i.getUint8(0),t.vendorId=i.getUint8(2);const r=i.getUint8(4);t.strength=r,t.originalCompressionMethod=n,e.compressionMethod=t.compressionMethod=i.getUint16(5,!0)}else e.compressionMethod=n}(s,e,l):e.compressionMethod=l,8==e.compressionMethod&&(e.bitFlag.enhancedDeflating=16!=(16&e.rawBitFlag))}function Bt(t,e){return new TextDecoder(e).decode(t)}const Tt="File already exists",Lt="Zip file comment exceeds 64KB",_t="File entry comment exceeds 64KB",Nt="File entry name exceeds 64KB",Mt="Version exceeds 65535",Ot="Extra field type exceeds 65535",Ct="Extra field data exceeds 64KB",Pt=new Uint8Array([7,0,2,0,65,69,3,0,0]);function kt(t){return unescape(encodeURIComponent(t))}function Vt(t){const e=[];for(let n=0;n{if(this.pendingData){const e=this.pendingData;this.pendingData=new Uint8Array(e.length+t.length),this.pendingData.set(e,0),this.pendingData.set(t,e.length)}else this.pendingData=new Uint8Array(t)};if(this.codec=new t(Object.assign({},e,n)),typeof this.codec.onData==Wt)this.codec.onData=i;else{if(typeof this.codec.on!=Wt)throw new Error("Cannot register the callback function");this.codec.on("data",i)}}async append(t){return this.codec.push(t),n(this)}async flush(){return this.codec.push(new Uint8Array(0),!0),n(this)}};function n(t){if(t.pendingData){const e=t.pendingData;return t.pendingData=null,e}return new Uint8Array(0)}}const Ht={chunkSize:524288,maxWorkers:"undefined"!=typeof navigator&&navigator.hardwareConcurrency||2,workerScriptsPath:void 0,useWebWorkers:!0};let jt=Object.assign({},Ht);class qt extends class{constructor(t,e={},n={}){this.reader=t,this.options=e,this.config=n}async getEntries(){const t=this.reader;t.initialized||await t.init();const e=await async function(t,e,n,i){const r=new Uint8Array(4);if(new DataView(r.buffer).setUint32(0,e),t.size=0;t--)if(s[t]==r[0]&&s[t+1]==r[1]&&s[t+2]==r[2]&&s[t+3]==r[3])return{offset:i,buffer:s.slice(t,t+n).buffer}}}(t,A,22,U);let n,i=new DataView(e.buffer),r=i.getUint32(16,!0),s=i.getUint16(8,!0);if(r==y||s==U){n=!0;const i=await t.readUint8Array(e.offset-20,20),a=new DataView(i.buffer);if(Number(a.getUint32(0,!1))!=D)throw new Error(yt);r=Number(a.getBigUint64(8,!0));const o=await t.readUint8Array(r,56),c=new DataView(o.buffer);if(Number(c.getUint32(0,!1))!=R)throw new Error(Ut);s=Number(c.getBigUint64(24,!0)),r-=Number(c.getBigUint64(40,!0))}if(r<0||!n&&(r>=t.size||s>=U))throw new Error(ft);const a=await t.readUint8Array(r,t.size-r);i=new DataView(a.buffer);const o=[];let c=0;for(let t=0;tU)throw new Error(_t);n.zip64=n.zip64||this.zip64,await async function(t,e,n,i){const r=t.files,s=t.writer;let a;r.set(e,null);try{let o,c;try{i.bufferedWrite||t.options.bufferedWrite||t.lockWrite?(o=new f,o.init()):(t.lockWrite=new Promise((t=>a=t)),s.initialized||await s.init(),o=s),(t.offset>=y||n&&(n.size>=y||t.offset+n.size>=y))&&(i.zip64=!0),c=await async function(t,e,n,i,r,s){const a=Vt(kt(t)),o=s.lastModDate||new Date,c=new Uint8Array(26),h=new DataView(c.buffer),d=void 0===s.password?r.password:s.password,l=d&&d.length&&d,p=void 0===s.level?r.level:s.level,u=0!==p&&!s.directory,g=void 0===d||!d.length,f=s.zip64;let w;if(l){w=new Uint8Array(Pt.length+2);new DataView(w.buffer).setUint16(0,x,!0),w.set(Pt,2)}else w=new Uint8Array(0);const E={zip64:f,headerArray:c,directory:s.directory,filename:a,comment:s.comment,extraFieldZip64:f?new Uint8Array(28):new Uint8Array(0),extraFieldAES:w,rawExtraField:new Uint8Array(0)},A=s.extraField;if(a.length>U)throw new Error(Nt);if(A){let t=4,e=0;A.forEach((e=>t+=e.length));const n=E.rawExtraField=new Uint8Array(t);A.forEach(((t,i)=>{if(i>U)throw new Error(Ot);if(t.length>U)throw new Error(Ct);n.set(new Uint16Array([i]),e),n.set(new Uint16Array([t.length]),e+2),n.set(t,e+4),e+=4+t.length}))}if(s.bitFlag=8,s.version=(void 0===s.version?r.version:s.version)||20,s.version>U)throw new Error(Mt);s.compressionMethod=0,u&&(s.compressionMethod=8);f&&(s.version=s.version>z?s.version:z);l&&(E.encrypted=!0,s.version=s.version>F?s.version:F,s.bitFlag=1|s.bitFlag,s.compressionMethod=99,u&&(E.extraFieldAES[9]=8));h.setUint16(0,s.version,!0),h.setUint16(2,s.bitFlag,!0),h.setUint16(4,s.compressionMethod,!0),h.setUint16(6,(o.getHours()<<6|o.getMinutes())<<5|o.getSeconds()/2,!0),h.setUint16(8,(o.getFullYear()-1980<<4|o.getMonth()+1)<<5|o.getDate(),!0),h.setUint16(22,a.length,!0),h.setUint16(24,0,!0);const R=new Uint8Array(30+a.length);let D;if(new DataView(R.buffer).setUint32(0,m),R.set(c,4),R.set(a,30),e){e.initialized||await e.init();const t=await ht(i,{codecType:J,level:p,outputPassword:d,outputSigned:g,outputCompressed:u,outputEncrypted:Boolean(d)});await n.writeUint8Array(R),D=await ut(t,e,n,0,e.size,i,{onprogress:s.onprogress}),E.compressedSize=D.length}else await n.writeUint8Array(R);const I=new Uint8Array(f?24:16),v=new DataView(I.buffer);if(v.setUint32(0,b),e)if(l||void 0===D.signature||(h.setUint32(10,D.signature,!0),v.setUint32(4,D.signature,!0)),f){h.setUint32(14,y,!0),v.setBigUint64(8,BigInt(E.compressedSize),!0),h.setUint32(18,y,!0),v.setBigUint64(16,BigInt(e.size),!0);const t=new DataView(E.extraFieldZip64.buffer);t.setUint16(0,1,!0),t.setUint16(2,24,!0),t.setBigUint64(4,BigInt(e.size),!0),t.setBigUint64(12,BigInt(E.compressedSize),!0)}else h.setUint32(14,E.compressedSize,!0),v.setUint32(8,E.compressedSize,!0),h.setUint32(18,e.size,!0),v.setUint32(12,e.size,!0);return await n.writeUint8Array(I),E.length=R.length+(D?D.length:0)+I.length,E}(e,n,o,t.config,t.options,i)}catch(t){throw r.delete(e),t}if(r.set(e,c),o!=s&&(t.lockWrite&&await t.lockWrite,await s.writeUint8Array(o.getData())),c.offset=t.offset,c.zip64){new DataView(c.extraFieldZip64.buffer).setBigUint64(20,BigInt(c.offset),!0)}t.offset+=c.length}finally{a&&(t.lockWrite=null,a())}}(this,t,e,n)}async close(t){const e=this.writer,n=this.files;let i=0,r=0,s=this.offset,a=n.size;if(t&&t.length){if(!(t.length<=U))throw new Error(Lt);c.setUint16(i+20,t.length,!0)}for(const[,t]of n)r+=46+t.filename.length+t.comment.length+t.extraFieldZip64.length+t.extraFieldAES.length+t.rawExtraField.length;(s+r>=y||a>=U)&&(this.zip64=!0);const o=new Uint8Array(r+(this.zip64?98:22)),c=new DataView(o.buffer);this.options.version=this.options.version||20;for(const[,t]of n){const e=t.filename,n=t.extraFieldZip64,r=t.extraFieldAES,s=n.length+r.length+t.rawExtraField.length;c.setUint32(i,E),t.zip64&&c.setUint16(i+4,this.options.version>z?this.options:z,!0),t.encrypted?c.setUint16(i+4,this.options.version>F?this.options:F,!0):c.setUint16(i+4,this.options.version>20?this.options:20,!0),o.set(t.headerArray,i+6),c.setUint16(i+30,s,!0),c.setUint16(i+32,t.comment.length,!0),t.directory&&c.setUint8(i+38,16),t.zip64?c.setUint32(i+42,y,!0):c.setUint32(i+42,t.offset,!0),o.set(e,i+46),o.set(n,i+46+e.length),o.set(r,i+46+e.length+n.length),o.set(t.rawExtraField,46+e.length+n.length+r.length),o.set(t.comment,i+46+e.length+s),i+=46+e.length+s+t.comment.length}return this.zip64&&(c.setUint32(i,R),c.setBigUint64(i+4,BigInt(44),!0),c.setUint16(i+12,45,!0),c.setUint16(i+14,45,!0),c.setBigUint64(i+24,BigInt(a),!0),c.setBigUint64(i+32,BigInt(a),!0),c.setBigUint64(i+40,BigInt(r),!0),c.setBigUint64(i+48,BigInt(s),!0),c.setUint32(i+56,D),c.setBigUint64(i+64,BigInt(s+r),!0),c.setUint32(i+72,1,!0),a=U,s=y,i+=76),c.setUint32(i,A),c.setUint16(i+8,a,!0),c.setUint16(i+10,a,!0),c.setUint32(i+12,r,!0),c.setUint32(i+16,s,!0),await e.writeUint8Array(o),t&&t.length&&await e.writeUint8Array(t),e.getData()}}{constructor(t,e){super(t,e,jt)}}const Xt=524288;class Yt{constructor(t,e,n,i){if(t.root&&i&&i.getChildByName(e))throw new Error("Entry filename already exists");n||(n={}),this.fs=t,this.name=e,this.id=t.entries.length,this.parent=i,this.children=[],this.zipVersion=n.zipVersion||20,this.uncompressedSize=0,t.entries.push(this),i&&this.parent.children.push(this)}moveTo(t){if(!t.directory)throw new Error("Target entry is not a directory");if(t.isDescendantOf(this))throw new Error("Entry is a ancestor of target entry");if(this!=t){if(t.getChildByName(this.name))throw new Error("Entry filename already exists");ne(this),this.parent=t,t.children.push(this)}}getFullname(){let t=this.name,e=this.parent;for(;e;)t=(e.name?e.name+"/":"")+t,e=e.parent;return t}isDescendantOf(t){let e=this.parent;for(;e&&e.id!=t.id;)e=e.parent;return Boolean(e)}}class Gt extends Yt{constructor(t,e,n,i){super(t,e,n,i),this.Reader=n.Reader,this.Writer=n.Writer,this.data=n.data,n.getData&&(this.getData=n.getData)}async getData(t,e={}){return!t||t.constructor==this.Writer&&this.data?this.data:(this.reader||(this.reader=new this.Reader(this.data)),await this.reader.init(),await t.init(),this.uncompressedSize=this.reader.size,async function(t,e,n){return i();async function i(r=0){const s=r*Xt;if(n.onprogress&&n.onprogress(s,t.size),s{e.file((i=>{t.addBlob(e.name,i),n()}),i)}));function n(t){return new Promise(((e,n)=>{let i=[];function r(t){t.readEntries((n=>{n.length?(i=i.concat(n),r(t)):e(i)}),n)}t.isDirectory&&r(t.createReader()),t.isFile&&e(i)}))}async function i(t,e){const r=await n(e);for(const e of r)e.isDirectory&&await i(t.addDirectory(e.name)),await new Promise(((n,i)=>{e.isFile&&e.file((i=>{const r=t.addBlob(e.name,i);r.uncompressedSize=i.size,n(r)}),i)}))}}(this,t)}async addData(t,e){return re(this,t,e)}async importBlob(t,e={}){await this.importZip(new l(t),e)}async importData64URI(t,e={}){await this.importZip(new h(t),e)}async importHttpContent(t,e={}){await this.importZip(e.useRangeHeader?new g(t):new u(t),e)}async exportBlob(t={}){return this.exportZip(new p("application/zip"),t)}async exportData64URI(t={}){return this.exportZip(new d("application/zip"),t)}async importZip(t,e){await t.init();const n=new qt(t),i=await n.getEntries();let r=0;const s=$t(i,"compressedSize");i.forEach((t=>{let n=this,i=t.filename.split("/"),a=i.pop();if(i.forEach((t=>n=n.getChildByName(t)||new Jt(this.fs,t,null,n))),!t.directory){let i=r;re(n,a,{data:t,Reader:te(Object.assign({},e,{onprogress:t=>{e.onprogress&&e.onprogress(i+t,s)}}))}),r+=t.compressedSize}}))}async exportZip(t,e){await ee(this);const n=new Kt(t);return await async function(t,e,n,i){let r=0;async function s(t,e){async function a(){let a=0;for(const o of e.children){let e=r;await t.add(o.getFullname(),o.reader,Object.assign({directory:o.directory,version:o.zipVersion},i,{onprogress:t=>{i.onprogress&&i.onprogress(e+a+t,n)}})),r+=o.uncompressedSize,await s(t,o),a++}}await a()}await s(t,e)}(n,this,$t([this],"uncompressedSize"),e),await n.close(),t.getData()}getChildByName(t){for(let e=0;e{n.id==t.id&&e.splice(i,1)}))}function ie(t){t.entries=[],t.root=new Jt(t)}function re(t,e,n,i){if(t.directory)return i?new Jt(t.fs,e,n,t):new Gt(t.fs,e,n,t);throw new Error("Parent entry is not a directory")}t.BlobReader=l,t.BlobWriter=p,t.Data64URIReader=h,t.Data64URIWriter=d,t.ERR_BAD_FORMAT=ft,t.ERR_CENTRAL_DIRECTORY_NOT_FOUND=mt,t.ERR_DUPLICATED_NAME=Tt,t.ERR_ENCRYPTED=At,t.ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND=Ut,t.ERR_EOCDR_NOT_FOUND=wt,t.ERR_EOCDR_ZIP64_NOT_FOUND=yt,t.ERR_EXTRAFIELD_ZIP64_NOT_FOUND=Et,t.ERR_HTTP_RANGE=n,t.ERR_INVALID_COMMENT=Lt,t.ERR_INVALID_ENTRY_COMMENT=_t,t.ERR_INVALID_ENTRY_NAME=Nt,t.ERR_INVALID_EXTRAFIELD_DATA=Ct,t.ERR_INVALID_EXTRAFIELD_TYPE=Ot,t.ERR_INVALID_PASSORD=v,t.ERR_INVALID_SIGNATURE=$,t.ERR_INVALID_VERSION=Mt,t.ERR_LOCAL_FILE_HEADER_NOT_FOUND=bt,t.ERR_UNSUPPORTED_COMPRESSION=Dt,t.ERR_UNSUPPORTED_ENCRYPTION=Rt,t.HttpRangeReader=g,t.HttpReader=u,t.Reader=s,t.TextReader=o,t.TextWriter=c,t.Uint8ArrayReader=class extends s{constructor(t){super(),this.array=t,this.size=t.length}readUint8Array(t,e){return this.array.slice(t,t+e)}},t.Uint8ArrayWriter=f,t.Writer=a,t.ZipReader=qt,t.ZipWriter=Kt,t.configure=function(t){jt=Object.assign({},jt,t)},t.fs=Qt,t.getMimeType=function(){return"application/octet-stream"},t.initShimAsyncCodec=(t,e={})=>({ZipDeflate:Zt(t.Deflate,e.deflate),ZipInflate:Zt(t.Inflate,e.inflate)}),Object.defineProperty(t,"__esModule",{value:!0})})); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).zip={})}(this,(function(t){"use strict";const e="HTTP error ",n="HTTP Range not supported",r="text/plain";class i{constructor(){this.size=0}init(){this.initialized=!0}}class s extends i{}class a extends i{writeUint8Array(t){this.size+=t.length}}class o extends s{constructor(t){super(),this.blobReader=new l(new Blob([t],{type:r}))}init(){super.init(),this.blobReader.init(),this.size=this.blobReader.size}readUint8Array(t,e){return this.blobReader.readUint8Array(t,e)}}class c extends a{constructor(t){super(),this.encoding=t,this.blob=new Blob([],{type:r})}writeUint8Array(t){super.writeUint8Array(t),this.blob=new Blob([this.blob,t.buffer],{type:r})}getData(){const t=new FileReader;return new Promise(((e,n)=>{t.onload=t=>e(t.target.result),t.onerror=n,t.readAsText(this.blob,this.encoding)}))}}class h extends s{constructor(t){super(),this.dataURI=t;let e=t.length;for(;"="==t.charAt(e-1);)e--;this.dataStart=t.indexOf(",")+1,this.size=Math.floor(.75*(e-this.dataStart))}readUint8Array(t,e){const n=new Uint8Array(e),r=4*Math.floor(t/3),i=atob(this.dataURI.substring(r+this.dataStart,4*Math.ceil((t+e)/3)+this.dataStart)),s=t-3*Math.floor(r/4);for(let t=s;t2?this.data+=btoa(n):this.pending=n}getData(){return this.data+btoa(this.pending)}}class l extends s{constructor(t){super(),this.blob=t,this.size=t.size}readUint8Array(t,e){const n=new FileReader;return new Promise(((r,i)=>{n.onload=t=>r(new Uint8Array(t.target.result)),n.onerror=i,n.readAsArrayBuffer(this.blob.slice(t,t+e))}))}}class u extends a{constructor(t){super(),this.offset=0,this.contentType=t,this.blob=new Blob([],{type:t})}writeUint8Array(t){super.writeUint8Array(t),this.blob=new Blob([this.blob,t.buffer],{type:this.contentType}),this.offset=this.blob.size}getData(){return this.blob}}class p extends s{constructor(t){super(),this.url=t}async init(){if(super.init(),function(t){if("undefined"!=typeof document){const e=document.createElement("a");return e.href=t,"http:"==e.protocol||"https:"==e.protocol}return/^https?:\/\//i.test(t)}(this.url))return new Promise(((t,n)=>{const r=new XMLHttpRequest;r.addEventListener("load",(()=>{r.status<400?(this.size=Number(r.getResponseHeader("Content-Length")),this.size?t():w().then((()=>t())).catch(n)):n(e+(r.statusText||r.status)+".")}),!1),r.addEventListener("error",n,!1),r.open("HEAD",this.url),r.send()}));await w()}async readUint8Array(t,e){return this.data||await w(this,this.url),new Uint8Array(this.data.subarray(t,t+e))}}class g extends s{constructor(t){super(),this.url=t}init(){return super.init(),new Promise(((t,r)=>{const i=new XMLHttpRequest;i.addEventListener("load",(()=>{i.status<400?(this.size=Number(i.getResponseHeader("Content-Length")),"bytes"==i.getResponseHeader("Accept-Ranges")?t():r(new Error(n))):r(e+(i.statusText||i.status)+".")}),!1),i.addEventListener("error",r,!1),i.open("HEAD",this.url),i.send()}))}readUint8Array(t,n){return new Promise(((r,i)=>{const s=new XMLHttpRequest;s.open("GET",this.url),s.responseType="arraybuffer",s.setRequestHeader("Range","bytes="+t+"-"+(t+n-1)),s.addEventListener("load",(()=>{s.status<400?r(new Uint8Array(s.response)):i(e+(s.statusText||s.status)+".")}),!1),s.addEventListener("error",i,!1),s.send()}))}}class f extends a{constructor(){super(),this.array=new Uint8Array(0)}writeUint8Array(t){super.writeUint8Array(t);const e=this.array;this.array=new Uint8Array(e.length+t.length),this.array.set(e),this.array.set(t,e.length)}getData(){return this.array}}function w(t,n){return new Promise(((r,i)=>{const s=new XMLHttpRequest;s.addEventListener("load",(()=>{s.status<400?(t.size||(t.size=Number(s.getResponseHeader("Content-Length"))||Number(s.response.byteLength)),t.data=new Uint8Array(s.response),r()):i(e+(s.statusText||s.status)+".")}),!1),s.addEventListener("error",i,!1),s.open("GET",n),s.responseType="arraybuffer",s.send()}))}const y=4294967295,m=65535,U=1347093252,b=1347094280,E=1347092738,A=1347093766,R=1347094022,D=1347094023,x=39169,z=2048,F=45,v=51;class I{constructor(){this.crc=-1,this.table=(()=>{const t=[];for(let e=0;e<256;e++){let n=e;for(let t=0;t<8;t++)1&n?n=n>>>1^3988292384:n>>>=1;t[e]=n}return t})()}append(t){const e=this.table;let n=0|this.crc;for(let r=0,i=0|t.length;r>>8^e[255&(n^t[r])];this.crc=n}get(){return~this.crc}}const S="Invalid pasword",B=16,T="raw",L={name:"PBKDF2"},_={name:"HMAC"},k="SHA-1",C={name:"AES-CTR"},N=Object.assign({hash:_},L),M=Object.assign({iterations:1e3,hash:{name:k}},L),O=Object.assign({hash:k},_),W=Object.assign({length:B},C),P=["deriveBits"],V=["sign"],Z=528,H=10,j=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],K=crypto.subtle;class q{constructor(t,e){this.password=t,this.signed=e,this.input=e&&new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(t){const e=async(i=0)=>{if(i+B<=r.length-H){const t=r.subarray(i,i+B),s=await K.decrypt(Object.assign({counter:this.counter},W),this.keys.decrypt,t);return Y(this.counter),n.set(new Uint8Array(s),i),e(i+B)}return this.pendingInput=r.subarray(i),this.signed&&(this.input=G(this.input,t)),n};if(this.password){const e=t.subarray(0,18);await async function(t,e,n){t.counter=new Uint8Array(j);const r=e.subarray(0,16),i=e.subarray(16),s=(new TextEncoder).encode(n),a=await K.importKey(T,s,N,!1,P),o=await K.deriveBits(Object.assign({salt:r},M),a,528),c=new Uint8Array(o),h=c.subarray(64);if(t.keys={decrypt:await K.importKey(T,c.subarray(0,32),C,!0,["decrypt"]),authentication:await K.importKey(T,c.subarray(32,64),O,!1,V),passwordVerification:h},h[0]!=i[0]||h[1]!=i[1])throw new Error(S)}(this,e,this.password),this.password=null,t=t.subarray(18)}let n=new Uint8Array(t.length-H-(t.length-H)%B),r=t;return this.pendingInput.length&&(r=G(this.pendingInput,t),n=J(n,r.length-H-(r.length-H)%B)),e()}async flush(){const t=this.pendingInput,e=this.keys,n=t.subarray(0,t.length-H),r=t.subarray(t.length-H);let i=new Uint8Array(0);if(n.length){const t=await K.decrypt(Object.assign({counter:this.counter},W),e.decrypt,n);i=new Uint8Array(t)}let s=!0;if(this.signed){const t=await K.sign(_,e.authentication,this.input.subarray(0,this.input.length-H)),n=new Uint8Array(t);this.input=null;for(let t=0;t{if(i+B<=t.length){const s=t.subarray(i,i+B),a=await K.encrypt(Object.assign({counter:this.counter},W),this.keys.encrypt,s);return Y(this.counter),r.set(new Uint8Array(a),i+n.length),e(i+B)}return this.pendingInput=t.subarray(i),this.output=G(this.output,r),r};let n=new Uint8Array(0);this.password&&(n=await async function(t,e){t.counter=new Uint8Array(j);const n=crypto.getRandomValues(new Uint8Array(16)),r=(new TextEncoder).encode(e),i=await K.importKey(T,r,N,!1,P),s=await K.deriveBits(Object.assign({salt:n},M),i,Z),a=new Uint8Array(s);return t.keys={encrypt:await K.importKey(T,a.subarray(0,32),C,!0,["encrypt"]),authentication:await K.importKey(T,a.subarray(32,64),O,!1,V),passwordVerification:a.subarray(64)},G(n,t.keys.passwordVerification)}(this,this.password),this.password=null);let r=new Uint8Array(n.length+t.length-t.length%B);return r.set(n,0),this.pendingInput.length&&(t=G(this.pendingInput,t),r=J(r,t.length-t.length%B)),e()}async flush(){let t=new Uint8Array(0);if(this.pendingInput.length){const e=await K.encrypt(Object.assign({counter:this.counter},W),this.keys.encrypt,this.pendingInput);t=new Uint8Array(e),this.output=G(this.output,t)}const e=await K.sign(_,this.keys.authentication,this.output.subarray(18));this.output=null;const n=new Uint8Array(e).subarray(0,H);return{data:G(t,n),signature:n}}}function Y(t){for(let e=0;e<16;e++){if(255!=t[e]){t[e]++;break}t[e]=0}}function G(t,e){let n=t;return t.length+e.length&&(n=new Uint8Array(t.length+e.length),n.set(t,0),n.set(e,t.length)),n}function J(t,e){if(e&&e>t.length){const n=t;(t=new Uint8Array(e)).set(n,0)}return t}const Q="deflate",$="inflate",tt="Invalid signature";class et{constructor(t){this.signature=t.inputSignature,this.encrypted=Boolean(t.inputPassword),this.signed=t.inputSigned,this.compressed=t.inputCompressed,this.inflate=this.compressed&&new ZipInflate,this.crc32=this.signed&&this.signed&&new I,this.decrypt=this.encrypted&&new q(t.inputPassword)}async append(t){return this.encrypted&&(t=await this.decrypt.append(t)),this.compressed&&t.length&&(t=await this.inflate.append(t)),!this.encrypted&&this.signed&&this.crc32.append(t),t}async flush(){let t,e=new Uint8Array(0);if(this.encrypted){const t=await this.decrypt.flush();if(!t.valid)throw new Error(tt);e=t.data}else if(this.signed){const e=new DataView(new Uint8Array(4).buffer);if(t=this.crc32.get(),e.setUint32(0,t),this.signature!=e.getUint32(0,!1))throw new Error(tt)}return this.compressed&&(e=await this.inflate.append(e)||new Uint8Array(0),await this.inflate.flush()),{data:e,signature:t}}}class nt{constructor(t){this.encrypted=t.outputEncrypted,this.signed=t.outputSigned,this.compressed=t.outputCompressed,this.deflate=this.compressed&&new ZipDeflate({level:t.level||5}),this.crc32=this.signed&&new I,this.encrypt=this.encrypted&&new X(t.outputPassword)}async append(t){let e=t;return this.compressed&&t.length&&(e=await this.deflate.append(t)),this.encrypted?e=await this.encrypt.append(e):this.signed&&this.crc32.append(t),e}async flush(){let t,e=new Uint8Array(0);if(this.compressed&&(e=await this.deflate.flush()||new Uint8Array(0)),this.encrypted){e=await this.encrypt.append(e);const n=await this.encrypt.flush();t=n.signature;const r=new Uint8Array(e.length+n.data.length);r.set(e,0),r.set(n.data,e.length),e=r}else this.signed&&(t=this.crc32.get());return{data:e,signature:t}}}const rt="init",it="append",st="flush",at="z-worker.js",ot={deflate:[at,"deflate.js"],inflate:[at,"inflate.js"]},ct={pool:[],pendingRequests:[]};function ht(t,e){const n=ct.pool,r=!(e.inputCompressed||e.inputSigned||e.inputEncrypted||e.outputCompressed||e.outputSigned||e.outputEncrypted);let i;if(e.useWebWorkers||void 0===e.useWebWorkers&&t.useWebWorkers&&!r){const n=e.codecType;if(null!=t.workerScripts&&null!=t.workerScriptsPath)throw new Error("Either workerScripts or workerScriptsPath may be set, not both");if(t.workerScripts){if(i=t.workerScripts[n],!Array.isArray(i))throw new Error("workerScripts."+n+" must be an array");s=i,i="undefined"!=typeof document?s.map((t=>new URL(t,document.baseURI).href)):s}else i=ot[n].slice(0),i[0]=(t.workerScriptsPath||"")+i[0]}var s;if(n.length!t.busy));return t?dt(t):new Promise((t=>ct.pendingRequests.push({resolve:t,options:e,scripts:i})))}}function dt(t,e,n){return t.busy=!0,t.options=e,t.scripts=n,n?ut(t):lt(t)}function lt(t){const e=(n=t.options).codecType.startsWith(Q)?new nt(n):n.codecType.startsWith($)?new et(n):void 0;var n;const r=e.append.bind(e),i=e.flush.bind(e);return e.append=async e=>{try{return await r(e)}catch(e){throw pt(t),e}},e.flush=async()=>{try{return await i()}finally{pt(t)}},e}function ut(t){let e;return t.interface||(t.worker=new Worker(t.scripts[0]),t.worker.addEventListener("message",(function(n){const r=n.data;if(e){const n=r.error;if(n){const r=new Error(n.message);r.stack=n.stack,e.reject(r),e=null,pt(t)}else r.type!=rt&&r.type!=st&&r.type!=it||(r.type==st?(e.resolve({data:new Uint8Array(r.data),signature:r.signature}),e=null,pt(t)):e.resolve(r.data&&new Uint8Array(r.data)))}}),!1),t.interface={append:t=>n({type:it,data:t}),flush:()=>n({type:st})}),t.interface;async function n(n){if(!e){const e=t.scripts.slice(1);await r(Object.assign({type:rt,options:t.options,scripts:e}))}return r(n)}function r(n){const r=t.worker,i=new Promise(((t,n)=>e={resolve:t,reject:n}));try{if(n.data)try{r.postMessage(n,[n.data.buffer])}catch(t){r.postMessage(n)}else r.postMessage(n)}catch(n){e.reject(n),e=null,pt(t)}return i}}function pt(t){if(t.busy=!1,ct.pendingRequests.length){const[{resolve:e,options:n,scripts:r}]=ct.pendingRequests.splice(0,1);e(dt(t,n,r))}else t.worker&&t.worker.terminate(),ct.pool=ct.pool.filter((e=>e!=t))}async function gt(t,e,n,r,i,s,a){const o=Math.max(s.chunkSize,64);return async function s(c=0,h=0){const d=c*o;if(d>1,dataDescriptor:8==(8&r),languageEncodingFlag:(r&z)==z},t.encrypted=t.bitFlag.encrypted,t.rawLastModDate=e.getUint32(n+6,!0),t.lastModDate=function(t){const e=(4294901760&t)>>16,n=65535&t;try{return new Date(1980+((65024&e)>>9),((480&e)>>5)-1,31&e,(63488&n)>>11,(2016&n)>>5,2*(31&n),0)}catch(t){}}(t.rawLastModDate),t.filenameLength=e.getUint16(n+22,!0),t.extraFieldLength=e.getUint16(n+24,!0)}function Bt(t,e,n,r){const i=e.rawExtraField,s=e.extraField=new Map,a=new DataView(new Uint8Array(i).buffer);let o=0;try{for(;oe[t]==y));for(let e=0;e{if(e[n]==y){if(!t||void 0===t[n])throw new Error(At);e[n]=t&&t[n]}}))}(h,e);const d=e.extraFieldUnicodePath=s.get(28789);d&&Tt(d,"filename","rawFilename",e,t);let l=e.extraFieldUnicodeComment=s.get(25461);l&&Tt(l,"comment","rawComment",e,t);const u=e.extraFieldAES=s.get(39169);u?function(t,e,n){if(t){const r=new DataView(t.data.buffer);t.vendorVersion=r.getUint8(0),t.vendorId=r.getUint8(2);const i=r.getUint8(4);t.strength=i,t.originalCompressionMethod=n,e.compressionMethod=t.compressionMethod=r.getUint16(5,!0)}else e.compressionMethod=n}(u,e,c):e.compressionMethod=c,8==e.compressionMethod&&(e.bitFlag.enhancedDeflating=16!=(16&e.rawBitFlag))}function Tt(t,e,n,r,i){const s=new DataView(t.data.buffer);t.version=s.getUint8(0),t.signature=s.getUint32(1,!0);const a=new I;a.append(i[n]);const o=new DataView(new Uint8Array(4).buffer);o.setUint32(0,a.get()),t[e]=(new TextDecoder).decode(t.data.subarray(5)),t.signature==o.getUint32(0,!1)&&(r[e]=t[e])}function Lt(t,e){return new TextDecoder(e).decode(t)}const _t="File already exists",kt="Zip file comment exceeds 64KB",Ct="File entry comment exceeds 64KB",Nt="File entry name exceeds 64KB",Mt="Version exceeds 65535",Ot="Extra field type exceeds 65535",Wt="Extra field data exceeds 64KB",Pt=new Uint8Array([7,0,2,0,65,69,3,0,0]);function Vt(t){return unescape(encodeURIComponent(t))}function Zt(t){const e=[];for(let n=0;n{if(this.pendingData){const e=this.pendingData;this.pendingData=new Uint8Array(e.length+t.length),this.pendingData.set(e,0),this.pendingData.set(t,e.length)}else this.pendingData=new Uint8Array(t)};if(this.codec=new t(Object.assign({},e,n)),typeof this.codec.onData==Ht)this.codec.onData=r;else{if(typeof this.codec.on!=Ht)throw new Error("Cannot register the callback function");this.codec.on("data",r)}}async append(t){return this.codec.push(t),n(this)}async flush(){return this.codec.push(new Uint8Array(0),!0),n(this)}};function n(t){if(t.pendingData){const e=t.pendingData;return t.pendingData=null,e}return new Uint8Array(0)}}const Kt={chunkSize:524288,maxWorkers:"undefined"!=typeof navigator&&navigator.hardwareConcurrency||2,workerScriptsPath:void 0,useWebWorkers:!0};let qt=Object.assign({},Kt);class Xt extends class{constructor(t,e={},n={}){this.reader=t,this.options=e,this.config=n}async getEntries(){const t=this.reader;t.initialized||await t.init();const e=await async function(t,e,n,r){const i=new Uint8Array(4);if(new DataView(i.buffer).setUint32(0,e),t.size=0;t--)if(s[t]==i[0]&&s[t+1]==i[1]&&s[t+2]==i[2]&&s[t+3]==i[3])return{offset:r,buffer:s.slice(t,t+n).buffer}}}(t,A,22,m);if(!e)throw new Error(yt);const n=new DataView(e.buffer);let r,i=n.getUint32(16,!0),s=n.getUint16(8,!0);if(i==y||s==m){r=!0;const n=await t.readUint8Array(e.offset-20,20),a=new DataView(n.buffer);if(Number(a.getUint32(0,!1))!=D)throw new Error(mt);i=Number(a.getBigUint64(8,!0));const o=await t.readUint8Array(i,56),c=new DataView(o.buffer);if(Number(c.getUint32(0,!1))!=R)throw new Error(Ut);s=Number(c.getBigUint64(24,!0)),i-=Number(c.getBigUint64(40,!0))}if(i<0||!r&&(i>=t.size||s>=m))throw new Error(wt);const a=await t.readUint8Array(i,t.size-i),o=new DataView(a.buffer),c=[];let h=0;for(let t=0;tm)throw new Error(Ct);n.zip64=n.zip64||this.zip64,await async function(t,e,n,r){const i=t.files,s=t.writer;let a;i.set(e,null);try{let o,c;try{r.bufferedWrite||t.options.bufferedWrite||t.lockWrite?(o=new f,o.init()):(t.lockWrite=new Promise((t=>a=t)),s.initialized||await s.init(),o=s),(t.offset>=y||n&&(n.size>=y||t.offset+n.size>=y))&&(r.zip64=!0),c=await async function(t,e,n,r,i,s){const a=Zt(Vt(t)),o=s.lastModDate||new Date,c=new Uint8Array(26),h=new DataView(c.buffer),d=void 0===s.password?i.password:s.password,l=d&&d.length&&d,u=void 0===s.level?i.level:s.level,p=0!==u&&!s.directory,g=void 0===d||!d.length,f=s.zip64;let w;if(l){w=new Uint8Array(Pt.length+2);new DataView(w.buffer).setUint16(0,x,!0),w.set(Pt,2)}else w=new Uint8Array(0);const E={zip64:f,headerArray:c,directory:s.directory,filename:a,comment:s.comment,extraFieldZip64:f?new Uint8Array(28):new Uint8Array(0),extraFieldAES:w,rawExtraField:new Uint8Array(0)},A=s.extraField;if(a.length>m)throw new Error(Nt);if(A){let t=4,e=0;A.forEach((e=>t+=e.length));const n=E.rawExtraField=new Uint8Array(t);A.forEach(((t,r)=>{if(r>m)throw new Error(Ot);if(t.length>m)throw new Error(Wt);n.set(new Uint16Array([r]),e),n.set(new Uint16Array([t.length]),e+2),n.set(t,e+4),e+=4+t.length}))}if(s.bitFlag=2056,s.version=(void 0===s.version?i.version:s.version)||20,s.version>m)throw new Error(Mt);s.compressionMethod=0,p&&(s.compressionMethod=8);f&&(s.version=s.version>F?s.version:F);l&&(E.encrypted=!0,s.version=s.version>v?s.version:v,s.bitFlag=1|s.bitFlag,s.compressionMethod=99,p&&(E.extraFieldAES[9]=8));h.setUint16(0,s.version,!0),h.setUint16(2,s.bitFlag,!0),h.setUint16(4,s.compressionMethod,!0),h.setUint16(6,(o.getHours()<<6|o.getMinutes())<<5|o.getSeconds()/2,!0),h.setUint16(8,(o.getFullYear()-1980<<4|o.getMonth()+1)<<5|o.getDate(),!0),h.setUint16(22,a.length,!0),h.setUint16(24,0,!0);const R=new Uint8Array(30+a.length);let D;if(new DataView(R.buffer).setUint32(0,U),R.set(c,4),R.set(a,30),e){e.initialized||await e.init();const t=await ht(r,{codecType:Q,level:u,outputPassword:d,outputSigned:g,outputCompressed:p,outputEncrypted:Boolean(d),useWebWorkers:void 0===s.useWebWorkers?i.useWebWorkers:s.useWebWorkers});await n.writeUint8Array(R),D=await gt(t,e,n,0,e.size,r,{onprogress:s.onprogress}),E.compressedSize=D.length}else await n.writeUint8Array(R);const z=new Uint8Array(f?24:16),I=new DataView(z.buffer);if(I.setUint32(0,b),e)if(l||void 0===D.signature||(h.setUint32(10,D.signature,!0),I.setUint32(4,D.signature,!0)),f){h.setUint32(14,y,!0),I.setBigUint64(8,BigInt(E.compressedSize),!0),h.setUint32(18,y,!0),I.setBigUint64(16,BigInt(e.size),!0);const t=new DataView(E.extraFieldZip64.buffer);t.setUint16(0,1,!0),t.setUint16(2,24,!0),t.setBigUint64(4,BigInt(e.size),!0),t.setBigUint64(12,BigInt(E.compressedSize),!0)}else h.setUint32(14,E.compressedSize,!0),I.setUint32(8,E.compressedSize,!0),h.setUint32(18,e.size,!0),I.setUint32(12,e.size,!0);return await n.writeUint8Array(z),E.length=R.length+(D?D.length:0)+z.length,E}(e,n,o,t.config,t.options,r)}catch(t){throw i.delete(e),t}if(i.set(e,c),o!=s&&(t.lockWrite&&await t.lockWrite,await s.writeUint8Array(o.getData())),c.offset=t.offset,c.zip64){new DataView(c.extraFieldZip64.buffer).setBigUint64(20,BigInt(c.offset),!0)}t.offset+=c.length}finally{a&&(t.lockWrite=null,a())}}(this,t,e,n)}async close(t){const e=this.writer,n=this.files;let r=0,i=0,s=this.offset,a=n.size;if(t&&t.length){if(!(t.length<=m))throw new Error(kt);c.setUint16(r+20,t.length,!0)}for(const[,t]of n)i+=46+t.filename.length+t.comment.length+t.extraFieldZip64.length+t.extraFieldAES.length+t.rawExtraField.length;(s+i>=y||a>=m)&&(this.zip64=!0);const o=new Uint8Array(i+(this.zip64?98:22)),c=new DataView(o.buffer);this.options.version=this.options.version||20;for(const[,t]of n){const e=t.filename,n=t.extraFieldZip64,i=t.extraFieldAES,s=n.length+i.length+t.rawExtraField.length;c.setUint32(r,E),t.zip64&&c.setUint16(r+4,this.options.version>F?this.options:F,!0),t.encrypted?c.setUint16(r+4,this.options.version>v?this.options:v,!0):c.setUint16(r+4,this.options.version>20?this.options:20,!0),o.set(t.headerArray,r+6),c.setUint16(r+30,s,!0),c.setUint16(r+32,t.comment.length,!0),t.directory&&c.setUint8(r+38,16),t.zip64?c.setUint32(r+42,y,!0):c.setUint32(r+42,t.offset,!0),o.set(e,r+46),o.set(n,r+46+e.length),o.set(i,r+46+e.length+n.length),o.set(t.rawExtraField,46+e.length+n.length+i.length),o.set(t.comment,r+46+e.length+s),r+=46+e.length+s+t.comment.length}return this.zip64&&(c.setUint32(r,R),c.setBigUint64(r+4,BigInt(44),!0),c.setUint16(r+12,45,!0),c.setUint16(r+14,45,!0),c.setBigUint64(r+24,BigInt(a),!0),c.setBigUint64(r+32,BigInt(a),!0),c.setBigUint64(r+40,BigInt(i),!0),c.setBigUint64(r+48,BigInt(s),!0),c.setUint32(r+56,D),c.setBigUint64(r+64,BigInt(s+i),!0),c.setUint32(r+72,1,!0),a=m,s=y,r+=76),c.setUint32(r,A),c.setUint16(r+8,a,!0),c.setUint16(r+10,a,!0),c.setUint32(r+12,i,!0),c.setUint32(r+16,s,!0),await e.writeUint8Array(o),t&&t.length&&await e.writeUint8Array(t),e.getData()}}{constructor(t,e){super(t,e,qt)}}const Gt=524288;class Jt{constructor(t,e,n,r){if(t.root&&r&&r.getChildByName(e))throw new Error("Entry filename already exists");n||(n={}),this.fs=t,this.name=e,this.id=t.entries.length,this.parent=r,this.children=[],this.zipVersion=n.zipVersion||20,this.uncompressedSize=0,t.entries.push(this),r&&this.parent.children.push(this)}moveTo(t){if(!t.directory)throw new Error("Target entry is not a directory");if(t.isDescendantOf(this))throw new Error("Entry is a ancestor of target entry");if(this!=t){if(t.getChildByName(this.name))throw new Error("Entry filename already exists");ie(this),this.parent=t,t.children.push(this)}}getFullname(){let t=this.name,e=this.parent;for(;e;)t=(e.name?e.name+"/":"")+t,e=e.parent;return t}isDescendantOf(t){let e=this.parent;for(;e&&e.id!=t.id;)e=e.parent;return Boolean(e)}}class Qt extends Jt{constructor(t,e,n,r){super(t,e,n,r),this.Reader=n.Reader,this.Writer=n.Writer,this.data=n.data,n.getData&&(this.getData=n.getData)}async getData(t,e={}){return!t||t.constructor==this.Writer&&this.data?this.data:(this.reader||(this.reader=new this.Reader(this.data)),await this.reader.init(),await t.init(),this.uncompressedSize=this.reader.size,async function(t,e,n){return r();async function r(i=0){const s=i*Gt;if(n.onprogress&&n.onprogress(s,t.size),s{e.file((r=>{t.addBlob(e.name,r),n()}),r)}));function n(t){return new Promise(((e,n)=>{let r=[];function i(t){t.readEntries((n=>{n.length?(r=r.concat(n),i(t)):e(r)}),n)}t.isDirectory&&i(t.createReader()),t.isFile&&e(r)}))}async function r(t,e){const i=await n(e);for(const e of i)e.isDirectory&&await r(t.addDirectory(e.name)),await new Promise(((n,r)=>{e.isFile&&e.file((r=>{const i=t.addBlob(e.name,r);i.uncompressedSize=r.size,n(i)}),r)}))}}(this,t)}async addData(t,e){return ae(this,t,e)}async importBlob(t,e={}){await this.importZip(new l(t),e)}async importData64URI(t,e={}){await this.importZip(new h(t),e)}async importHttpContent(t,e={}){await this.importZip(e.useRangeHeader?new g(t):new p(t),e)}async exportBlob(t={}){return this.exportZip(new u("application/zip"),t)}async exportData64URI(t={}){return this.exportZip(new d("application/zip"),t)}async importZip(t,e){await t.init();const n=new Xt(t),r=await n.getEntries();let i=0;const s=ee(r,"compressedSize");r.forEach((t=>{let n=this,r=t.filename.split("/"),a=r.pop();if(r.forEach((t=>n=n.getChildByName(t)||new $t(this.fs,t,null,n))),!t.directory){let r=i;ae(n,a,{data:t,Reader:ne(Object.assign({},e,{onprogress:t=>{e.onprogress&&e.onprogress(r+t,s)}}))}),i+=t.compressedSize}}))}async exportZip(t,e){await re(this);const n=new Yt(t);return await async function(t,e,n,r){let i=0;async function s(t,e){async function a(){let a=0;for(const o of e.children){let e=i;await t.add(o.getFullname(),o.reader,Object.assign({directory:o.directory,version:o.zipVersion},r,{onprogress:t=>{r.onprogress&&r.onprogress(e+a+t,n)}})),i+=o.uncompressedSize,await s(t,o),a++}}await a()}await s(t,e)}(n,this,ee([this],"uncompressedSize"),e),await n.close(),t.getData()}getChildByName(t){for(let e=0;e{n.id==t.id&&e.splice(r,1)}))}function se(t){t.entries=[],t.root=new $t(t)}function ae(t,e,n,r){if(t.directory)return r?new $t(t.fs,e,n,t):new Qt(t.fs,e,n,t);throw new Error("Parent entry is not a directory")}t.BlobReader=l,t.BlobWriter=u,t.Data64URIReader=h,t.Data64URIWriter=d,t.ERR_BAD_FORMAT=wt,t.ERR_CENTRAL_DIRECTORY_NOT_FOUND=bt,t.ERR_DUPLICATED_NAME=_t,t.ERR_ENCRYPTED=Rt,t.ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND=Ut,t.ERR_EOCDR_NOT_FOUND=yt,t.ERR_EOCDR_ZIP64_NOT_FOUND=mt,t.ERR_EXTRAFIELD_ZIP64_NOT_FOUND=At,t.ERR_HTTP_RANGE=n,t.ERR_INVALID_COMMENT=kt,t.ERR_INVALID_ENTRY_COMMENT=Ct,t.ERR_INVALID_ENTRY_NAME=Nt,t.ERR_INVALID_EXTRAFIELD_DATA=Wt,t.ERR_INVALID_EXTRAFIELD_TYPE=Ot,t.ERR_INVALID_PASSORD=S,t.ERR_INVALID_SIGNATURE=tt,t.ERR_INVALID_VERSION=Mt,t.ERR_LOCAL_FILE_HEADER_NOT_FOUND=Et,t.ERR_UNSUPPORTED_COMPRESSION=xt,t.ERR_UNSUPPORTED_ENCRYPTION=Dt,t.HttpRangeReader=g,t.HttpReader=p,t.Reader=s,t.TextReader=o,t.TextWriter=c,t.Uint8ArrayReader=class extends s{constructor(t){super(),this.array=t,this.size=t.length}readUint8Array(t,e){return this.array.slice(t,t+e)}},t.Uint8ArrayWriter=f,t.Writer=a,t.ZipReader=Xt,t.ZipWriter=Yt,t.configure=function(t){qt=Object.assign({},qt,t)},t.fs=te,t.getMimeType=function(){return"application/octet-stream"},t.initShimAsyncCodec=(t,e={})=>({ZipDeflate:jt(t.Deflate,e.deflate),ZipInflate:jt(t.Inflate,e.inflate)}),Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/dist/zip.js b/dist/zip.js index 7c628734..97e6ea71 100644 --- a/dist/zip.js +++ b/dist/zip.js @@ -392,6 +392,7 @@ const EXTRA_FIELD_TYPE_ZIP64 = 0x0001; const EXTRA_FIELD_TYPE_AES = 0x9901; const EXTRA_FIELD_TYPE_UNICODE_PATH = 0x7075; + const EXTRA_FIELD_TYPE_UNICODE_COMMENT = 0x6375; const BITFLAG_ENCRYPTED = 0x01; const BITFLAG_LEVEL = 0x06; @@ -882,8 +883,11 @@ function createWorkerCodec(config, options) { const pool = workers.pool; + const streamCopy = + !options.inputCompressed && !options.inputSigned && !options.inputEncrypted && + !options.outputCompressed && !options.outputSigned && !options.outputEncrypted; let scripts; - if (config.useWebWorkers) { + if (options.useWebWorkers || (options.useWebWorkers === undefined && config.useWebWorkers && !streamCopy)) { const codecType = options.codecType; if (config.workerScripts != null && config.workerScriptsPath != null) { throw new Error("Either workerScripts or workerScriptsPath may be set, not both"); @@ -900,22 +904,26 @@ } } if (pool.length < config.maxWorkers) { - const workerData = { worker: scripts && new Worker(scripts[0]), busy: true, options, scripts }; + const workerData = { busy: true, options, scripts }; pool.push(workerData); return scripts ? createWebWorkerInterface(workerData) : createWorkerInterface(workerData); } else { - const availableWorkerData = pool.find(workerData => !workerData.busy); - if (availableWorkerData) { - availableWorkerData.busy = true; - availableWorkerData.options = options; - availableWorkerData.scripts = scripts; - return scripts ? availableWorkerData.interface : createWorkerInterface(availableWorkerData); + const workerData = pool.find(workerData => !workerData.busy); + if (workerData) { + return getWorkerInterface(workerData); } else { return new Promise(resolve => workers.pendingRequests.push({ resolve, options, scripts })); } } } + function getWorkerInterface(workerData, options, scripts) { + workerData.busy = true; + workerData.options = options; + workerData.scripts = scripts; + return scripts ? createWebWorkerInterface(workerData) : createWorkerInterface(workerData); + } + function createWorkerInterface(workerData) { const interfaceCodec = createCodec(workerData.options); const append = interfaceCodec.append.bind(interfaceCodec); @@ -924,7 +932,7 @@ try { return await append(data); } catch (error) { - await onWorkerTaskFinished(workerData); + onTaskFinished(workerData); throw error; } }; @@ -932,36 +940,26 @@ try { return await flush(); } finally { - await onWorkerTaskFinished(workerData); + onTaskFinished(workerData); } }; return interfaceCodec; } - async function onWorkerTaskFinished(workerData) { - workerData.busy = false; - if (workers.pendingRequests.length) { - const [{ resolve, options }] = workers.pendingRequests.splice(0, 1); - workerData.busy = true; - workerData.options = options; - resolve(createWorkerInterface(workerData)); - } else { - workers.pool = workers.pool.filter(data => data != workerData); - } - } - function createWebWorkerInterface(workerData) { - const worker = workerData.worker; let task; - worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false); - workerData.interface = { - async append(data) { - return initAndSendMessage({ type: MESSAGE_APPEND, data }); - }, - async flush() { - return initAndSendMessage({ type: MESSAGE_FLUSH }); - } - }; + if (!workerData.interface) { + workerData.worker = new Worker(workerData.scripts[0]); + workerData.worker.addEventListener(MESSAGE_EVENT_TYPE, onMessage, false); + workerData.interface = { + append(data) { + return initAndSendMessage({ type: MESSAGE_APPEND, data }); + }, + flush() { + return initAndSendMessage({ type: MESSAGE_FLUSH }); + } + }; + } return workerData.interface; async function initAndSendMessage(message) { @@ -973,6 +971,8 @@ } function sendMessage(message) { + const worker = workerData.worker; + const result = new Promise((resolve, reject) => task = { resolve, reject }); try { if (message.data) { try { @@ -986,9 +986,9 @@ } catch (error) { task.reject(error); task = null; - onWebWorkerTaskFinished(workerData); + onTaskFinished(workerData); } - return new Promise((resolve, reject) => task = { resolve, reject }); + return result; } function onMessage(event) { @@ -1000,12 +1000,12 @@ error.stack = reponseError.stack; task.reject(error); task = null; - onWebWorkerTaskFinished(workerData); + onTaskFinished(workerData); } else if (message.type == MESSAGE_INIT || message.type == MESSAGE_FLUSH || message.type == MESSAGE_APPEND) { if (message.type == MESSAGE_FLUSH) { task.resolve({ data: new Uint8Array(message.data), signature: message.signature }); task = null; - onWebWorkerTaskFinished(workerData); + onTaskFinished(workerData); } else { task.resolve(message.data && new Uint8Array(message.data)); } @@ -1014,16 +1014,15 @@ } } - function onWebWorkerTaskFinished(workerData) { + function onTaskFinished(workerData) { workerData.busy = false; if (workers.pendingRequests.length) { const [{ resolve, options, scripts }] = workers.pendingRequests.splice(0, 1); - workerData.busy = true; - workerData.options = options; - workerData.scripts = scripts; - resolve(workerData.interface); + resolve(getWorkerInterface(workerData, options, scripts)); } else { - workerData.worker.terminate(); + if (workerData.worker) { + workerData.worker.terminate(); + } workers.pool = workers.pool.filter(data => data != workerData); } } @@ -1150,52 +1149,56 @@ if (!reader.initialized) { await reader.init(); } - const directoryInfo = await seekSignature(reader, END_OF_CENTRAL_DIR_SIGNATURE, END_OF_CENTRAL_DIR_LENGTH, MAX_16_BITS); - let zip64, directoryDataView = new DataView(directoryInfo.buffer); - let directoryDataLength = directoryDataView.getUint32(16, true); - let filesLength = directoryDataView.getUint16(8, true); - if (directoryDataLength == MAX_32_BITS || filesLength == MAX_16_BITS) { + const endOfDirectoryInfo = await seekSignature(reader, END_OF_CENTRAL_DIR_SIGNATURE, END_OF_CENTRAL_DIR_LENGTH, MAX_16_BITS); + if (!endOfDirectoryInfo) { + throw new Error(ERR_EOCDR_NOT_FOUND); + } + const endOfDirectoryView = new DataView(endOfDirectoryInfo.buffer); + let zip64; + let directoryDataOffset = endOfDirectoryView.getUint32(16, true); + let filesLength = endOfDirectoryView.getUint16(8, true); + if (directoryDataOffset == MAX_32_BITS || filesLength == MAX_16_BITS) { zip64 = true; - const directoryLocatorArray = await reader.readUint8Array(directoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH); - const directoryLocatorView = new DataView(directoryLocatorArray.buffer); - if (Number(directoryLocatorView.getUint32(0, false)) != ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) { + const endOfDirectoryLocatorArray = await reader.readUint8Array(endOfDirectoryInfo.offset - ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_LENGTH); + const endOfDirectoryLocatorView = new DataView(endOfDirectoryLocatorArray.buffer); + if (Number(endOfDirectoryLocatorView.getUint32(0, false)) != ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE) { throw new Error(ERR_EOCDR_ZIP64_NOT_FOUND); } - directoryDataLength = Number(directoryLocatorView.getBigUint64(8, true)); - const directoryDataArray = await reader.readUint8Array(directoryDataLength, ZIP64_END_OF_CENTRAL_DIR_LENGTH); - const directoryDataView = new DataView(directoryDataArray.buffer); - if (Number(directoryDataView.getUint32(0, false)) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) { + directoryDataOffset = Number(endOfDirectoryLocatorView.getBigUint64(8, true)); + const endOfDirectoryArray = await reader.readUint8Array(directoryDataOffset, ZIP64_END_OF_CENTRAL_DIR_LENGTH); + const endOfDirectoryView = new DataView(endOfDirectoryArray.buffer); + if (Number(endOfDirectoryView.getUint32(0, false)) != ZIP64_END_OF_CENTRAL_DIR_SIGNATURE) { throw new Error(ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND); } - filesLength = Number(directoryDataView.getBigUint64(24, true)); - directoryDataLength -= Number(directoryDataView.getBigUint64(40, true)); + filesLength = Number(endOfDirectoryView.getBigUint64(24, true)); + directoryDataOffset -= Number(endOfDirectoryView.getBigUint64(40, true)); } - if (directoryDataLength < 0 || (!zip64 && (directoryDataLength >= reader.size || filesLength >= MAX_16_BITS))) { + if (directoryDataOffset < 0 || (!zip64 && (directoryDataOffset >= reader.size || filesLength >= MAX_16_BITS))) { throw new Error(ERR_BAD_FORMAT); } - const directoryDataArray = await reader.readUint8Array(directoryDataLength, reader.size - directoryDataLength); - directoryDataView = new DataView(directoryDataArray.buffer); + const directoryArray = await reader.readUint8Array(directoryDataOffset, reader.size - directoryDataOffset); + const directoryView = new DataView(directoryArray.buffer); const entries = []; let offset = 0; for (let indexFile = 0; indexFile < filesLength; indexFile++) { const fileEntry = new Entry(this.reader, this.config, this.options); - if (directoryDataView.getUint32(offset, false) != CENTRAL_FILE_HEADER_SIGNATURE) { + if (directoryView.getUint32(offset, false) != CENTRAL_FILE_HEADER_SIGNATURE) { throw new Error(ERR_CENTRAL_DIRECTORY_NOT_FOUND); } fileEntry.compressedSize = 0; fileEntry.uncompressedSize = 0; - readCommonHeader(fileEntry, directoryDataView, offset + 6); - fileEntry.commentLength = directoryDataView.getUint16(offset + 32, true); - fileEntry.directory = ((directoryDataView.getUint8(offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK); - fileEntry.offset = directoryDataView.getUint32(offset + 42, true); - fileEntry.rawFilename = directoryDataArray.subarray(offset + 46, offset + 46 + fileEntry.filenameLength); + readCommonHeader(fileEntry, directoryView, offset + 6); + fileEntry.commentLength = directoryView.getUint16(offset + 32, true); + fileEntry.directory = ((directoryView.getUint8(offset + 38) & FILE_ATTR_MSDOS_DIR_MASK) == FILE_ATTR_MSDOS_DIR_MASK); + fileEntry.offset = directoryView.getUint32(offset + 42, true); + fileEntry.rawFilename = directoryArray.subarray(offset + 46, offset + 46 + fileEntry.filenameLength); fileEntry.filename = decodeString(fileEntry.rawFilename, fileEntry.bitFlag.languageEncodingFlag ? CHARSET_UTF8 : this.options.filenameEncoding || CHARSET_WIN_1252); if (!fileEntry.directory && fileEntry.filename && fileEntry.filename.charAt(fileEntry.filename.length - 1) == DIRECTORY_SIGNATURE) { fileEntry.directory = true; } - fileEntry.rawExtraField = directoryDataArray.subarray(offset + 46 + fileEntry.filenameLength, offset + 46 + fileEntry.filenameLength + fileEntry.extraFieldLength); - readCommonFooter(fileEntry, fileEntry, directoryDataView, offset + 6); - fileEntry.rawComment = directoryDataArray.subarray(offset + 46 + fileEntry.filenameLength + fileEntry.extraFieldLength, offset + 46 + fileEntry.rawExtraField = directoryArray.subarray(offset + 46 + fileEntry.filenameLength, offset + 46 + fileEntry.filenameLength + fileEntry.extraFieldLength); + readCommonFooter(fileEntry, fileEntry, directoryView, offset + 6); + fileEntry.rawComment = directoryArray.subarray(offset + 46 + fileEntry.filenameLength + fileEntry.extraFieldLength, offset + 46 + fileEntry.filenameLength + fileEntry.extraFieldLength + fileEntry.commentLength); fileEntry.comment = decodeString(fileEntry.rawComment, fileEntry.bitFlag.languageEncodingFlag ? CHARSET_UTF8 : this.options.commentEncoding || CHARSET_WIN_1252); entries.push(fileEntry); @@ -1254,7 +1257,8 @@ inputSigned: options.checkSignature === undefined ? this.options.checkSignature : options.checkSignature, inputSignature: this.signature, inputCompressed: this.compressionMethod != 0, - inputEncrypted + inputEncrypted, + useWebWorkers: options.useWebWorkers === undefined ? this.options.useWebWorkers : options.useWebWorkers }); if (!writer.initialized) { await writer.init(); @@ -1281,7 +1285,6 @@ } function readCommonFooter(fileEntry, directory, dataView, offset) { - let extraFieldZip64, extraFieldAES, extraFieldUnicodePath; const rawExtraField = directory.rawExtraField; const extraField = directory.extraField = new Map(); const rawExtraFieldView = new DataView(new Uint8Array(rawExtraField).buffer); @@ -1303,15 +1306,19 @@ directory.signature = dataView.getUint32(offset + 10, true); directory.uncompressedSize = dataView.getUint32(offset + 18, true); directory.compressedSize = dataView.getUint32(offset + 14, true); - extraFieldZip64 = directory.extraFieldZip64 = extraField.get(EXTRA_FIELD_TYPE_ZIP64); + const extraFieldZip64 = directory.extraFieldZip64 = extraField.get(EXTRA_FIELD_TYPE_ZIP64); if (extraFieldZip64) { readExtraFieldZip64(extraFieldZip64, directory); } - extraFieldUnicodePath = directory.extraFieldUnicodePath = extraField.get(EXTRA_FIELD_TYPE_UNICODE_PATH); + const extraFieldUnicodePath = directory.extraFieldUnicodePath = extraField.get(EXTRA_FIELD_TYPE_UNICODE_PATH); if (extraFieldUnicodePath) { - readExtraFieldUnicodePath(extraFieldUnicodePath, directory, fileEntry); + readExtraFieldUnicode(extraFieldUnicodePath, "filename", "rawFilename", directory, fileEntry); + } + let extraFieldUnicodeComment = directory.extraFieldUnicodeComment = extraField.get(EXTRA_FIELD_TYPE_UNICODE_COMMENT); + if (extraFieldUnicodeComment) { + readExtraFieldUnicode(extraFieldUnicodeComment, "comment", "rawComment", directory, fileEntry); } - extraFieldAES = directory.extraFieldAES = extraField.get(EXTRA_FIELD_TYPE_AES); + const extraFieldAES = directory.extraFieldAES = extraField.get(EXTRA_FIELD_TYPE_AES); if (extraFieldAES) { readExtraFieldAES(extraFieldAES, directory, compressionMethod); } else { @@ -1344,17 +1351,17 @@ }); } - function readExtraFieldUnicodePath(extraFieldUnicodePath, directory, fileEntry) { - const extraFieldView = new DataView(extraFieldUnicodePath.data.buffer); - extraFieldUnicodePath.version = extraFieldView.getUint8(0); - extraFieldUnicodePath.signature = extraFieldView.getUint32(1, true); + function readExtraFieldUnicode(extraFieldUnicode, propertyName, rawPropertyName, directory, fileEntry) { + const extraFieldView = new DataView(extraFieldUnicode.data.buffer); + extraFieldUnicode.version = extraFieldView.getUint8(0); + extraFieldUnicode.signature = extraFieldView.getUint32(1, true); const crc32 = new Crc32(); - crc32.append(fileEntry.rawFilename); + crc32.append(fileEntry[rawPropertyName]); const dataViewSignature = new DataView(new Uint8Array(4).buffer); dataViewSignature.setUint32(0, crc32.get()); - extraFieldUnicodePath.filename = (new TextDecoder()).decode(extraFieldUnicodePath.data.subarray(5)); - if (extraFieldUnicodePath.signature == dataViewSignature.getUint32(0, false)) { - directory.filename = extraFieldUnicodePath.filename; + extraFieldUnicode[propertyName] = (new TextDecoder()).decode(extraFieldUnicode.data.subarray(5)); + if (extraFieldUnicode.signature == dataViewSignature.getUint32(0, false)) { + directory[propertyName] = extraFieldUnicode[propertyName]; } } @@ -1385,9 +1392,6 @@ if (!dataInfo) { dataInfo = await seek(Math.min(maximumBytes, reader.size)); } - if (!dataInfo) { - throw new Error(ERR_EOCDR_NOT_FOUND); - } return dataInfo; async function seek(length) { @@ -1489,7 +1493,7 @@ let offset = 0, directoryDataLength = 0, directoryOffset = this.offset, filesLength = files.size; if (comment && comment.length) { if (comment.length <= MAX_16_BITS) { - directoryDataView.setUint16(offset + 20, comment.length, true); + directoryView.setUint16(offset + 20, comment.length, true); } else { throw new Error(ERR_INVALID_COMMENT); } @@ -1500,62 +1504,62 @@ if (directoryOffset + directoryDataLength >= MAX_32_BITS || filesLength >= MAX_16_BITS) { this.zip64 = true; } - const directoryDataArray = new Uint8Array(directoryDataLength + (this.zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH)); - const directoryDataView = new DataView(directoryDataArray.buffer); + const directoryArray = new Uint8Array(directoryDataLength + (this.zip64 ? ZIP64_END_OF_CENTRAL_DIR_TOTAL_LENGTH : END_OF_CENTRAL_DIR_LENGTH)); + const directoryView = new DataView(directoryArray.buffer); this.options.version = this.options.version || VERSION_DEFLATE; for (const [, fileEntry] of files) { const filename = fileEntry.filename; const extraFieldZip64 = fileEntry.extraFieldZip64; const extraFieldAES = fileEntry.extraFieldAES; const extraFieldLength = extraFieldZip64.length + extraFieldAES.length + fileEntry.rawExtraField.length; - directoryDataView.setUint32(offset, CENTRAL_FILE_HEADER_SIGNATURE); + directoryView.setUint32(offset, CENTRAL_FILE_HEADER_SIGNATURE); if (fileEntry.zip64) { - directoryDataView.setUint16(offset + 4, this.options.version > VERSION_ZIP64 ? this.options : VERSION_ZIP64, true); + directoryView.setUint16(offset + 4, this.options.version > VERSION_ZIP64 ? this.options : VERSION_ZIP64, true); } if (fileEntry.encrypted) { - directoryDataView.setUint16(offset + 4, this.options.version > VERSION_AES ? this.options : VERSION_AES, true); + directoryView.setUint16(offset + 4, this.options.version > VERSION_AES ? this.options : VERSION_AES, true); } else { - directoryDataView.setUint16(offset + 4, this.options.version > VERSION_DEFLATE ? this.options : VERSION_DEFLATE, true); + directoryView.setUint16(offset + 4, this.options.version > VERSION_DEFLATE ? this.options : VERSION_DEFLATE, true); } - directoryDataArray.set(fileEntry.headerArray, offset + 6); - directoryDataView.setUint16(offset + 30, extraFieldLength, true); - directoryDataView.setUint16(offset + 32, fileEntry.comment.length, true); + directoryArray.set(fileEntry.headerArray, offset + 6); + directoryView.setUint16(offset + 30, extraFieldLength, true); + directoryView.setUint16(offset + 32, fileEntry.comment.length, true); if (fileEntry.directory) { - directoryDataView.setUint8(offset + 38, FILE_ATTR_MSDOS_DIR_MASK); + directoryView.setUint8(offset + 38, FILE_ATTR_MSDOS_DIR_MASK); } if (fileEntry.zip64) { - directoryDataView.setUint32(offset + 42, MAX_32_BITS, true); + directoryView.setUint32(offset + 42, MAX_32_BITS, true); } else { - directoryDataView.setUint32(offset + 42, fileEntry.offset, true); + directoryView.setUint32(offset + 42, fileEntry.offset, true); } - directoryDataArray.set(filename, offset + 46); - directoryDataArray.set(extraFieldZip64, offset + 46 + filename.length); - directoryDataArray.set(extraFieldAES, offset + 46 + filename.length + extraFieldZip64.length); - directoryDataArray.set(fileEntry.rawExtraField, 46 + filename.length + extraFieldZip64.length + extraFieldAES.length); - directoryDataArray.set(fileEntry.comment, offset + 46 + filename.length + extraFieldLength); + directoryArray.set(filename, offset + 46); + directoryArray.set(extraFieldZip64, offset + 46 + filename.length); + directoryArray.set(extraFieldAES, offset + 46 + filename.length + extraFieldZip64.length); + directoryArray.set(fileEntry.rawExtraField, 46 + filename.length + extraFieldZip64.length + extraFieldAES.length); + directoryArray.set(fileEntry.comment, offset + 46 + filename.length + extraFieldLength); offset += 46 + filename.length + extraFieldLength + fileEntry.comment.length; } if (this.zip64) { - directoryDataView.setUint32(offset, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE); - directoryDataView.setBigUint64(offset + 4, BigInt(44), true); - directoryDataView.setUint16(offset + 12, 45, true); - directoryDataView.setUint16(offset + 14, 45, true); - directoryDataView.setBigUint64(offset + 24, BigInt(filesLength), true); - directoryDataView.setBigUint64(offset + 32, BigInt(filesLength), true); - directoryDataView.setBigUint64(offset + 40, BigInt(directoryDataLength), true); - directoryDataView.setBigUint64(offset + 48, BigInt(directoryOffset), true); - directoryDataView.setUint32(offset + 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE); - directoryDataView.setBigUint64(offset + 64, BigInt(directoryOffset + directoryDataLength), true); - directoryDataView.setUint32(offset + 72, 1, true); + directoryView.setUint32(offset, ZIP64_END_OF_CENTRAL_DIR_SIGNATURE); + directoryView.setBigUint64(offset + 4, BigInt(44), true); + directoryView.setUint16(offset + 12, 45, true); + directoryView.setUint16(offset + 14, 45, true); + directoryView.setBigUint64(offset + 24, BigInt(filesLength), true); + directoryView.setBigUint64(offset + 32, BigInt(filesLength), true); + directoryView.setBigUint64(offset + 40, BigInt(directoryDataLength), true); + directoryView.setBigUint64(offset + 48, BigInt(directoryOffset), true); + directoryView.setUint32(offset + 56, ZIP64_END_OF_CENTRAL_DIR_LOCATOR_SIGNATURE); + directoryView.setBigUint64(offset + 64, BigInt(directoryOffset + directoryDataLength), true); + directoryView.setUint32(offset + 72, 1, true); filesLength = MAX_16_BITS; directoryOffset = MAX_32_BITS; offset += 76; } - directoryDataView.setUint32(offset, END_OF_CENTRAL_DIR_SIGNATURE); - directoryDataView.setUint16(offset + 8, filesLength, true); - directoryDataView.setUint16(offset + 10, filesLength, true); - directoryDataView.setUint32(offset + 12, directoryDataLength, true); - directoryDataView.setUint32(offset + 16, directoryOffset, true); - await writer.writeUint8Array(directoryDataArray); + directoryView.setUint32(offset, END_OF_CENTRAL_DIR_SIGNATURE); + directoryView.setUint16(offset + 8, filesLength, true); + directoryView.setUint16(offset + 10, filesLength, true); + directoryView.setUint32(offset + 12, directoryDataLength, true); + directoryView.setUint32(offset + 16, directoryOffset, true); + await writer.writeUint8Array(directoryArray); if (comment && comment.length) { await writer.writeUint8Array(comment); } @@ -1570,7 +1574,7 @@ try { let fileWriter, fileEntry; try { - if ((options.bufferedWrite || zipWriter.options.bufferedWrite) || zipWriter.lockWrite) { + if (options.bufferedWrite || zipWriter.options.bufferedWrite || zipWriter.lockWrite) { fileWriter = new Uint8ArrayWriter(); fileWriter.init(); } else { @@ -1660,7 +1664,7 @@ offset += 4 + data.length; }); } - options.bitFlag = BITFLAG_DATA_DESCRIPTOR; + options.bitFlag = BITFLAG_DATA_DESCRIPTOR | BITFLAG_LANG_ENCODING_FLAG; options.version = (options.version === undefined ? zipWriterOptions.version : options.version) || VERSION_DEFLATE; if (options.version > MAX_16_BITS) { throw new Error(ERR_INVALID_VERSION); @@ -1704,7 +1708,8 @@ outputPassword: password, outputSigned, outputCompressed: compressed, - outputEncrypted: Boolean(password) + outputEncrypted: Boolean(password), + useWebWorkers: options.useWebWorkers === undefined ? zipWriterOptions.useWebWorkers : options.useWebWorkers }); await writer.writeUint8Array(fileDataArray); result = await processData(codec, reader, writer, 0, reader.size, config, { onprogress: options.onprogress }); diff --git a/dist/zip.min.js b/dist/zip.min.js index ac8f276b..ab57758a 100644 --- a/dist/zip.min.js +++ b/dist/zip.min.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).zip={})}(this,(function(t){"use strict";const e="HTTP error ",n="HTTP Range not supported",i="text/plain";class r{constructor(){this.size=0}init(){this.initialized=!0}}class s extends r{}class a extends r{writeUint8Array(t){this.size+=t.length}}class o extends s{constructor(t){super(),this.blob=t,this.size=t.size}readUint8Array(t,e){const n=new FileReader;return new Promise(((i,r)=>{n.onload=t=>i(new Uint8Array(t.target.result)),n.onerror=r,n.readAsArrayBuffer(this.blob.slice(t,t+e))}))}}class c extends a{constructor(){super(),this.array=new Uint8Array(0)}writeUint8Array(t){super.writeUint8Array(t);const e=this.array;this.array=new Uint8Array(e.length+t.length),this.array.set(e),this.array.set(t,e.length)}getData(){return this.array}}function h(t,n){return new Promise(((i,r)=>{const s=new XMLHttpRequest;s.addEventListener("load",(()=>{s.status<400?(t.size||(t.size=Number(s.getResponseHeader("Content-Length"))||Number(s.response.byteLength)),t.data=new Uint8Array(s.response),i()):r(e+(s.statusText||s.status)+".")}),!1),s.addEventListener("error",r,!1),s.open("GET",n),s.responseType="arraybuffer",s.send()}))}const l=4294967295,d=65535,u=1347093252,p=1347094280,g=1347092738,f=1347093766,w=1347094022,y=1347094023,U=39169,b=45,m=51;class A{constructor(){this.crc=-1,this.table=(()=>{const t=[];for(let e=0;e<256;e++){let n=e;for(let t=0;t<8;t++)1&n?n=n>>>1^3988292384:n>>>=1;t[e]=n}return t})()}append(t){const e=this.table;let n=0|this.crc;for(let i=0,r=0|t.length;i>>8^e[255&(n^t[i])];this.crc=n}get(){return~this.crc}}const E="Invalid pasword",R=16,D="raw",x={name:"PBKDF2"},F={name:"HMAC"},v="SHA-1",z={name:"AES-CTR"},I=Object.assign({hash:F},x),L=Object.assign({iterations:1e3,hash:{name:v}},x),S=Object.assign({hash:v},F),_=Object.assign({length:R},z),T=["deriveBits"],M=["sign"],B=528,N=10,O=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],k=crypto.subtle;class C{constructor(t,e){this.password=t,this.signed=e,this.input=e&&new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(t){const e=async(r=0)=>{if(r+R<=i.length-N){const t=i.subarray(r,r+R),s=await k.decrypt(Object.assign({counter:this.counter},_),this.keys.decrypt,t);return V(this.counter),n.set(new Uint8Array(s),r),e(r+R)}return this.pendingInput=i.subarray(r),this.signed&&(this.input=j(this.input,t)),n};if(this.password){const e=t.subarray(0,18);await async function(t,e,n){t.counter=new Uint8Array(O);const i=e.subarray(0,16),r=e.subarray(16),s=(new TextEncoder).encode(n),a=await k.importKey(D,s,I,!1,T),o=await k.deriveBits(Object.assign({salt:i},L),a,528),c=new Uint8Array(o),h=c.subarray(64);if(t.keys={decrypt:await k.importKey(D,c.subarray(0,32),z,!0,["decrypt"]),authentication:await k.importKey(D,c.subarray(32,64),S,!1,M),passwordVerification:h},h[0]!=r[0]||h[1]!=r[1])throw new Error(E)}(this,e,this.password),this.password=null,t=t.subarray(18)}let n=new Uint8Array(t.length-N-(t.length-N)%R),i=t;return this.pendingInput.length&&(i=j(this.pendingInput,t),n=W(n,i.length-N-(i.length-N)%R)),e()}async flush(){const t=this.pendingInput,e=this.keys,n=t.subarray(0,t.length-N),i=t.subarray(t.length-N);let r=new Uint8Array(0);if(n.length){const t=await k.decrypt(Object.assign({counter:this.counter},_),e.decrypt,n);r=new Uint8Array(t)}let s=!0;if(this.signed){const t=await k.sign(F,e.authentication,this.input.subarray(0,this.input.length-N)),n=new Uint8Array(t);this.input=null;for(let t=0;t{if(r+R<=t.length){const s=t.subarray(r,r+R),a=await k.encrypt(Object.assign({counter:this.counter},_),this.keys.encrypt,s);return V(this.counter),i.set(new Uint8Array(a),r+n.length),e(r+R)}return this.pendingInput=t.subarray(r),this.output=j(this.output,i),i};let n=new Uint8Array(0);this.password&&(n=await async function(t,e){t.counter=new Uint8Array(O);const n=crypto.getRandomValues(new Uint8Array(16)),i=(new TextEncoder).encode(e),r=await k.importKey(D,i,I,!1,T),s=await k.deriveBits(Object.assign({salt:n},L),r,B),a=new Uint8Array(s);return t.keys={encrypt:await k.importKey(D,a.subarray(0,32),z,!0,["encrypt"]),authentication:await k.importKey(D,a.subarray(32,64),S,!1,M),passwordVerification:a.subarray(64)},j(n,t.keys.passwordVerification)}(this,this.password),this.password=null);let i=new Uint8Array(n.length+t.length-t.length%R);return i.set(n,0),this.pendingInput.length&&(t=j(this.pendingInput,t),i=W(i,t.length-t.length%R)),e()}async flush(){let t=new Uint8Array(0);if(this.pendingInput.length){const e=await k.encrypt(Object.assign({counter:this.counter},_),this.keys.encrypt,this.pendingInput);t=new Uint8Array(e),this.output=j(this.output,t)}const e=await k.sign(F,this.keys.authentication,this.output.subarray(18));this.output=null;const n=new Uint8Array(e).subarray(0,N);return{data:j(t,n),signature:n}}}function V(t){for(let e=0;e<16;e++){if(255!=t[e]){t[e]++;break}t[e]=0}}function j(t,e){let n=t;return t.length+e.length&&(n=new Uint8Array(t.length+e.length),n.set(t,0),n.set(e,t.length)),n}function W(t,e){if(e&&e>t.length){const n=t;(t=new Uint8Array(e)).set(n,0)}return t}const H="deflate",Z="inflate",q="Invalid signature";class K{constructor(t){this.signature=t.inputSignature,this.encrypted=Boolean(t.inputPassword),this.signed=t.inputSigned,this.compressed=t.inputCompressed,this.inflate=this.compressed&&new ZipInflate,this.crc32=this.signed&&this.signed&&new A,this.decrypt=this.encrypted&&new C(t.inputPassword)}async append(t){return this.encrypted&&(t=await this.decrypt.append(t)),this.compressed&&t.length&&(t=await this.inflate.append(t)),!this.encrypted&&this.signed&&this.crc32.append(t),t}async flush(){let t,e=new Uint8Array(0);if(this.encrypted){const t=await this.decrypt.flush();if(!t.valid)throw new Error(q);e=t.data}else if(this.signed){const e=new DataView(new Uint8Array(4).buffer);if(t=this.crc32.get(),e.setUint32(0,t),this.signature!=e.getUint32(0,!1))throw new Error(q)}return this.compressed&&(e=await this.inflate.append(e)||new Uint8Array(0),await this.inflate.flush()),{data:e,signature:t}}}class X{constructor(t){this.encrypted=t.outputEncrypted,this.signed=t.outputSigned,this.compressed=t.outputCompressed,this.deflate=this.compressed&&new ZipDeflate({level:t.level||5}),this.crc32=this.signed&&new A,this.encrypt=this.encrypted&&new P(t.outputPassword)}async append(t){let e=t;return this.compressed&&t.length&&(e=await this.deflate.append(t)),this.encrypted?e=await this.encrypt.append(e):this.signed&&this.crc32.append(t),e}async flush(){let t,e=new Uint8Array(0);if(this.compressed&&(e=await this.deflate.flush()||new Uint8Array(0)),this.encrypted){e=await this.encrypt.append(e);const n=await this.encrypt.flush();t=n.signature;const i=new Uint8Array(e.length+n.data.length);i.set(e,0),i.set(n.data,e.length),e=i}else this.signed&&(t=this.crc32.get());return{data:e,signature:t}}}const Y="init",G="append",J="flush",Q="message",$="z-worker.js",tt={deflate:[$,"deflate.js"],inflate:[$,"inflate.js"]},et={pool:[],pendingRequests:[]};function nt(t,e){const n=et.pool;let i;if(t.useWebWorkers){const n=e.codecType;if(null!=t.workerScripts&&null!=t.workerScriptsPath)throw new Error("Either workerScripts or workerScriptsPath may be set, not both");if(t.workerScripts){if(i=t.workerScripts[n],!Array.isArray(i))throw new Error("workerScripts."+n+" must be an array");r=i,i="undefined"!=typeof document?r.map((t=>new URL(t,document.baseURI).href)):r}else i=tt[n].slice(0),i[0]=(t.workerScriptsPath||"")+i[0]}var r;if(n.lengthi({type:G,data:t}),flush:async()=>i({type:J})},t.interface;async function i(e){if(!n){const e=t.scripts.slice(1);await r(Object.assign({type:Y,options:t.options,scripts:e}))}return r(e)}function r(i){try{if(i.data)try{e.postMessage(i,[i.data.buffer])}catch(t){e.postMessage(i)}else e.postMessage(i)}catch(e){n.reject(e),n=null,st(t)}return new Promise(((t,e)=>n={resolve:t,reject:e}))}function s(e){const i=e.data;if(n){const e=i.error;if(e){const i=new Error(e.message);i.stack=e.stack,n.reject(i),n=null,st(t)}else i.type!=Y&&i.type!=J&&i.type!=G||(i.type==J?(n.resolve({data:new Uint8Array(i.data),signature:i.signature}),n=null,st(t)):n.resolve(i.data&&new Uint8Array(i.data)))}}}(t):it(t)}{const t=n.find((t=>!t.busy));return t?(t.busy=!0,t.options=e,t.scripts=i,i?t.interface:it(t)):new Promise((t=>et.pendingRequests.push({resolve:t,options:e,scripts:i})))}}function it(t){const e=(n=t.options).codecType.startsWith(H)?new X(n):n.codecType.startsWith(Z)?new K(n):void 0;var n;const i=e.append.bind(e),r=e.flush.bind(e);return e.append=async e=>{try{return await i(e)}catch(e){throw await rt(t),e}},e.flush=async()=>{try{return await r()}finally{await rt(t)}},e}async function rt(t){if(t.busy=!1,et.pendingRequests.length){const[{resolve:e,options:n}]=et.pendingRequests.splice(0,1);t.busy=!0,t.options=n,e(it(t))}else et.pool=et.pool.filter((e=>e!=t))}function st(t){if(t.busy=!1,et.pendingRequests.length){const[{resolve:e,options:n,scripts:i}]=et.pendingRequests.splice(0,1);t.busy=!0,t.options=n,t.scripts=i,e(t.interface)}else t.worker.terminate(),et.pool=et.pool.filter((e=>e!=t))}async function at(t,e,n,i,r,s,a){const o=Math.max(s.chunkSize,64);return async function s(c=0,h=0){const l=c*o;if(l>1,dataDescriptor:8==(8&i),languageEncodingFlag:2048==(2048&i)},t.encrypted=t.bitFlag.encrypted,t.rawLastModDate=e.getUint32(n+6,!0),t.lastModDate=function(t){const e=(4294901760&t)>>16,n=65535&t;try{return new Date(1980+((65024&e)>>9),((480&e)>>5)-1,31&e,(63488&n)>>11,(2016&n)>>5,2*(31&n),0)}catch(t){}}(t.rawLastModDate),t.filenameLength=e.getUint16(n+22,!0),t.extraFieldLength=e.getUint16(n+24,!0)}function Rt(t,e,n,i){let r,s,a;const o=e.rawExtraField,c=e.extraField=new Map,h=new DataView(new Uint8Array(o).buffer);let d=0;try{for(;de[t]==l));for(let e=0;e{if(e[n]==l){if(!t||void 0===t[n])throw new Error(gt);e[n]=t&&t[n]}}))}(r,e),a=e.extraFieldUnicodePath=c.get(28789),a&&function(t,e,n){const i=new DataView(t.data.buffer);t.version=i.getUint8(0),t.signature=i.getUint32(1,!0);const r=new A;r.append(n.rawFilename);const s=new DataView(new Uint8Array(4).buffer);s.setUint32(0,r.get()),t.filename=(new TextDecoder).decode(t.data.subarray(5)),t.signature==s.getUint32(0,!1)&&(e.filename=t.filename)}(a,e,t),s=e.extraFieldAES=c.get(39169),s?function(t,e,n){if(t){const i=new DataView(t.data.buffer);t.vendorVersion=i.getUint8(0),t.vendorId=i.getUint8(2);const r=i.getUint8(4);t.strength=r,t.originalCompressionMethod=n,e.compressionMethod=t.compressionMethod=i.getUint16(5,!0)}else e.compressionMethod=n}(s,e,u):e.compressionMethod=u,8==e.compressionMethod&&(e.bitFlag.enhancedDeflating=16!=(16&e.rawBitFlag))}function Dt(t,e){return new TextDecoder(e).decode(t)}const xt="File already exists",Ft="Zip file comment exceeds 64KB",vt="File entry comment exceeds 64KB",zt="File entry name exceeds 64KB",It="Version exceeds 65535",Lt="Extra field type exceeds 65535",St="Extra field data exceeds 64KB",_t=new Uint8Array([7,0,2,0,65,69,3,0,0]);function Tt(t){return unescape(encodeURIComponent(t))}function Mt(t){const e=[];for(let n=0;n{if(this.pendingData){const e=this.pendingData;this.pendingData=new Uint8Array(e.length+t.length),this.pendingData.set(e,0),this.pendingData.set(t,e.length)}else this.pendingData=new Uint8Array(t)};if(this.codec=new t(Object.assign({},e,n)),typeof this.codec.onData==Bt)this.codec.onData=i;else{if(typeof this.codec.on!=Bt)throw new Error("Cannot register the callback function");this.codec.on("data",i)}}async append(t){return this.codec.push(t),n(this)}async flush(){return this.codec.push(new Uint8Array(0),!0),n(this)}};function n(t){if(t.pendingData){const e=t.pendingData;return t.pendingData=null,e}return new Uint8Array(0)}}const Ot={chunkSize:524288,maxWorkers:"undefined"!=typeof navigator&&navigator.hardwareConcurrency||2,workerScriptsPath:void 0,useWebWorkers:!0};let kt=Object.assign({},Ot);t.BlobReader=o,t.BlobWriter=class extends a{constructor(t){super(),this.offset=0,this.contentType=t,this.blob=new Blob([],{type:t})}writeUint8Array(t){super.writeUint8Array(t),this.blob=new Blob([this.blob,t.buffer],{type:this.contentType}),this.offset=this.blob.size}getData(){return this.blob}},t.Data64URIReader=class extends s{constructor(t){super(),this.dataURI=t;let e=t.length;for(;"="==t.charAt(e-1);)e--;this.dataStart=t.indexOf(",")+1,this.size=Math.floor(.75*(e-this.dataStart))}readUint8Array(t,e){const n=new Uint8Array(e),i=4*Math.floor(t/3),r=atob(this.dataURI.substring(i+this.dataStart,4*Math.ceil((t+e)/3)+this.dataStart)),s=t-3*Math.floor(i/4);for(let t=s;t2?this.data+=btoa(n):this.pending=n}getData(){return this.data+btoa(this.pending)}},t.ERR_BAD_FORMAT=ct,t.ERR_CENTRAL_DIRECTORY_NOT_FOUND=ut,t.ERR_DUPLICATED_NAME=xt,t.ERR_ENCRYPTED=ft,t.ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND=dt,t.ERR_EOCDR_NOT_FOUND=ht,t.ERR_EOCDR_ZIP64_NOT_FOUND=lt,t.ERR_EXTRAFIELD_ZIP64_NOT_FOUND=gt,t.ERR_HTTP_RANGE=n,t.ERR_INVALID_COMMENT=Ft,t.ERR_INVALID_ENTRY_COMMENT=vt,t.ERR_INVALID_ENTRY_NAME=zt,t.ERR_INVALID_EXTRAFIELD_DATA=St,t.ERR_INVALID_EXTRAFIELD_TYPE=Lt,t.ERR_INVALID_PASSORD=E,t.ERR_INVALID_SIGNATURE=q,t.ERR_INVALID_VERSION=It,t.ERR_LOCAL_FILE_HEADER_NOT_FOUND=pt,t.ERR_UNSUPPORTED_COMPRESSION=yt,t.ERR_UNSUPPORTED_ENCRYPTION=wt,t.HttpRangeReader=class extends s{constructor(t){super(),this.url=t}init(){return super.init(),new Promise(((t,i)=>{const r=new XMLHttpRequest;r.addEventListener("load",(()=>{r.status<400?(this.size=Number(r.getResponseHeader("Content-Length")),"bytes"==r.getResponseHeader("Accept-Ranges")?t():i(new Error(n))):i(e+(r.statusText||r.status)+".")}),!1),r.addEventListener("error",i,!1),r.open("HEAD",this.url),r.send()}))}readUint8Array(t,n){return new Promise(((i,r)=>{const s=new XMLHttpRequest;s.open("GET",this.url),s.responseType="arraybuffer",s.setRequestHeader("Range","bytes="+t+"-"+(t+n-1)),s.addEventListener("load",(()=>{s.status<400?i(new Uint8Array(s.response)):r(e+(s.statusText||s.status)+".")}),!1),s.addEventListener("error",r,!1),s.send()}))}},t.HttpReader=class extends s{constructor(t){super(),this.url=t}async init(){if(super.init(),function(t){if("undefined"!=typeof document){const e=document.createElement("a");return e.href=t,"http:"==e.protocol||"https:"==e.protocol}return/^https?:\/\//i.test(t)}(this.url))return new Promise(((t,n)=>{const i=new XMLHttpRequest;i.addEventListener("load",(()=>{i.status<400?(this.size=Number(i.getResponseHeader("Content-Length")),this.size?t():h().then((()=>t())).catch(n)):n(e+(i.statusText||i.status)+".")}),!1),i.addEventListener("error",n,!1),i.open("HEAD",this.url),i.send()}));await h()}async readUint8Array(t,e){return this.data||await h(this,this.url),new Uint8Array(this.data.subarray(t,t+e))}},t.Reader=s,t.TextReader=class extends s{constructor(t){super(),this.blobReader=new o(new Blob([t],{type:i}))}init(){super.init(),this.blobReader.init(),this.size=this.blobReader.size}readUint8Array(t,e){return this.blobReader.readUint8Array(t,e)}},t.TextWriter=class extends a{constructor(t){super(),this.encoding=t,this.blob=new Blob([],{type:i})}writeUint8Array(t){super.writeUint8Array(t),this.blob=new Blob([this.blob,t.buffer],{type:i})}getData(){const t=new FileReader;return new Promise(((e,n)=>{t.onload=t=>e(t.target.result),t.onerror=n,t.readAsText(this.blob,this.encoding)}))}},t.Uint8ArrayReader=class extends s{constructor(t){super(),this.array=t,this.size=t.length}readUint8Array(t,e){return this.array.slice(t,t+e)}},t.Uint8ArrayWriter=c,t.Writer=a,t.ZipReader=class extends class{constructor(t,e={},n={}){this.reader=t,this.options=e,this.config=n}async getEntries(){const t=this.reader;t.initialized||await t.init();const e=await async function(t,e,n,i){const r=new Uint8Array(4);if(new DataView(r.buffer).setUint32(0,e),t.size=0;t--)if(s[t]==r[0]&&s[t+1]==r[1]&&s[t+2]==r[2]&&s[t+3]==r[3])return{offset:i,buffer:s.slice(t,t+n).buffer}}}(t,f,22,d);let n,i=new DataView(e.buffer),r=i.getUint32(16,!0),s=i.getUint16(8,!0);if(r==l||s==d){n=!0;const i=await t.readUint8Array(e.offset-20,20),a=new DataView(i.buffer);if(Number(a.getUint32(0,!1))!=y)throw new Error(lt);r=Number(a.getBigUint64(8,!0));const o=await t.readUint8Array(r,56),c=new DataView(o.buffer);if(Number(c.getUint32(0,!1))!=w)throw new Error(dt);s=Number(c.getBigUint64(24,!0)),r-=Number(c.getBigUint64(40,!0))}if(r<0||!n&&(r>=t.size||s>=d))throw new Error(ct);const a=await t.readUint8Array(r,t.size-r);i=new DataView(a.buffer);const o=[];let c=0;for(let t=0;td)throw new Error(vt);n.zip64=n.zip64||this.zip64,await async function(t,e,n,i){const r=t.files,s=t.writer;let a;r.set(e,null);try{let o,h;try{i.bufferedWrite||t.options.bufferedWrite||t.lockWrite?(o=new c,o.init()):(t.lockWrite=new Promise((t=>a=t)),s.initialized||await s.init(),o=s),(t.offset>=l||n&&(n.size>=l||t.offset+n.size>=l))&&(i.zip64=!0),h=await async function(t,e,n,i,r,s){const a=Mt(Tt(t)),o=s.lastModDate||new Date,c=new Uint8Array(26),h=new DataView(c.buffer),g=void 0===s.password?r.password:s.password,f=g&&g.length&&g,w=void 0===s.level?r.level:s.level,y=0!==w&&!s.directory,A=void 0===g||!g.length,E=s.zip64;let R;if(f){R=new Uint8Array(_t.length+2);new DataView(R.buffer).setUint16(0,U,!0),R.set(_t,2)}else R=new Uint8Array(0);const D={zip64:E,headerArray:c,directory:s.directory,filename:a,comment:s.comment,extraFieldZip64:E?new Uint8Array(28):new Uint8Array(0),extraFieldAES:R,rawExtraField:new Uint8Array(0)},x=s.extraField;if(a.length>d)throw new Error(zt);if(x){let t=4,e=0;x.forEach((e=>t+=e.length));const n=D.rawExtraField=new Uint8Array(t);x.forEach(((t,i)=>{if(i>d)throw new Error(Lt);if(t.length>d)throw new Error(St);n.set(new Uint16Array([i]),e),n.set(new Uint16Array([t.length]),e+2),n.set(t,e+4),e+=4+t.length}))}if(s.bitFlag=8,s.version=(void 0===s.version?r.version:s.version)||20,s.version>d)throw new Error(It);s.compressionMethod=0,y&&(s.compressionMethod=8);E&&(s.version=s.version>b?s.version:b);f&&(D.encrypted=!0,s.version=s.version>m?s.version:m,s.bitFlag=1|s.bitFlag,s.compressionMethod=99,y&&(D.extraFieldAES[9]=8));h.setUint16(0,s.version,!0),h.setUint16(2,s.bitFlag,!0),h.setUint16(4,s.compressionMethod,!0),h.setUint16(6,(o.getHours()<<6|o.getMinutes())<<5|o.getSeconds()/2,!0),h.setUint16(8,(o.getFullYear()-1980<<4|o.getMonth()+1)<<5|o.getDate(),!0),h.setUint16(22,a.length,!0),h.setUint16(24,0,!0);const F=new Uint8Array(30+a.length);let v;if(new DataView(F.buffer).setUint32(0,u),F.set(c,4),F.set(a,30),e){e.initialized||await e.init();const t=await nt(i,{codecType:H,level:w,outputPassword:g,outputSigned:A,outputCompressed:y,outputEncrypted:Boolean(g)});await n.writeUint8Array(F),v=await at(t,e,n,0,e.size,i,{onprogress:s.onprogress}),D.compressedSize=v.length}else await n.writeUint8Array(F);const z=new Uint8Array(E?24:16),I=new DataView(z.buffer);if(I.setUint32(0,p),e)if(f||void 0===v.signature||(h.setUint32(10,v.signature,!0),I.setUint32(4,v.signature,!0)),E){h.setUint32(14,l,!0),I.setBigUint64(8,BigInt(D.compressedSize),!0),h.setUint32(18,l,!0),I.setBigUint64(16,BigInt(e.size),!0);const t=new DataView(D.extraFieldZip64.buffer);t.setUint16(0,1,!0),t.setUint16(2,24,!0),t.setBigUint64(4,BigInt(e.size),!0),t.setBigUint64(12,BigInt(D.compressedSize),!0)}else h.setUint32(14,D.compressedSize,!0),I.setUint32(8,D.compressedSize,!0),h.setUint32(18,e.size,!0),I.setUint32(12,e.size,!0);return await n.writeUint8Array(z),D.length=F.length+(v?v.length:0)+z.length,D}(e,n,o,t.config,t.options,i)}catch(t){throw r.delete(e),t}if(r.set(e,h),o!=s&&(t.lockWrite&&await t.lockWrite,await s.writeUint8Array(o.getData())),h.offset=t.offset,h.zip64){new DataView(h.extraFieldZip64.buffer).setBigUint64(20,BigInt(h.offset),!0)}t.offset+=h.length}finally{a&&(t.lockWrite=null,a())}}(this,t,e,n)}async close(t){const e=this.writer,n=this.files;let i=0,r=0,s=this.offset,a=n.size;if(t&&t.length){if(!(t.length<=d))throw new Error(Ft);c.setUint16(i+20,t.length,!0)}for(const[,t]of n)r+=46+t.filename.length+t.comment.length+t.extraFieldZip64.length+t.extraFieldAES.length+t.rawExtraField.length;(s+r>=l||a>=d)&&(this.zip64=!0);const o=new Uint8Array(r+(this.zip64?98:22)),c=new DataView(o.buffer);this.options.version=this.options.version||20;for(const[,t]of n){const e=t.filename,n=t.extraFieldZip64,r=t.extraFieldAES,s=n.length+r.length+t.rawExtraField.length;c.setUint32(i,g),t.zip64&&c.setUint16(i+4,this.options.version>b?this.options:b,!0),t.encrypted?c.setUint16(i+4,this.options.version>m?this.options:m,!0):c.setUint16(i+4,this.options.version>20?this.options:20,!0),o.set(t.headerArray,i+6),c.setUint16(i+30,s,!0),c.setUint16(i+32,t.comment.length,!0),t.directory&&c.setUint8(i+38,16),t.zip64?c.setUint32(i+42,l,!0):c.setUint32(i+42,t.offset,!0),o.set(e,i+46),o.set(n,i+46+e.length),o.set(r,i+46+e.length+n.length),o.set(t.rawExtraField,46+e.length+n.length+r.length),o.set(t.comment,i+46+e.length+s),i+=46+e.length+s+t.comment.length}return this.zip64&&(c.setUint32(i,w),c.setBigUint64(i+4,BigInt(44),!0),c.setUint16(i+12,45,!0),c.setUint16(i+14,45,!0),c.setBigUint64(i+24,BigInt(a),!0),c.setBigUint64(i+32,BigInt(a),!0),c.setBigUint64(i+40,BigInt(r),!0),c.setBigUint64(i+48,BigInt(s),!0),c.setUint32(i+56,y),c.setBigUint64(i+64,BigInt(s+r),!0),c.setUint32(i+72,1,!0),a=d,s=l,i+=76),c.setUint32(i,f),c.setUint16(i+8,a,!0),c.setUint16(i+10,a,!0),c.setUint32(i+12,r,!0),c.setUint32(i+16,s,!0),await e.writeUint8Array(o),t&&t.length&&await e.writeUint8Array(t),e.getData()}}{constructor(t,e){super(t,e,kt)}},t.configure=function(t){kt=Object.assign({},kt,t)},t.getMimeType=function(){return"application/octet-stream"},t.initShimAsyncCodec=(t,e={})=>({ZipDeflate:Nt(t.Deflate,e.deflate),ZipInflate:Nt(t.Inflate,e.inflate)}),Object.defineProperty(t,"__esModule",{value:!0})})); +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).zip={})}(this,(function(t){"use strict";const e="HTTP error ",n="HTTP Range not supported",i="text/plain";class r{constructor(){this.size=0}init(){this.initialized=!0}}class s extends r{}class a extends r{writeUint8Array(t){this.size+=t.length}}class o extends s{constructor(t){super(),this.blob=t,this.size=t.size}readUint8Array(t,e){const n=new FileReader;return new Promise(((i,r)=>{n.onload=t=>i(new Uint8Array(t.target.result)),n.onerror=r,n.readAsArrayBuffer(this.blob.slice(t,t+e))}))}}class c extends a{constructor(){super(),this.array=new Uint8Array(0)}writeUint8Array(t){super.writeUint8Array(t);const e=this.array;this.array=new Uint8Array(e.length+t.length),this.array.set(e),this.array.set(t,e.length)}getData(){return this.array}}function h(t,n){return new Promise(((i,r)=>{const s=new XMLHttpRequest;s.addEventListener("load",(()=>{s.status<400?(t.size||(t.size=Number(s.getResponseHeader("Content-Length"))||Number(s.response.byteLength)),t.data=new Uint8Array(s.response),i()):r(e+(s.statusText||s.status)+".")}),!1),s.addEventListener("error",r,!1),s.open("GET",n),s.responseType="arraybuffer",s.send()}))}const d=4294967295,l=65535,u=1347093252,p=1347094280,g=1347092738,f=1347093766,w=1347094022,y=1347094023,U=39169,b=2048,m=45,A=51;class E{constructor(){this.crc=-1,this.table=(()=>{const t=[];for(let e=0;e<256;e++){let n=e;for(let t=0;t<8;t++)1&n?n=n>>>1^3988292384:n>>>=1;t[e]=n}return t})()}append(t){const e=this.table;let n=0|this.crc;for(let i=0,r=0|t.length;i>>8^e[255&(n^t[i])];this.crc=n}get(){return~this.crc}}const R="Invalid pasword",D=16,x="raw",F={name:"PBKDF2"},v={name:"HMAC"},z="SHA-1",I={name:"AES-CTR"},S=Object.assign({hash:v},F),L=Object.assign({iterations:1e3,hash:{name:z}},F),_=Object.assign({hash:z},v),T=Object.assign({length:D},I),k=["deriveBits"],M=["sign"],B=528,N=10,O=[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],C=crypto.subtle;class W{constructor(t,e){this.password=t,this.signed=e,this.input=e&&new Uint8Array(0),this.pendingInput=new Uint8Array(0)}async append(t){const e=async(r=0)=>{if(r+D<=i.length-N){const t=i.subarray(r,r+D),s=await C.decrypt(Object.assign({counter:this.counter},T),this.keys.decrypt,t);return V(this.counter),n.set(new Uint8Array(s),r),e(r+D)}return this.pendingInput=i.subarray(r),this.signed&&(this.input=j(this.input,t)),n};if(this.password){const e=t.subarray(0,18);await async function(t,e,n){t.counter=new Uint8Array(O);const i=e.subarray(0,16),r=e.subarray(16),s=(new TextEncoder).encode(n),a=await C.importKey(x,s,S,!1,k),o=await C.deriveBits(Object.assign({salt:i},L),a,528),c=new Uint8Array(o),h=c.subarray(64);if(t.keys={decrypt:await C.importKey(x,c.subarray(0,32),I,!0,["decrypt"]),authentication:await C.importKey(x,c.subarray(32,64),_,!1,M),passwordVerification:h},h[0]!=r[0]||h[1]!=r[1])throw new Error(R)}(this,e,this.password),this.password=null,t=t.subarray(18)}let n=new Uint8Array(t.length-N-(t.length-N)%D),i=t;return this.pendingInput.length&&(i=j(this.pendingInput,t),n=H(n,i.length-N-(i.length-N)%D)),e()}async flush(){const t=this.pendingInput,e=this.keys,n=t.subarray(0,t.length-N),i=t.subarray(t.length-N);let r=new Uint8Array(0);if(n.length){const t=await C.decrypt(Object.assign({counter:this.counter},T),e.decrypt,n);r=new Uint8Array(t)}let s=!0;if(this.signed){const t=await C.sign(v,e.authentication,this.input.subarray(0,this.input.length-N)),n=new Uint8Array(t);this.input=null;for(let t=0;t{if(r+D<=t.length){const s=t.subarray(r,r+D),a=await C.encrypt(Object.assign({counter:this.counter},T),this.keys.encrypt,s);return V(this.counter),i.set(new Uint8Array(a),r+n.length),e(r+D)}return this.pendingInput=t.subarray(r),this.output=j(this.output,i),i};let n=new Uint8Array(0);this.password&&(n=await async function(t,e){t.counter=new Uint8Array(O);const n=crypto.getRandomValues(new Uint8Array(16)),i=(new TextEncoder).encode(e),r=await C.importKey(x,i,S,!1,k),s=await C.deriveBits(Object.assign({salt:n},L),r,B),a=new Uint8Array(s);return t.keys={encrypt:await C.importKey(x,a.subarray(0,32),I,!0,["encrypt"]),authentication:await C.importKey(x,a.subarray(32,64),_,!1,M),passwordVerification:a.subarray(64)},j(n,t.keys.passwordVerification)}(this,this.password),this.password=null);let i=new Uint8Array(n.length+t.length-t.length%D);return i.set(n,0),this.pendingInput.length&&(t=j(this.pendingInput,t),i=H(i,t.length-t.length%D)),e()}async flush(){let t=new Uint8Array(0);if(this.pendingInput.length){const e=await C.encrypt(Object.assign({counter:this.counter},T),this.keys.encrypt,this.pendingInput);t=new Uint8Array(e),this.output=j(this.output,t)}const e=await C.sign(v,this.keys.authentication,this.output.subarray(18));this.output=null;const n=new Uint8Array(e).subarray(0,N);return{data:j(t,n),signature:n}}}function V(t){for(let e=0;e<16;e++){if(255!=t[e]){t[e]++;break}t[e]=0}}function j(t,e){let n=t;return t.length+e.length&&(n=new Uint8Array(t.length+e.length),n.set(t,0),n.set(e,t.length)),n}function H(t,e){if(e&&e>t.length){const n=t;(t=new Uint8Array(e)).set(n,0)}return t}const Z="deflate",K="inflate",q="Invalid signature";class X{constructor(t){this.signature=t.inputSignature,this.encrypted=Boolean(t.inputPassword),this.signed=t.inputSigned,this.compressed=t.inputCompressed,this.inflate=this.compressed&&new ZipInflate,this.crc32=this.signed&&this.signed&&new E,this.decrypt=this.encrypted&&new W(t.inputPassword)}async append(t){return this.encrypted&&(t=await this.decrypt.append(t)),this.compressed&&t.length&&(t=await this.inflate.append(t)),!this.encrypted&&this.signed&&this.crc32.append(t),t}async flush(){let t,e=new Uint8Array(0);if(this.encrypted){const t=await this.decrypt.flush();if(!t.valid)throw new Error(q);e=t.data}else if(this.signed){const e=new DataView(new Uint8Array(4).buffer);if(t=this.crc32.get(),e.setUint32(0,t),this.signature!=e.getUint32(0,!1))throw new Error(q)}return this.compressed&&(e=await this.inflate.append(e)||new Uint8Array(0),await this.inflate.flush()),{data:e,signature:t}}}class Y{constructor(t){this.encrypted=t.outputEncrypted,this.signed=t.outputSigned,this.compressed=t.outputCompressed,this.deflate=this.compressed&&new ZipDeflate({level:t.level||5}),this.crc32=this.signed&&new E,this.encrypt=this.encrypted&&new P(t.outputPassword)}async append(t){let e=t;return this.compressed&&t.length&&(e=await this.deflate.append(t)),this.encrypted?e=await this.encrypt.append(e):this.signed&&this.crc32.append(t),e}async flush(){let t,e=new Uint8Array(0);if(this.compressed&&(e=await this.deflate.flush()||new Uint8Array(0)),this.encrypted){e=await this.encrypt.append(e);const n=await this.encrypt.flush();t=n.signature;const i=new Uint8Array(e.length+n.data.length);i.set(e,0),i.set(n.data,e.length),e=i}else this.signed&&(t=this.crc32.get());return{data:e,signature:t}}}const G="init",J="append",Q="flush",$="z-worker.js",tt={deflate:[$,"deflate.js"],inflate:[$,"inflate.js"]},et={pool:[],pendingRequests:[]};function nt(t,e){const n=et.pool,i=!(e.inputCompressed||e.inputSigned||e.inputEncrypted||e.outputCompressed||e.outputSigned||e.outputEncrypted);let r;if(e.useWebWorkers||void 0===e.useWebWorkers&&t.useWebWorkers&&!i){const n=e.codecType;if(null!=t.workerScripts&&null!=t.workerScriptsPath)throw new Error("Either workerScripts or workerScriptsPath may be set, not both");if(t.workerScripts){if(r=t.workerScripts[n],!Array.isArray(r))throw new Error("workerScripts."+n+" must be an array");s=r,r="undefined"!=typeof document?s.map((t=>new URL(t,document.baseURI).href)):s}else r=tt[n].slice(0),r[0]=(t.workerScriptsPath||"")+r[0]}var s;if(n.length!t.busy));return t?it(t):new Promise((t=>et.pendingRequests.push({resolve:t,options:e,scripts:r})))}}function it(t,e,n){return t.busy=!0,t.options=e,t.scripts=n,n?st(t):rt(t)}function rt(t){const e=(n=t.options).codecType.startsWith(Z)?new Y(n):n.codecType.startsWith(K)?new X(n):void 0;var n;const i=e.append.bind(e),r=e.flush.bind(e);return e.append=async e=>{try{return await i(e)}catch(e){throw at(t),e}},e.flush=async()=>{try{return await r()}finally{at(t)}},e}function st(t){let e;return t.interface||(t.worker=new Worker(t.scripts[0]),t.worker.addEventListener("message",(function(n){const i=n.data;if(e){const n=i.error;if(n){const i=new Error(n.message);i.stack=n.stack,e.reject(i),e=null,at(t)}else i.type!=G&&i.type!=Q&&i.type!=J||(i.type==Q?(e.resolve({data:new Uint8Array(i.data),signature:i.signature}),e=null,at(t)):e.resolve(i.data&&new Uint8Array(i.data)))}}),!1),t.interface={append:t=>n({type:J,data:t}),flush:()=>n({type:Q})}),t.interface;async function n(n){if(!e){const e=t.scripts.slice(1);await i(Object.assign({type:G,options:t.options,scripts:e}))}return i(n)}function i(n){const i=t.worker,r=new Promise(((t,n)=>e={resolve:t,reject:n}));try{if(n.data)try{i.postMessage(n,[n.data.buffer])}catch(t){i.postMessage(n)}else i.postMessage(n)}catch(n){e.reject(n),e=null,at(t)}return r}}function at(t){if(t.busy=!1,et.pendingRequests.length){const[{resolve:e,options:n,scripts:i}]=et.pendingRequests.splice(0,1);e(it(t,n,i))}else t.worker&&t.worker.terminate(),et.pool=et.pool.filter((e=>e!=t))}async function ot(t,e,n,i,r,s,a){const o=Math.max(s.chunkSize,64);return async function s(c=0,h=0){const d=c*o;if(d>1,dataDescriptor:8==(8&i),languageEncodingFlag:(i&b)==b},t.encrypted=t.bitFlag.encrypted,t.rawLastModDate=e.getUint32(n+6,!0),t.lastModDate=function(t){const e=(4294901760&t)>>16,n=65535&t;try{return new Date(1980+((65024&e)>>9),((480&e)>>5)-1,31&e,(63488&n)>>11,(2016&n)>>5,2*(31&n),0)}catch(t){}}(t.rawLastModDate),t.filenameLength=e.getUint16(n+22,!0),t.extraFieldLength=e.getUint16(n+24,!0)}function Dt(t,e,n,i){const r=e.rawExtraField,s=e.extraField=new Map,a=new DataView(new Uint8Array(r).buffer);let o=0;try{for(;oe[t]==d));for(let e=0;e{if(e[n]==d){if(!t||void 0===t[n])throw new Error(ft);e[n]=t&&t[n]}}))}(h,e);const l=e.extraFieldUnicodePath=s.get(28789);l&&xt(l,"filename","rawFilename",e,t);let u=e.extraFieldUnicodeComment=s.get(25461);u&&xt(u,"comment","rawComment",e,t);const p=e.extraFieldAES=s.get(39169);p?function(t,e,n){if(t){const i=new DataView(t.data.buffer);t.vendorVersion=i.getUint8(0),t.vendorId=i.getUint8(2);const r=i.getUint8(4);t.strength=r,t.originalCompressionMethod=n,e.compressionMethod=t.compressionMethod=i.getUint16(5,!0)}else e.compressionMethod=n}(p,e,c):e.compressionMethod=c,8==e.compressionMethod&&(e.bitFlag.enhancedDeflating=16!=(16&e.rawBitFlag))}function xt(t,e,n,i,r){const s=new DataView(t.data.buffer);t.version=s.getUint8(0),t.signature=s.getUint32(1,!0);const a=new E;a.append(r[n]);const o=new DataView(new Uint8Array(4).buffer);o.setUint32(0,a.get()),t[e]=(new TextDecoder).decode(t.data.subarray(5)),t.signature==o.getUint32(0,!1)&&(i[e]=t[e])}function Ft(t,e){return new TextDecoder(e).decode(t)}const vt="File already exists",zt="Zip file comment exceeds 64KB",It="File entry comment exceeds 64KB",St="File entry name exceeds 64KB",Lt="Version exceeds 65535",_t="Extra field type exceeds 65535",Tt="Extra field data exceeds 64KB",kt=new Uint8Array([7,0,2,0,65,69,3,0,0]);function Mt(t){return unescape(encodeURIComponent(t))}function Bt(t){const e=[];for(let n=0;n{if(this.pendingData){const e=this.pendingData;this.pendingData=new Uint8Array(e.length+t.length),this.pendingData.set(e,0),this.pendingData.set(t,e.length)}else this.pendingData=new Uint8Array(t)};if(this.codec=new t(Object.assign({},e,n)),typeof this.codec.onData==Nt)this.codec.onData=i;else{if(typeof this.codec.on!=Nt)throw new Error("Cannot register the callback function");this.codec.on("data",i)}}async append(t){return this.codec.push(t),n(this)}async flush(){return this.codec.push(new Uint8Array(0),!0),n(this)}};function n(t){if(t.pendingData){const e=t.pendingData;return t.pendingData=null,e}return new Uint8Array(0)}}const Ct={chunkSize:524288,maxWorkers:"undefined"!=typeof navigator&&navigator.hardwareConcurrency||2,workerScriptsPath:void 0,useWebWorkers:!0};let Wt=Object.assign({},Ct);t.BlobReader=o,t.BlobWriter=class extends a{constructor(t){super(),this.offset=0,this.contentType=t,this.blob=new Blob([],{type:t})}writeUint8Array(t){super.writeUint8Array(t),this.blob=new Blob([this.blob,t.buffer],{type:this.contentType}),this.offset=this.blob.size}getData(){return this.blob}},t.Data64URIReader=class extends s{constructor(t){super(),this.dataURI=t;let e=t.length;for(;"="==t.charAt(e-1);)e--;this.dataStart=t.indexOf(",")+1,this.size=Math.floor(.75*(e-this.dataStart))}readUint8Array(t,e){const n=new Uint8Array(e),i=4*Math.floor(t/3),r=atob(this.dataURI.substring(i+this.dataStart,4*Math.ceil((t+e)/3)+this.dataStart)),s=t-3*Math.floor(i/4);for(let t=s;t2?this.data+=btoa(n):this.pending=n}getData(){return this.data+btoa(this.pending)}},t.ERR_BAD_FORMAT=ht,t.ERR_CENTRAL_DIRECTORY_NOT_FOUND=pt,t.ERR_DUPLICATED_NAME=vt,t.ERR_ENCRYPTED=wt,t.ERR_EOCDR_LOCATOR_ZIP64_NOT_FOUND=ut,t.ERR_EOCDR_NOT_FOUND=dt,t.ERR_EOCDR_ZIP64_NOT_FOUND=lt,t.ERR_EXTRAFIELD_ZIP64_NOT_FOUND=ft,t.ERR_HTTP_RANGE=n,t.ERR_INVALID_COMMENT=zt,t.ERR_INVALID_ENTRY_COMMENT=It,t.ERR_INVALID_ENTRY_NAME=St,t.ERR_INVALID_EXTRAFIELD_DATA=Tt,t.ERR_INVALID_EXTRAFIELD_TYPE=_t,t.ERR_INVALID_PASSORD=R,t.ERR_INVALID_SIGNATURE=q,t.ERR_INVALID_VERSION=Lt,t.ERR_LOCAL_FILE_HEADER_NOT_FOUND=gt,t.ERR_UNSUPPORTED_COMPRESSION=Ut,t.ERR_UNSUPPORTED_ENCRYPTION=yt,t.HttpRangeReader=class extends s{constructor(t){super(),this.url=t}init(){return super.init(),new Promise(((t,i)=>{const r=new XMLHttpRequest;r.addEventListener("load",(()=>{r.status<400?(this.size=Number(r.getResponseHeader("Content-Length")),"bytes"==r.getResponseHeader("Accept-Ranges")?t():i(new Error(n))):i(e+(r.statusText||r.status)+".")}),!1),r.addEventListener("error",i,!1),r.open("HEAD",this.url),r.send()}))}readUint8Array(t,n){return new Promise(((i,r)=>{const s=new XMLHttpRequest;s.open("GET",this.url),s.responseType="arraybuffer",s.setRequestHeader("Range","bytes="+t+"-"+(t+n-1)),s.addEventListener("load",(()=>{s.status<400?i(new Uint8Array(s.response)):r(e+(s.statusText||s.status)+".")}),!1),s.addEventListener("error",r,!1),s.send()}))}},t.HttpReader=class extends s{constructor(t){super(),this.url=t}async init(){if(super.init(),function(t){if("undefined"!=typeof document){const e=document.createElement("a");return e.href=t,"http:"==e.protocol||"https:"==e.protocol}return/^https?:\/\//i.test(t)}(this.url))return new Promise(((t,n)=>{const i=new XMLHttpRequest;i.addEventListener("load",(()=>{i.status<400?(this.size=Number(i.getResponseHeader("Content-Length")),this.size?t():h().then((()=>t())).catch(n)):n(e+(i.statusText||i.status)+".")}),!1),i.addEventListener("error",n,!1),i.open("HEAD",this.url),i.send()}));await h()}async readUint8Array(t,e){return this.data||await h(this,this.url),new Uint8Array(this.data.subarray(t,t+e))}},t.Reader=s,t.TextReader=class extends s{constructor(t){super(),this.blobReader=new o(new Blob([t],{type:i}))}init(){super.init(),this.blobReader.init(),this.size=this.blobReader.size}readUint8Array(t,e){return this.blobReader.readUint8Array(t,e)}},t.TextWriter=class extends a{constructor(t){super(),this.encoding=t,this.blob=new Blob([],{type:i})}writeUint8Array(t){super.writeUint8Array(t),this.blob=new Blob([this.blob,t.buffer],{type:i})}getData(){const t=new FileReader;return new Promise(((e,n)=>{t.onload=t=>e(t.target.result),t.onerror=n,t.readAsText(this.blob,this.encoding)}))}},t.Uint8ArrayReader=class extends s{constructor(t){super(),this.array=t,this.size=t.length}readUint8Array(t,e){return this.array.slice(t,t+e)}},t.Uint8ArrayWriter=c,t.Writer=a,t.ZipReader=class extends class{constructor(t,e={},n={}){this.reader=t,this.options=e,this.config=n}async getEntries(){const t=this.reader;t.initialized||await t.init();const e=await async function(t,e,n,i){const r=new Uint8Array(4);if(new DataView(r.buffer).setUint32(0,e),t.size=0;t--)if(s[t]==r[0]&&s[t+1]==r[1]&&s[t+2]==r[2]&&s[t+3]==r[3])return{offset:i,buffer:s.slice(t,t+n).buffer}}}(t,f,22,l);if(!e)throw new Error(dt);const n=new DataView(e.buffer);let i,r=n.getUint32(16,!0),s=n.getUint16(8,!0);if(r==d||s==l){i=!0;const n=await t.readUint8Array(e.offset-20,20),a=new DataView(n.buffer);if(Number(a.getUint32(0,!1))!=y)throw new Error(lt);r=Number(a.getBigUint64(8,!0));const o=await t.readUint8Array(r,56),c=new DataView(o.buffer);if(Number(c.getUint32(0,!1))!=w)throw new Error(ut);s=Number(c.getBigUint64(24,!0)),r-=Number(c.getBigUint64(40,!0))}if(r<0||!i&&(r>=t.size||s>=l))throw new Error(ht);const a=await t.readUint8Array(r,t.size-r),o=new DataView(a.buffer),c=[];let h=0;for(let t=0;tl)throw new Error(It);n.zip64=n.zip64||this.zip64,await async function(t,e,n,i){const r=t.files,s=t.writer;let a;r.set(e,null);try{let o,h;try{i.bufferedWrite||t.options.bufferedWrite||t.lockWrite?(o=new c,o.init()):(t.lockWrite=new Promise((t=>a=t)),s.initialized||await s.init(),o=s),(t.offset>=d||n&&(n.size>=d||t.offset+n.size>=d))&&(i.zip64=!0),h=await async function(t,e,n,i,r,s){const a=Bt(Mt(t)),o=s.lastModDate||new Date,c=new Uint8Array(26),h=new DataView(c.buffer),g=void 0===s.password?r.password:s.password,f=g&&g.length&&g,w=void 0===s.level?r.level:s.level,y=0!==w&&!s.directory,b=void 0===g||!g.length,E=s.zip64;let R;if(f){R=new Uint8Array(kt.length+2);new DataView(R.buffer).setUint16(0,U,!0),R.set(kt,2)}else R=new Uint8Array(0);const D={zip64:E,headerArray:c,directory:s.directory,filename:a,comment:s.comment,extraFieldZip64:E?new Uint8Array(28):new Uint8Array(0),extraFieldAES:R,rawExtraField:new Uint8Array(0)},x=s.extraField;if(a.length>l)throw new Error(St);if(x){let t=4,e=0;x.forEach((e=>t+=e.length));const n=D.rawExtraField=new Uint8Array(t);x.forEach(((t,i)=>{if(i>l)throw new Error(_t);if(t.length>l)throw new Error(Tt);n.set(new Uint16Array([i]),e),n.set(new Uint16Array([t.length]),e+2),n.set(t,e+4),e+=4+t.length}))}if(s.bitFlag=2056,s.version=(void 0===s.version?r.version:s.version)||20,s.version>l)throw new Error(Lt);s.compressionMethod=0,y&&(s.compressionMethod=8);E&&(s.version=s.version>m?s.version:m);f&&(D.encrypted=!0,s.version=s.version>A?s.version:A,s.bitFlag=1|s.bitFlag,s.compressionMethod=99,y&&(D.extraFieldAES[9]=8));h.setUint16(0,s.version,!0),h.setUint16(2,s.bitFlag,!0),h.setUint16(4,s.compressionMethod,!0),h.setUint16(6,(o.getHours()<<6|o.getMinutes())<<5|o.getSeconds()/2,!0),h.setUint16(8,(o.getFullYear()-1980<<4|o.getMonth()+1)<<5|o.getDate(),!0),h.setUint16(22,a.length,!0),h.setUint16(24,0,!0);const F=new Uint8Array(30+a.length);let v;if(new DataView(F.buffer).setUint32(0,u),F.set(c,4),F.set(a,30),e){e.initialized||await e.init();const t=await nt(i,{codecType:Z,level:w,outputPassword:g,outputSigned:b,outputCompressed:y,outputEncrypted:Boolean(g),useWebWorkers:void 0===s.useWebWorkers?r.useWebWorkers:s.useWebWorkers});await n.writeUint8Array(F),v=await ot(t,e,n,0,e.size,i,{onprogress:s.onprogress}),D.compressedSize=v.length}else await n.writeUint8Array(F);const z=new Uint8Array(E?24:16),I=new DataView(z.buffer);if(I.setUint32(0,p),e)if(f||void 0===v.signature||(h.setUint32(10,v.signature,!0),I.setUint32(4,v.signature,!0)),E){h.setUint32(14,d,!0),I.setBigUint64(8,BigInt(D.compressedSize),!0),h.setUint32(18,d,!0),I.setBigUint64(16,BigInt(e.size),!0);const t=new DataView(D.extraFieldZip64.buffer);t.setUint16(0,1,!0),t.setUint16(2,24,!0),t.setBigUint64(4,BigInt(e.size),!0),t.setBigUint64(12,BigInt(D.compressedSize),!0)}else h.setUint32(14,D.compressedSize,!0),I.setUint32(8,D.compressedSize,!0),h.setUint32(18,e.size,!0),I.setUint32(12,e.size,!0);return await n.writeUint8Array(z),D.length=F.length+(v?v.length:0)+z.length,D}(e,n,o,t.config,t.options,i)}catch(t){throw r.delete(e),t}if(r.set(e,h),o!=s&&(t.lockWrite&&await t.lockWrite,await s.writeUint8Array(o.getData())),h.offset=t.offset,h.zip64){new DataView(h.extraFieldZip64.buffer).setBigUint64(20,BigInt(h.offset),!0)}t.offset+=h.length}finally{a&&(t.lockWrite=null,a())}}(this,t,e,n)}async close(t){const e=this.writer,n=this.files;let i=0,r=0,s=this.offset,a=n.size;if(t&&t.length){if(!(t.length<=l))throw new Error(zt);c.setUint16(i+20,t.length,!0)}for(const[,t]of n)r+=46+t.filename.length+t.comment.length+t.extraFieldZip64.length+t.extraFieldAES.length+t.rawExtraField.length;(s+r>=d||a>=l)&&(this.zip64=!0);const o=new Uint8Array(r+(this.zip64?98:22)),c=new DataView(o.buffer);this.options.version=this.options.version||20;for(const[,t]of n){const e=t.filename,n=t.extraFieldZip64,r=t.extraFieldAES,s=n.length+r.length+t.rawExtraField.length;c.setUint32(i,g),t.zip64&&c.setUint16(i+4,this.options.version>m?this.options:m,!0),t.encrypted?c.setUint16(i+4,this.options.version>A?this.options:A,!0):c.setUint16(i+4,this.options.version>20?this.options:20,!0),o.set(t.headerArray,i+6),c.setUint16(i+30,s,!0),c.setUint16(i+32,t.comment.length,!0),t.directory&&c.setUint8(i+38,16),t.zip64?c.setUint32(i+42,d,!0):c.setUint32(i+42,t.offset,!0),o.set(e,i+46),o.set(n,i+46+e.length),o.set(r,i+46+e.length+n.length),o.set(t.rawExtraField,46+e.length+n.length+r.length),o.set(t.comment,i+46+e.length+s),i+=46+e.length+s+t.comment.length}return this.zip64&&(c.setUint32(i,w),c.setBigUint64(i+4,BigInt(44),!0),c.setUint16(i+12,45,!0),c.setUint16(i+14,45,!0),c.setBigUint64(i+24,BigInt(a),!0),c.setBigUint64(i+32,BigInt(a),!0),c.setBigUint64(i+40,BigInt(r),!0),c.setBigUint64(i+48,BigInt(s),!0),c.setUint32(i+56,y),c.setBigUint64(i+64,BigInt(s+r),!0),c.setUint32(i+72,1,!0),a=l,s=d,i+=76),c.setUint32(i,f),c.setUint16(i+8,a,!0),c.setUint16(i+10,a,!0),c.setUint32(i+12,r,!0),c.setUint32(i+16,s,!0),await e.writeUint8Array(o),t&&t.length&&await e.writeUint8Array(t),e.getData()}}{constructor(t,e){super(t,e,Wt)}},t.configure=function(t){Wt=Object.assign({},Wt,t)},t.getMimeType=function(){return"application/octet-stream"},t.initShimAsyncCodec=(t,e={})=>({ZipDeflate:Ot(t.Deflate,e.deflate),ZipInflate:Ot(t.Inflate,e.inflate)}),Object.defineProperty(t,"__esModule",{value:!0})})); diff --git a/package.json b/package.json index 02adfd8c..160195ca 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "description": "A JavaScript library to zip and unzip files in the browser", "author": "Gildas Lormeau", "license": "BSD-3-Clause", - "version": "2.0.5", + "version": "2.0.6", "keywords": [ "zip", "unzip",