brotli/js/decode.min.js

1 line
148 KiB
JavaScript
Raw Normal View History

export let BrotliDecode=(()=>{const f=Int32Array.from([256,402,436,468,500,534,566,598,630,662,694,726,758,790,822,854,886,920,952,984,1016,1048,1080]),w=Int32Array.from([1,2,3,4,0,5,17,6,16,7,8,9,10,11,12,13,14,15]),b=Int32Array.from([0,3,2,1,0,0,0,0,0,0,3,3,3,3,3,3]),j=Int32Array.from([0,0,0,0,-1,1,-2,2,-3,3,-1,1,-2,2,-3,3]),l=Int32Array.from([131072,131076,131075,196610,131072,131076,131075,262145,131072,131076,131075,196610,131072,131076,131075,262149]),m=Int32Array.from([1,5,9,13,17,25,33,41,49,65,81,97,113,145,177,209,241,305,369,497,753,1265,2289,4337,8433,16625]),p=Int32Array.from([2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,7,8,9,10,11,12,13,24]),q=Int16Array.from([0,0,0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,7,8,9,10,12,14,24]),o=Int16Array.from([0,0,0,0,0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,7,8,9,10,24]),n=new Int16Array(2816);function g(f){let w=-1,b=16,j=f;for(;b>0;){let f=j>>>b;0!==f&&(w+=b,j=f),b>>=1}return w+j}function k(f,w,b){return 16+w+2*(b<<f)}function s(f,w,b){if(f<b+(2<<w))throw new Error("maxDistance is too small");const j=4+(f-b>>w),l=g(j)-1;return((l-1<<1|j>>l&1)-1<<w)+(1<<w)+b+16}function t(f){if(0!==f.j)throw new Error("State MUST be uninitialized");f.l=new Int32Array(3091),f.l[0]=7,f.m=3;const w=s(2147483644,3,120);f.p=new Int8Array(w),f.q=new Int32Array(w),function(f){f.o=new Int8Array(4160),f.g=0,f.k=new Int16Array(2080),f.s=32,f.t=2048,f.v=0,M(f)}(f),f.j=1}function v(f){if(f.s>=16&&(f.g=f.k[f.t++]<<16|f.g>>>16,f.s-=16),0!==J(f,1)){const w=J(f,3);return 0===w?1:J(f,w)+(1<<w)}return 0}function e(f,w,b){let j=f[w];const l=b.g>>>b.s;j+=255&l;const m=f[j]>>16,p=65535&f[j];if(m<=8)return b.s+=m,p;j+=p;return j+=(l&(1<<m)-1)>>>8,b.s+=8+(f[j]>>16),65535&f[j]}function d(f,w,b){b.s>=16&&(b.g=b.k[b.t++]<<16|b.g>>>16,b.s-=16);const j=e(f,w,b),l=p[j];return b.s>=16&&(b.g=b.k[b.t++]<<16|b.g>>>16,b.s-=16),m[j]+(l<=16?J(b,l):_(b,l))}function H(f,w){let b=w;const j=f[b];for(;b>0;)f[b]=f[b-1],b--;f[0]=j}function a(f,w,b,j,l){const m=new Int32Array(w),p=new Int32Array(4),q=1+g(f-1),o=J(l,2)+1;for(let f=0;f<o;++f){l.s>=16&&(l.g=l.k[l.t++]<<16|l.g>>>16,l.s-=16);const b=J(l,q);if(b>=w)throw new Error("Can't readHuffmanCode");p[f]=b}!function(f,w){for(let b=0;b<w-1;++b)for(let j=b+1;j<w;++j)if(f[b]===f[j])throw new Error("Duplicate simple Huffman code symbol")}(p,o);let n=o;switch(4===o&&(n+=J(l,1)),n){case 1:m[p[0]]=1;break;case 2:m[p[0]]=1,m[p[1]]=1;break;case 3:m[p[0]]=1,m[p[1]]=2,m[p[2]]=2;break;case 4:m[p[0]]=2,m[p[1]]=2,m[p[2]]=2,m[p[3]]=2;break;case 5:m[p[0]]=1,m[p[1]]=2,m[p[2]]=3,m[p[3]]=3}return U(b,j,8,m,w)}function u(f,b,j,m,p){const q=new Int32Array(f),o=new Int32Array(18);let n=32,g=0;for(let f=b;f<18;++f){const b=w[f];p.s>=16&&(p.g=p.k[p.t++]<<16|p.g>>>16,p.s-=16);const j=p.g>>>p.s&15;p.s+=l[j]>>16;const m=65535&l[j];if(o[b]=m,0!==m&&(n-=32>>m,g++,n<=0))break}if(0!==n&&1!==g)throw new Error("Corrupted Huffman code histogram");return function(f,w,b,j){let l=0,m=8,p=0,q=0,o=32768;const n=new Int32Array(33);for(U(n,n.length-1,5,f,18);l<w&&o>0;){j.t>2030&&E(j),j.s>=16&&(j.g=j.k[j.t++]<<16|j.g>>>16,j.s-=16);const f=j.g>>>j.s&31;j.s+=n[f]>>16;const g=65535&n[f];if(g<16)p=0,b[l++]=g,0!==g&&(m=g,o-=32768>>g);else{const f=g-14;let n=0;16===g&&(n=m),q!==n&&(p=0,q=n);const k=p;p>0&&(p-=2,p<<=f),j.s>=16&&(j.g=j.k[j.t++]<<16|j.g>>>16,j.s-=16),p+=J(j,f)+3;const s=p-k;if(l+s>w)throw new Error("symbol + repeatDelta > numSymbols");for(let f=0;f<s;++f)b[l++]=q;0!==q&&(o-=s<<15-q)}}if(0!==o)throw new Error("Unused space");b.fill(0,l,w)}(o,f,q,p),U(j,m,8,q,f)}function z(f,w,b,j,l){l.t>2030&&E(l),l.s>=16&&(l.g=l.k[l.t++]<<16|l.g>>>16,l.s-=16);const m=J(l,2);return 1===m?a(f,w,b,j,l):u(w,m,b,j,l)}function h(w,b,j){j.t>2030&&E(j);const l=v(j)+1;if(1===l)return b.fill(0,0,w),l;j.s>=16&&(j.g=j.k[j.t++]<<16|j.g>>>16,j.s-=16);let m=0;0!==J(j,1)&&(m=J(j,4)+1);const p=l+m,q=f[p+31>>5],o=new Int32Array(q+1),n=o.length-1;z(p,p,o,n,j);let g=0;for(;g<w;){j.t>2030&&E(j),j.s>=16&&(j.g=j.k[j.t++]<<16|j.g>>>16,j.s-=16);const f=e(o,n,j);if(0===f)b[g]=0,g++;else if(f<=m){j.s>=16&&(j.g=j.k[j.t++]<<16|j.g>>>16,j.s-=16);let l=(1<<f)+J(j,f);for(;0!==l;){if(g>=w)thro