ZSTD 解压缩前端处理方案

这里提供一个 zstd 的解压缩 demo,将获取到的二进制 bin 文件转为可用的数据。




    
    
    
    zstd 解压缩
    


    
    
    

另外提供一个示例中使用到的 zstd.js 资源:

!function(f){typeof module!='undefined'&&typeof exports=='object'?module.exports=f():typeof define!='undefined'&&define.amd?define(f):(typeof self!='undefined'?self:this).fzstd=f()}(function(){var _e={};"use strict";var r=ArrayBuffer,t=Uint8Array,e=Uint16Array,n=Int16Array,a=Uint32Array,s=Int32Array,i=function(r,e,n){if(t.prototype.slice)return t.prototype.slice.call(r,e,n);(null==e||e<0)&&(e=0),(null==n||n>r.length)&&(n=r.length);var a=new t(n-e);return a.set(r.subarray(e,n)),a},o=function(r,e,n,a){if(t.prototype.fill)return t.prototype.fill.call(r,e,n,a);for((null==n||n<0)&&(n=0),(null==a||a>r.length)&&(a=r.length);nr.length)&&(a=r.length);n2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],h=function(r,t,e){var n=Error(t||f[r]);if(n.code=r,Error.captureStackTrace&&Error.captureStackTrace(n,h),!e)throw n;return n},l=function(r,t,e){for(var n=0,a=0;n>>0},c=function(r,e){var n=r[0]|r[1]<<8|r[2]<<16;if(3126568==n&&253==r[3]){var a=r[4],i=a>>5&1,o=a>>2&1,u=3&a,f=a>>6;8&a&&h(0);var c=6-i,b=3==u?4:u,y=l(r,c,b),p=f?1<>3);g=d+(d>>3)*(7&r[5])}g>2145386496&&h(1);var m=new t((1==e?w||g:e?0:g)+12);return m[0]=1,m[4]=4,m[8]=8,{b:c+p,y:0,l:0,d:y,w:e&&1!=e?e:m.subarray(12),e:g,o:new s(m.buffer,0,3),u:w,c:o,m:Math.min(131072,g)}}if(25481893==(n>>4|r[3]<<20))return v(r,4)+8;h(0)},b=function(r){for(var t=0;1<i&&h(3);for(var f=1<0;){var A=b(l+1),T=o>>3,x=(1<>(7&o)&x,S=(1<S&&(F-=B)),g[++v]=--F,-1==F?(l+=F,E[--p]=v):l-=F,!F)do{var U=o>>3;c=(a[U]|a[U+1]<<8)>>(7&o)&3,o+=2,v+=c}while(3==c)}(v>255||l)&&h(0);for(var D=0,M=(f>>1)+(f>>3)+3,W=f-1,O=0;O<=v;++O){var j=g[O];if(j<1)d[O]=-j;else for(y=0;y=p)}}for(D&&h(0),y=0;y>3,{b:u,s:E,n:k,t:m}]},p=function(r,n){var a=0,s=-1,i=new t(292),u=r[n],f=i.subarray(0,256),l=i.subarray(256,268),v=new e(i.buffer,268);if(u<128){var c=y(r,n+1,6),p=c[1],w=c[0]<<3,g=r[n+=u];g||h(0);for(var d=0,m=0,z=p.b,E=z,k=(++n<<3)-8+b(g);!((k-=z)>3;if(f[++s]=p.s[d+=(r[A]|r[A+1]<<8)>>(7&k)&(1<>3]|r[A+1]<<8)>>(7&k)&(1<255&&h(0)}else{for(s=u-127;a>4,f[a+1]=15&T}++n}var x=0;for(a=0;a11&&h(0),x+=I&&1<0;--a){var W=v[a];o(M,a,W,v[a-1]=W+l[a]*(1<o&&v>3;t[++v]=e.s[u=(u<>(7&l))&i],l-=f=e.n[u]}l==o&&v+1==a||h(0)},x=function(r,t,e){var n=6,a=t.length+3>>2,s=a<<1,i=a+s;T(r.subarray(n,n+=r[0]|r[1]<<8),t.subarray(0,a),e),T(r.subarray(n,n+=r[2]|r[3]<<8),t.subarray(a,s),e),T(r.subarray(n,n+=r[4]|r[5]<<8),t.subarray(s,i),e),T(r.subarray(n),t.subarray(i),e)},F=function(r,n,a){var s,u=n.b,f=r[u],l=f>>1&3;n.l=1&f;var v=f>>3|r[u+1]<<5|r[u+2]<<13,c=(u+=3)+v;if(1==l){if(u>=r.length)return;return n.b=u+1,a?(o(a,r[u],n.y,n.y+=v),a):o(new t(v),r[u])}if(!(c>r.length)){if(0==l)return n.b=c,a?(a.set(r.subarray(u,c),n.y),n.y+=v,a):i(r,u,c);if(2==l){var m=r[u],F=3&m,S=m>>2&3,B=m>>4,I=0,U=0;F<2?1&S?B|=r[++u]<<4|(2&S&&r[++u]<<12):B=m>>3:(U=S,S<2?(B|=(63&r[++u])<<4,I=r[u]>>6|r[++u]<<2):2==S?(B|=r[++u]<<4|(3&r[++u])<<12,I=r[u]>>2|r[++u]<<6):(B|=r[++u]<<4|(63&r[++u])<<12,I=r[u]>>6|r[++u]<<2|r[++u]<<10)),++u;var D=a?a.subarray(n.y,n.y+n.m):new t(n.m),M=D.length-B;if(0==F)D.set(r.subarray(u,u+=B),M);else if(1==F)o(D,r[u++],M);else{var W=n.h;if(2==F){var O=p(r,u);I+=u-(u=O[0]),n.h=W=O[1]}else W||h(0);(U?x:T)(r.subarray(u,u+=I),D.subarray(M),W)}var j=r[u++];if(j){255==j?j=32512+(r[u++]|r[u++]<<8):j>127&&(j=j-128<<8|r[u++]);var C=r[u++];3&C&&h(0);for(var H=[g,d,w],L=2;L>-1;--L){var Z=C>>2+(L<<1)&3;if(1==Z){var q=new t([0,0,r[u++]]);H[L]={s:q.subarray(2,3),n:q.subarray(0,1),t:new e(q.buffer,0,1),b:0}}else 2==Z?(u=(s=y(r,u,9-(1&L)))[0],H[L]=s[1]):3==Z&&(n.t||h(0),H[L]=n.t[L])}var G=n.t=H,J=G[0],K=G[1],N=G[2],P=r[c-1];P||h(0);var Q=(c<<3)-8+b(P)-N.b,R=Q>>3,V=0,X=(r[R]|r[R+1]<<8)>>(7&Q)&(1<>3]|r[R+1]<<8)>>(7&Q)&(1<>3]|r[R+1]<<8)>>(7&Q)&(1<>3]|r[R+1]<<8|r[R+2]<<16|r[R+3]<<24)>>>(7&Q)&sr-1);R=(Q-=k[tr])>>3;var or=A[tr]+((r[R]|r[R+1]<<8|r[R+2]<<16)>>(7&Q)&(1<>3;var ur=E[_]+((r[R]|r[R+1]<<8|r[R+2]<<16)>>(7&Q)&(1<>3,X=N.t[X]+((r[R]|r[R+1]<<8)>>(7&Q)&(1<>3,$=J.t[$]+((r[R]|r[R+1]<<8)>>(7&Q)&(1<>3,Y=K.t[Y]+((r[R]|r[R+1]<<8)>>(7&Q)&(1<3)n.o[2]=n.o[1],n.o[1]=n.o[0],n.o[0]=ir-=3;else{var fr=ir-(0!=ur);fr?(ir=3==fr?n.o[0]-1:n.o[fr],fr>1&&(n.o[2]=n.o[1]),n.o[1]=n.o[0],n.o[0]=ir):ir=n.o[0]}for(L=0;Lor&&(lr=or),L=0;L>3|r[this.s.b+1]<<5|r[this.s.b+2]<<13)))return t&&h(5),this.c.push(r),void(this.l=n);for(this.z=0;;){var a=F(r,this.s);if(!a){t&&h(5);var s=r.subarray(this.s.b);return this.s.b=0,this.c.push(s),void(this.l+=s.length)}if(this.ondata(a,!1),u(this.s.w,0,a.length),this.s.w.set(a,this.s.w.length-a.length),this.s.l){var i=r.subarray(this.s.b);return this.s=4*this.s.c,void this.push(i,t)}}}},r}();_e.Decompress=I;return _e})

你可能感兴趣的:(工作总结,前端,javascript,zstd)