-
The docs say If there was a build with just these 4 functions, I'd be extremely grateful! ❤️ |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I made a build that exports those four functions in ESM format for you. Here's the file (~9kB, 4.5kB gzipped): var r=Uint8Array,n=Uint16Array,e=Uint32Array,a=new r([0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0,0,0,0]),f=new r([0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,0,0]),t=new r([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),o=function(r,a){for(var f=new n(31),t=0;t<31;++t)f[t]=a+=1<<r[t-1];var o=new e(f[30]);for(t=1;t<30;++t)for(var i=f[t];i<f[t+1];++i)o[i]=i-f[t]<<5|t;return[f,o]},i=o(a,2),u=i[0],v=i[1];u[28]=258,v[258]=28;for(var l=o(f,0),c=l[0],s=l[1],h=new n(32768),g=0;g<32768;++g){var w=(43690&g)>>>1|(21845&g)<<1;w=(61680&(w=(52428&w)>>>2|(13107&w)<<2))>>>4|(3855&w)<<4,h[g]=((65280&w)>>>8|(255&w)<<8)>>>1}var d=function(r,e,a){for(var f=r.length,t=0,o=new n(e);t<f;++t)r[t]&&++o[r[t]-1];var i,u=new n(e);for(t=0;t<e;++t)u[t]=u[t-1]+o[t-1]<<1;if(a){i=new n(1<<e);var v=15-e;for(t=0;t<f;++t)if(r[t])for(var l=t<<4|r[t],c=e-r[t],s=u[r[t]-1]++<<c,g=s|(1<<c)-1;s<=g;++s)i[h[s]>>>v]=l}else for(i=new n(f),t=0;t<f;++t)r[t]&&(i[t]=h[u[r[t]-1]++]>>>15-r[t]);return i},m=new r(288);for(g=0;g<144;++g)m[g]=8;for(g=144;g<256;++g)m[g]=9;for(g=256;g<280;++g)m[g]=7;for(g=280;g<288;++g)m[g]=8;var b=new r(32);for(g=0;g<32;++g)b[g]=5;var y=d(m,9,0),p=d(m,9,1),E=d(b,5,0),M=d(b,5,1),k=function(r){for(var n=r[0],e=1;e<r.length;++e)r[e]>n&&(n=r[e]);return n},C=function(r,n,e){var a=n/8|0;return(r[a]|r[a+1]<<8)>>(7&n)&e},T=function(r,n){var e=n/8|0;return(r[e]|r[e+1]<<8|r[e+2]<<16)>>(7&n)},x=function(r){return(r+7)/8|0},S=function(a,f,t){(null==f||f<0)&&(f=0),(null==t||t>a.length)&&(t=a.length);var o=new(2==a.BYTES_PER_ELEMENT?n:4==a.BYTES_PER_ELEMENT?e:r)(t-f);return o.set(a.subarray(f,t)),o},A=["unexpected EOF","invalid block type","invalid length/literal","invalid distance","stream finished","no stream handler",,"no callback","invalid UTF-8 data","extra field too long","date not in range 1980-2099","filename too long","stream finishing","invalid zip data"],U=function(r,n,e){var a=new Error(n||A[r]);if(a.code=r,Error.captureStackTrace&&Error.captureStackTrace(a,U),!e)throw a;return a},_=function(n,e,o){var i=n.length;if(!i||o&&o.f&&!o.l)return e||new r(0);var v=!e||o,l=!o||o.i;o||(o={}),e||(e=new r(3*i));var s=function(n){var a=e.length;if(n>a){var f=new r(Math.max(2*a,n));f.set(e),e=f}},h=o.f||0,g=o.p||0,w=o.b||0,m=o.l,b=o.d,y=o.m,E=o.n,A=8*i;do{if(!m){h=C(n,g,1);var _=C(n,g+1,3);if(g+=3,!_){var q=n[(j=x(g)+4)-4]|n[j-3]<<8,B=j+q;if(B>i){l&&U(0);break}v&&s(w+q),e.set(n.subarray(j,B),w),o.b=w+=q,o.p=g=8*B,o.f=h;continue}if(1==_)m=p,b=M,y=9,E=5;else if(2==_){var D=C(n,g,31)+257,F=C(n,g+10,15)+4,L=D+C(n,g+5,31)+1;g+=14;for(var N=new r(L),P=new r(19),R=0;R<F;++R)P[t[R]]=C(n,g+3*R,7);g+=3*F;var Y=k(P),z=(1<<Y)-1,O=d(P,Y,1);for(R=0;R<L;){var j,G=O[C(n,g,z)];if(g+=15&G,(j=G>>>4)<16)N[R++]=j;else{var H=0,I=0;for(16==j?(I=3+C(n,g,3),g+=2,H=N[R-1]):17==j?(I=3+C(n,g,7),g+=3):18==j&&(I=11+C(n,g,127),g+=7);I--;)N[R++]=H}}var J=N.subarray(0,D),K=N.subarray(D);y=k(J),E=k(K),m=d(J,y,1),b=d(K,E,1)}else U(1);if(g>A){l&&U(0);break}}v&&s(w+131072);for(var Q=(1<<y)-1,V=(1<<E)-1,W=g;;W=g){var X=(H=m[T(n,g)&Q])>>>4;if((g+=15&H)>A){l&&U(0);break}if(H||U(2),X<256)e[w++]=X;else{if(256==X){W=g,m=null;break}var Z=X-254;if(X>264){var $=a[R=X-257];Z=C(n,g,(1<<$)-1)+u[R],g+=$}var rr=b[T(n,g)&V],nr=rr>>>4;rr||U(3),g+=15&rr;K=c[nr];if(nr>3){$=f[nr];K+=T(n,g)&(1<<$)-1,g+=$}if(g>A){l&&U(0);break}v&&s(w+131072);for(var er=w+Z;w<er;w+=4)e[w]=e[w-K],e[w+1]=e[w+1-K],e[w+2]=e[w+2-K],e[w+3]=e[w+3-K];w=er}}o.l=m,o.p=W,o.b=w,o.f=h,m&&(h=1,o.m=y,o.d=b,o.n=E)}while(!h);return w==e.length?e:S(e,0,w)},q=function(r,n,e){e<<=7&n;var a=n/8|0;r[a]|=e,r[a+1]|=e>>>8},B=function(r,n,e){e<<=7&n;var a=n/8|0;r[a]|=e,r[a+1]|=e>>>8,r[a+2]|=e>>>16},D=function(e,a){for(var f=[],t=0;t<e.length;++t)e[t]&&f.push({s:t,f:e[t]});var o=f.length,i=f.slice();if(!o)return[z,0];if(1==o){var u=new r(f[0].s+1);return u[f[0].s]=1,[u,1]}f.sort((function(r,n){return r.f-n.f})),f.push({s:-1,f:25001});var v=f[0],l=f[1],c=0,s=1,h=2;for(f[0]={s:-1,f:v.f+l.f,l:v,r:l};s!=o-1;)v=f[f[c].f<f[h].f?c++:h++],l=f[c!=s&&f[c].f<f[h].f?c++:h++],f[s++]={s:-1,f:v.f+l.f,l:v,r:l};var g=i[0].s;for(t=1;t<o;++t)i[t].s>g&&(g=i[t].s);var w=new n(g+1),d=F(f[s-1],w,0);if(d>a){t=0;var m=0,b=d-a,y=1<<b;for(i.sort((function(r,n){return w[n.s]-w[r.s]||r.f-n.f}));t<o;++t){var p=i[t].s;if(!(w[p]>a))break;m+=y-(1<<d-w[p]),w[p]=a}for(m>>>=b;m>0;){var E=i[t].s;w[E]<a?m-=1<<a-w[E]++-1:++t}for(;t>=0&&m;--t){var M=i[t].s;w[M]==a&&(--w[M],++m)}d=a}return[new r(w),d]},F=function(r,n,e){return-1==r.s?Math.max(F(r.l,n,e+1),F(r.r,n,e+1)):n[r.s]=e},L=function(r){for(var e=r.length;e&&!r[--e];);for(var a=new n(++e),f=0,t=r[0],o=1,i=function(r){a[f++]=r},u=1;u<=e;++u)if(r[u]==t&&u!=e)++o;else{if(!t&&o>2){for(;o>138;o-=138)i(32754);o>2&&(i(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(i(t),--o;o>6;o-=6)i(8304);o>2&&(i(o-3<<5|8208),o=0)}for(;o--;)i(t);o=1,t=r[u]}return[a.subarray(0,f),e]},N=function(r,n){for(var e=0,a=0;a<n.length;++a)e+=r[a]*n[a];return e},P=function(r,n,e){var a=e.length,f=x(n+2);r[f]=255&a,r[f+1]=a>>>8,r[f+2]=255^r[f],r[f+3]=255^r[f+1];for(var t=0;t<a;++t)r[f+t+4]=e[t];return 8*(f+4+a)},R=function(r,e,o,i,u,v,l,c,s,h,g){q(e,g++,o),++u[256];for(var w=D(u,15),p=w[0],M=w[1],k=D(v,15),C=k[0],T=k[1],x=L(p),S=x[0],A=x[1],U=L(C),_=U[0],F=U[1],R=new n(19),Y=0;Y<S.length;++Y)R[31&S[Y]]++;for(Y=0;Y<_.length;++Y)R[31&_[Y]]++;for(var z=D(R,7),O=z[0],j=z[1],G=19;G>4&&!O[t[G-1]];--G);var H,I,J,K,Q=h+5<<3,V=N(u,m)+N(v,b)+l,W=N(u,p)+N(v,C)+l+14+3*G+N(R,O)+(2*R[16]+3*R[17]+7*R[18]);if(Q<=V&&Q<=W)return P(e,g,r.subarray(s,s+h));if(q(e,g,1+(W<V)),g+=2,W<V){H=d(p,M,0),I=p,J=d(C,T,0),K=C;var X=d(O,j,0);q(e,g,A-257),q(e,g+5,F-1),q(e,g+10,G-4),g+=14;for(Y=0;Y<G;++Y)q(e,g+3*Y,O[t[Y]]);g+=3*G;for(var Z=[S,_],$=0;$<2;++$){var rr=Z[$];for(Y=0;Y<rr.length;++Y){var nr=31&rr[Y];q(e,g,X[nr]),g+=O[nr],nr>15&&(q(e,g,rr[Y]>>>5&127),g+=rr[Y]>>>12)}}}else H=y,I=m,J=E,K=b;for(Y=0;Y<c;++Y)if(i[Y]>255){nr=i[Y]>>>18&31;B(e,g,H[nr+257]),g+=I[nr+257],nr>7&&(q(e,g,i[Y]>>>23&31),g+=a[nr]);var er=31&i[Y];B(e,g,J[er]),g+=K[er],er>3&&(B(e,g,i[Y]>>>5&8191),g+=f[er])}else B(e,g,H[i[Y]]),g+=I[i[Y]];return B(e,g,H[256]),g+I[256]},Y=new e([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),z=new r(0),O=function(t,o,i,u,l,c){var h=t.length,g=new r(u+h+5*(1+Math.ceil(h/7e3))+l),w=g.subarray(u,g.length-l),d=0;if(!o||h<8)for(var m=0;m<=h;m+=65535){var b=m+65535;b>=h&&(w[d>>3]=c),d=P(w,d+1,t.subarray(m,b))}else{for(var y=Y[o-1],p=y>>>13,E=8191&y,M=(1<<i)-1,k=new n(32768),C=new n(M+1),T=Math.ceil(i/3),A=2*T,U=function(r){return(t[r]^t[r+1]<<T^t[r+2]<<A)&M},_=new e(25e3),q=new n(288),B=new n(32),D=0,F=0,L=(m=0,0),N=0,O=0;m<h;++m){var j=U(m),G=32767&m,H=C[j];if(k[G]=H,C[j]=G,N<=m){var I=h-m;if((D>7e3||L>24576)&&I>423){d=R(t,w,0,_,q,B,F,L,O,m-O,d),L=D=F=0,O=m;for(var J=0;J<286;++J)q[J]=0;for(J=0;J<30;++J)B[J]=0}var K=2,Q=0,V=E,W=G-H&32767;if(I>2&&j==U(m-W))for(var X=Math.min(p,I)-1,Z=Math.min(32767,m),$=Math.min(258,I);W<=Z&&--V&&G!=H;){if(t[m+K]==t[m+K-W]){for(var rr=0;rr<$&&t[m+rr]==t[m+rr-W];++rr);if(rr>K){if(K=rr,Q=W,rr>X)break;var nr=Math.min(W,rr-2),er=0;for(J=0;J<nr;++J){var ar=m-W+J+32768&32767,fr=ar-k[ar]+32768&32767;fr>er&&(er=fr,H=ar)}}}W+=(G=H)-(H=k[G])+32768&32767}if(Q){_[L++]=268435456|v[K]<<18|s[Q];var tr=31&v[K],or=31&s[Q];F+=a[tr]+f[or],++q[257+tr],++B[or],N=m+K,++D}else _[L++]=t[m],++q[t[m]]}}d=R(t,w,c,_,q,B,F,L,O,m-O,d),!c&&7&d&&(d=P(w,d+1,z))}return S(g,0,u+x(d)+l)},j=function(r,n,e,a,f){return O(r,null==n.level?6:n.level,null==n.mem?Math.ceil(1.5*Math.max(8,Math.min(13,Math.log(r.length)))):12+n.mem,e,a,!f)};function G(r,n){return j(r,n||{},0,0)}function H(r,n){return _(r,n)}var I="undefined"!=typeof TextEncoder&&new TextEncoder,J="undefined"!=typeof TextDecoder&&new TextDecoder;try{J.decode(z,{stream:!0}),1}catch(r){}var K=function(r){for(var n="",e=0;;){var a=r[e++],f=(a>127)+(a>223)+(a>239);if(e+f>r.length)return[n,S(r,e-1)];f?3==f?(a=((15&a)<<18|(63&r[e++])<<12|(63&r[e++])<<6|63&r[e++])-65536,n+=String.fromCharCode(55296|a>>10,56320|1023&a)):n+=1&f?String.fromCharCode((31&a)<<6|63&r[e++]):String.fromCharCode((15&a)<<12|(63&r[e++])<<6|63&r[e++]):n+=String.fromCharCode(a)}};function Q(n,e){if(e){for(var a=new r(n.length),f=0;f<n.length;++f)a[f]=n.charCodeAt(f);return a}if(I)return I.encode(n);var t=n.length,o=new r(n.length+(n.length>>1)),i=0,u=function(r){o[i++]=r};for(f=0;f<t;++f){if(i+5>o.length){var v=new r(i+8+(t-f<<1));v.set(o),o=v}var l=n.charCodeAt(f);l<128||e?u(l):l<2048?(u(192|l>>6),u(128|63&l)):l>55295&&l<57344?(u(240|(l=65536+(1047552&l)|1023&n.charCodeAt(++f))>>18),u(128|l>>12&63),u(128|l>>6&63),u(128|63&l)):(u(224|l>>12),u(128|l>>6&63),u(128|63&l))}return S(o,0,i)}function V(r,n){if(n){for(var e="",a=0;a<r.length;a+=16384)e+=String.fromCharCode.apply(null,r.subarray(a,a+16384));return e}if(J)return J.decode(r);var f=K(r),t=f[0];return f[1].length&&U(8),t}"function"==typeof queueMicrotask?queueMicrotask:"function"==typeof setTimeout&&setTimeout;export{G as deflateSync,H as inflateSync,V as strFromU8,Q as strToU8} You can paste this into e.g. import {inflateSync, deflateSync, strFromU8, strToU8} from './fflate.js';
console.log(strFromU8(inflateSync(deflateSync(strToU8('hello world'))))); There are ways to hand optimize this further but it's not really necessary. Let me know if this works for you! |
Beta Was this translation helpful? Give feedback.
I made a build that exports those four functions in ESM format for you. Here's the file (~9kB, 4.5kB gzipped):