question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[124] TiltLoader breaks in a module env

See original GitHub issue

Repro: https://codesandbox.io/s/elegant-villani-9d3hr?file=/src/index.js

import { TiltLoader } from "three/examples/jsm/loaders/TiltLoader"

new TiltLoader().load("/model.tilt", (scene) => console.log(scene))

This is the error message in a local env (Parcel):

TiltLoader.js:42 TypeError: _jszipModuleMin.JSZip is not a constructor
    at TiltLoader.parse (TiltLoader.js:59)
    at Object.onLoad (TiltLoader.js:32)
    at XMLHttpRequest.<anonymous> (three.module.js:36749)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:32 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
101arrowzcommented, Dec 28, 2020

Hi, author of fflate here! The reason the async version exists in JSZip is beyond me, since it doesn’t actually offload the processing to other threads. On the other hand, if the assets in the ZIP are reasonably large (around 500kB), fflate will use worker threads to compress/decompress them faster.

However, I looked at some of the demos using JSZip and they don’t seem to load that much data, so using the synchronous unzipping algorithm would be no different to the async version. You could even replace gunzip.js, which is used by the NRRD loader, with fflate because gunzip and unzip use the same core algorithm.

Since it seems the ThreeJS team wants minified ES6 module scripts, I’ve hand-tuned a minified version of the library and pasted it below. It’s 4.4kB (2.2kB gzipped) and supports synchronous ZIP decompression (through the exported unzipSync method) and GZIP decompression (through gunzipSync).

Usage:

import { unzipSync, strFromU8 } from '../libs/fflate.module.min.js';
let arrayBuffer = ... // From XHR, presumably
const zip = unzipSync(new Uint8Array(arrayBuffer));

// If we were using JSZip, the following would be:
// zip.files['data.xml'].asUint8Array()
const dataXmlU8 = zip['data.xml'];
// zip.files['data.xml'].asArrayBuffer()
const dataXmlBuffer = dataXmlU8.buffer;
// zip.files['data.xml'].asText()
const dataXmlText = strFromU8(dataXmlU8);
import { gunzipSync } from '../libs/fflate.module.min.js';
let arrayBuffer = ... // From XHR, presumably

// If we were using gunzip.js, the following would be:
// const gunzip = new Zlib.Gunzip(new Uint8Array(arrayBuffer));
// const data = gunzip.decompress();
const data = gunzipSync(new Uint8Array(arrayBuffer));

Minified code (to put in fflate.module.min.js):

/*!
fflate - fast JavaScript compression/decompression
<https://101arrowz.github.io/fflate>
Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
Subset included: synchronous unzip and gunzip
*/
"use strict";var r=Uint8Array,n=Uint16Array,e=Uint32Array,t=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]),a=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]),i=new r([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),f=function(r,e){for(var t=new n(31),a=0;a<31;++a)t[a]=e+=1<<r[a-1];return t},o=f(t,2);o[28]=258;for(var u=f(a,0),v=new n(32768),l=0;l<32768;++l){var c=(43690&l)>>>1|(21845&l)<<1;c=(61680&(c=(52428&c)>>>2|(13107&c)<<2))>>>4|(3855&c)<<4,v[l]=((65280&c)>>>8|(255&c)<<8)>>>1}var w=function(r,e){for(var t=r.length,a=0,i=new n(e);a<t;++a)++i[r[a]-1];var f=new n(1<<e),o=new n(e);for(a=0;a<e;++a)o[a]=o[a-1]+i[a-1]<<1;var u=15-e;for(a=0;a<t;++a)if(r[a])for(var l=a<<4|r[a],c=e-r[a],w=o[r[a]-1]++<<c,h=w|(1<<c)-1;w<=h;++w)f[v[w]>>>u]=l;return f},h=new r(288);for(l=0;l<144;++l)h[l]=8;for(l=144;l<256;++l)h[l]=9;for(l=256;l<280;++l)h[l]=7;for(l=280;l<288;++l)h[l]=8;var d=new r(32);for(l=0;l<32;++l)d[l]=5;var s=w(h,9),g=w(d,5),p=function(r){for(var n=r[0],e=1;e<r.length;++e)r[e]>n&&(n=r[e]);return n},y=function(r,n,e){var t=n/8>>0;return(r[t]|r[t+1]<<8)>>>(7&n)&e},b=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/8>>0)+(7&r&&1)},m=function(t,a,i){(null==a||a<0)&&(a=0),(null==i||i>t.length)&&(i=t.length);var f=new(t instanceof n?n:t instanceof e?e:r)(i-a);return f.set(t.subarray(a,i)),f},C=function(n,e,f){var v=n.length,l=!e||f,c=!f||f.i;f||(f={}),e||(e=new r(3*v));var h=function(n){var t=e.length;if(n>t){var a=new r(Math.max(2*t,n));a.set(e),e=a}},d=f.f||0,C=f.p||0,S=f.b||0,k=f.l,F=f.d,z=f.m,E=f.n;if(d&&!k)return e;var O=8*v;do{if(!k){f.f=d=y(n,C,1);var U=y(n,C+1,3);if(C+=3,!U){var A=n[(K=x(C)+4)-4]|n[K-3]<<8,D=K+A;if(D>v){if(c)throw"unexpected EOF";break}l&&h(S+A),e.set(n.subarray(K,D),S),f.b=S+=A,f.p=C=8*D;continue}if(1==U)k=s,F=g,z=9,E=5;else{if(2!=U)throw"invalid block type";var T=y(n,C,31)+257,M=y(n,C+10,15)+4,j=T+y(n,C+5,31)+1;C+=14;for(var q=new r(j),B=new r(19),G=0;G<M;++G)B[i[G]]=y(n,C+3*G,7);C+=3*M;var H=p(B),I=(1<<H)-1;if(!c&&C+j*(H+7)>O)break;var J=w(B,H);for(G=0;G<j;){var K,L=J[y(n,C,I)];if(C+=15&L,(K=L>>>4)<16)q[G++]=K;else{var N=0,P=0;for(16==K?(P=3+y(n,C,3),C+=2,N=q[G-1]):17==K?(P=3+y(n,C,7),C+=3):18==K&&(P=11+y(n,C,127),C+=7);P--;)q[G++]=N}}var Q=q.subarray(0,T),R=q.subarray(T);z=p(Q),E=p(R),k=w(Q,z),F=w(R,E)}if(C>O)throw"unexpected EOF"}l&&h(S+131072);for(var V=(1<<z)-1,W=(1<<E)-1,X=z+E+18;c||C+X<O;){var Y=(N=k[b(n,C)&V])>>>4;if((C+=15&N)>O)throw"unexpected EOF";if(!N)throw"invalid length/literal";if(Y<256)e[S++]=Y;else{if(256==Y){k=null;break}var Z=Y-254;if(Y>264){var $=t[G=Y-257];Z=y(n,C,(1<<$)-1)+o[G],C+=$}var _=F[b(n,C)&W],rr=_>>>4;if(!_)throw"invalid distance";if(C+=15&_,R=u[rr],rr>3&&($=a[rr],R+=b(n,C)&(1<<$)-1,C+=$),C>O)throw"unexpected EOF";l&&h(S+131072);for(var nr=S+Z;S<nr;S+=4)e[S]=e[S-R],e[S+1]=e[S+1-R],e[S+2]=e[S+2-R],e[S+3]=e[S+3-R];S=nr}}f.l=k,f.p=C,f.b=S,k&&(d=1,f.m=z,f.d=F,f.n=E)}while(!d);return S==e.length?e:m(e,0,S)},S=function(r,n){return r[n]|r[n+1]<<8},k=function(r,n){return(r[n]|r[n+1]<<8|r[n+2]<<16)+2*(r[n+3]<<23)},F=function(r){var n="";if("undefined"!=typeof TextDecoder)return(new TextDecoder).decode(r);for(var e=0;e<r.length;){var t=r[e++];t<128?n+=String.fromCharCode(t):t<224?n+=String.fromCharCode((31&t)<<6|63&r[e++]):t<240?n+=String.fromCharCode((15&t)<<12|(63&r[e++])<<6|63&r[e++]):(t=((15&t)<<18|(63&r[e++])<<12|(63&r[e++])<<6|63&r[e++])-65536,n+=String.fromCharCode(55296|t>>10,56320|1023&t))}return n};export var strFromU8=F;var z=function(r,n){S(r,n+8);var e=S(r,n+10),t=k(r,n+20),a=k(r,n+24),i=S(r,n+28);return[t,e,a,F(r.subarray(n+46,n+46+i)),n+46+i+S(r,n+30)+S(r,n+32),k(r,n+42)]};export var unzipSync=function(n){for(var e={},t=n.length-22;101010256!=k(n,t);--t)if(!t||n.length-t>65558)throw"invalid zip file";var a=S(n,t+8);if(!a)return{};for(var i=k(n,t+16),f=0;f<a;++f){var o=z(n,i),u=o[0],v=o[1],l=o[2],c=o[3],w=o[4],h=o[5],d=h+30+S(n,h+26)+S(n,h+28);if(i=w,v){if(8!=v)throw"unknown compression type "+v;e[c]=C(n.subarray(d,d+u),new r(l))}else e[c]=m(n,d,d+u)}return e};export var gunzipSync=function(n){return C(n.subarray(function(r){if(31!=r[0]||139!=r[1]||8!=r[2])throw"invalid gzip data";var n=r[3],e=10;4&n&&(e+=r[10]|2+(r[11]<<8));for(var t=(n>>3&1)+(n>>4&1);t>0;t-=!r[e++]);return e+(2&n)}(n),-8),new r(function(r){var n=r.length;return(r[n-4]|r[n-3]<<8|r[n-2]<<16)+2*(r[n-1]<<23)}(n)))}

Btw, I generally wonder why these aren’t npm dependencies. jszip is here: https://www.npmjs.com/package/jszip Why would threejs use a local copy? If my app already happens to use jszip, it would now serve it twice, not to mention the headache on your side keeping these dependencies up to date.

This duplication issue will still exist if the examples were to use fflate, but since most users seem to think of 4kB as pocket change, it probably doesn’t matter.

3reactions
101arrowzcommented, Dec 31, 2020

I added the ZIP function into fflateDeflate.

fflate-deflate.min.js:

/*!
fflate - fast JavaScript compression/decompression
<https://101arrowz.github.io/fflate>
Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
Subset included: synchronous deflate, synchronous zip
*/
!function(f){typeof exports=="object"&&typeof module!="undefined"?module.exports=f():typeof define=='function'&&define.amd?define([],f):(typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"&&self).fflateDeflate=f()}(function(){"use strict";var _e={},r=Uint8Array,n=Uint16Array,e=Uint32Array,t=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]),a=new r([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),o=function(r,t){for(var f=new n(31),a=0;a<31;++a)f[a]=t+=1<<r[a-1];var o=new e(f[30]);for(a=1;a<30;++a)for(var v=f[a];v<f[a+1];++v)o[v]=v-f[a]<<5|a;return[f,o]},v=o(t,2),i=v[0],u=v[1];i[28]=258,u[258]=28;for(var l=o(f,0),c=(l[0],l[1]),s=new n(32768),h=0;h<32768;++h){var g=(43690&h)>>>1|(21845&h)<<1;g=(61680&(g=(52428&g)>>>2|(13107&g)<<2))>>>4|(3855&g)<<4,s[h]=((65280&g)>>>8|(255&g)<<8)>>>1}var w=function(r,e,t){for(var f=r.length,a=0,o=new n(e);a<f;++a)++o[r[a]-1];var v,i=new n(e);for(a=0;a<e;++a)i[a]=i[a-1]+o[a-1]<<1;if(t){v=new n(1<<e);var u=15-e;for(a=0;a<f;++a)if(r[a])for(var l=a<<4|r[a],c=e-r[a],h=i[r[a]-1]++<<c,g=h|(1<<c)-1;h<=g;++h)v[s[h]>>>u]=l}else for(v=new n(f),a=0;a<f;++a)v[a]=s[i[r[a]-1]++]>>>15-r[a];return v},d=new r(288);for(h=0;h<144;++h)d[h]=8;for(h=144;h<256;++h)d[h]=9;for(h=256;h<280;++h)d[h]=7;for(h=280;h<288;++h)d[h]=8;var m=new r(32);for(h=0;h<32;++h)m[h]=5;var p=w(d,9,0),y=w(m,5,0),M=function(r){return(r/8>>0)+(7&r&&1)},b=function(r,n,e){e<<=7&n;var t=n/8>>0;r[t]|=e,r[t+1]|=e>>>8},x=function(r,n,e){e<<=7&n;var t=n/8>>0;r[t]|=e,r[t+1]|=e>>>8,r[t+2]|=e>>>16},A=function(e,t){for(var f=[],a=0;a<e.length;++a)e[a]&&f.push({s:a,f:e[a]});var o=f.length,v=f.slice();if(!o)return[new r(0),0];if(1==o){var i=new r(f[0].s+1);return i[f[0].s]=1,[i,1]}f.sort((function(r,n){return r.f-n.f})),f.push({s:-1,f:25001});var u=f[0],l=f[1],c=0,s=1,h=2;for(f[0]={s:-1,f:u.f+l.f,l:u,r:l};s!=o-1;)u=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:u.f+l.f,l:u,r:l};var g=v[0].s;for(a=1;a<o;++a)v[a].s>g&&(g=v[a].s);var w=new n(g+1),d=U(f[s-1],w,0);if(d>t){a=0;var m=0,p=d-t,y=1<<p;for(v.sort((function(r,n){return w[n.s]-w[r.s]||r.f-n.f}));a<o;++a){var M=v[a].s;if(!(w[M]>t))break;m+=y-(1<<d-w[M]),w[M]=t}for(m>>>=p;m>0;){var b=v[a].s;w[b]<t?m-=1<<t-w[b]++-1:++a}for(;a>=0&&m;--a){var x=v[a].s;w[x]==t&&(--w[x],++m)}d=t}return[new r(w),d]},U=function(r,n,e){return-1==r.s?Math.max(U(r.l,n,e+1),U(r.r,n,e+1)):n[r.s]=e},D=function(r){for(var e=r.length;e&&!r[--e];);for(var t=new n(++e),f=0,a=r[0],o=1,v=function(r){t[f++]=r},i=1;i<=e;++i)if(r[i]==a&&i!=e)++o;else{if(!a&&o>2){for(;o>138;o-=138)v(32754);o>2&&(v(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(v(a),--o;o>6;o-=6)v(8304);o>2&&(v(o-3<<5|8208),o=0)}for(;o--;)v(a);o=1,a=r[i]}return[t.subarray(0,f),e]},S=function(r,n){for(var e=0,t=0;t<n.length;++t)e+=r[t]*n[t];return e},T=function(r,n,e){var t=e.length,f=M(n+2);r[f]=255&t,r[f+1]=t>>>8,r[f+2]=255^r[f],r[f+3]=255^r[f+1];for(var a=0;a<t;++a)r[f+a+4]=e[a];return 8*(f+4+t)},k=function(r,e,o,v,i,u,l,c,s,h,g){b(e,g++,o),++i[256];for(var M=A(i,15),U=M[0],k=M[1],z=A(u,15),C=z[0],E=z[1],F=D(U),H=F[0],Y=F[1],j=D(C),q=j[0],B=j[1],G=new n(19),I=0;I<H.length;++I)G[31&H[I]]++;for(I=0;I<q.length;++I)G[31&q[I]]++;for(var J=A(G,7),K=J[0],L=J[1],N=19;N>4&&!K[a[N-1]];--N);var O,P,Q,R,V=h+5<<3,W=S(i,d)+S(u,m)+l,X=S(i,U)+S(u,C)+l+14+3*N+S(G,K)+(2*G[16]+3*G[17]+7*G[18]);if(V<=W&&V<=X)return T(e,g,r.subarray(s,s+h));if(b(e,g,1+(X<W)),g+=2,X<W){O=w(U,k,0),P=U,Q=w(C,E,0),R=C;var Z=w(K,L,0);for(b(e,g,Y-257),b(e,g+5,B-1),b(e,g+10,N-4),g+=14,I=0;I<N;++I)b(e,g+3*I,K[a[I]]);g+=3*N;for(var $=[H,q],_=0;_<2;++_){var rr=$[_];for(I=0;I<rr.length;++I){var nr=31&rr[I];b(e,g,Z[nr]),g+=K[nr],nr>15&&(b(e,g,rr[I]>>>5&127),g+=rr[I]>>>12)}}}else O=p,P=d,Q=y,R=m;for(I=0;I<c;++I)if(v[I]>255){nr=v[I]>>>18&31,x(e,g,O[nr+257]),g+=P[nr+257],nr>7&&(b(e,g,v[I]>>>23&31),g+=t[nr]);var er=31&v[I];x(e,g,Q[er]),g+=R[er],er>3&&(x(e,g,v[I]>>>5&8191),g+=f[er])}else x(e,g,O[v[I]]),g+=P[v[I]];return x(e,g,O[256]),g+P[256]},z=new e([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),C=new r(0),E=function(a,o,v,i,l,s){var h=a.length,g=new r(i+h+5*(1+Math.floor(h/7e3))+l),w=g.subarray(i,g.length-l),d=0;if(!o||h<8)for(var m=0;m<=h;m+=65535){var p=m+65535;p<h?d=T(w,d,a.subarray(m,p)):(w[m]=s,d=T(w,d,a.subarray(m,h)))}else{for(var y=z[o-1],b=y>>>13,x=8191&y,A=(1<<v)-1,U=new n(32768),D=new n(A+1),S=Math.ceil(v/3),E=2*S,F=function(r){return(a[r]^a[r+1]<<S^a[r+2]<<E)&A},H=new e(25e3),Y=new n(288),j=new n(32),q=0,B=0,G=(m=0,0),I=0,J=0;m<h;++m){var K=F(m),L=32767&m,N=D[K];if(U[L]=N,D[K]=L,I<=m){var O=h-m;if((q>7e3||G>24576)&&O>423){d=k(a,w,0,H,Y,j,B,G,J,m-J,d),G=q=B=0,J=m;for(var P=0;P<286;++P)Y[P]=0;for(P=0;P<30;++P)j[P]=0}var Q=2,R=0,V=x,W=L-N&32767;if(O>2&&K==F(m-W))for(var X=Math.min(b,O)-1,Z=Math.min(32767,m),$=Math.min(258,O);W<=Z&&--V&&L!=N;){if(a[m+Q]==a[m+Q-W]){for(var _=0;_<$&&a[m+_]==a[m+_-W];++_);if(_>Q){if(Q=_,R=W,_>X)break;var rr=Math.min(W,_-2),nr=0;for(P=0;P<rr;++P){var er=m-W+P+32768&32767,tr=er-U[er]+32768&32767;tr>nr&&(nr=tr,N=er)}}}W+=(L=N)-(N=U[L])+32768&32767}if(R){H[G++]=268435456|u[Q]<<18|c[R];var fr=31&u[Q],ar=31&c[R];B+=t[fr]+f[ar],++Y[257+fr],++j[ar],I=m+Q,++q}else H[G++]=a[m],++Y[a[m]]}}d=k(a,w,s,H,Y,j,B,G,J,m-J,d),s||(d=T(w,d,C))}return function(t,f,a){(null==f||f<0)&&(f=0),(null==a||a>t.length)&&(a=t.length);var o=new(t instanceof n?n:t instanceof e?e:r)(a-f);return o.set(t.subarray(f,a)),o}(g,0,i+M(d)+l)},F=function(r,n,e,t,f){return E(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,t,!f)},H=function(r,n,e){for(;e;++n)r[n]=e,e>>>=8};_e.zlibSync=function(r,n){void 0===n&&(n={});var e=function(){var r=1,n=0;return{p:function(e){for(var t=r,f=n,a=e.length,o=0;o!=a;){for(var v=Math.min(o+5552,a);o<v;++o)f+=t+=e[o];t%=65521,f%=65521}r=t,n=f},d:function(){return(r>>>8<<16|(255&n)<<8|n>>>8)+2*((255&r)<<23)}}}();e.p(r);var t=F(r,n,2,4);return function(r,n){var e=n.level,t=0==e?0:e<6?1:9==e?3:2;r[0]=120,r[1]=t<<6|(t?32-2*t:1)}(t,n),H(t,t.length-4,e.d()),t};var Y=function(n,e,t,f){for(var a in n){var o=n[a],v=e+a;o instanceof r?t[v]=[o,f]:Array.isArray(o)?t[v]=[o[0],mrg(f,o[1])]:Y(o,v+"/",t,f)}};function j(n,e){var t=n.length;if(!e&&"undefined"!=typeof TextEncoder)return(new TextEncoder).encode(n);for(var f=new r(n.length+(n.length>>>1)),a=0,o=function(r){f[a++]=r},v=0;v<t;++v){if(a+5>f.length){var i=new r(a+8+(t-v<<1));i.set(f),f=i}var u=n.charCodeAt(v);u<128||e?o(u):u<2048?(o(192|u>>>6),o(128|63&u)):u>55295&&u<57344?(o(240|(u=65536+(1047552&u)|1023&n.charCodeAt(++v))>>>18),o(128|u>>>12&63),o(128|u>>>6&63),o(128|63&u)):(o(224|u>>>12),o(128|u>>>6&63),o(128|63&u))}return slc(f,0,a)}_e.strToU8=j;for(var q=function(r,n,e,t,f,a,o,v,i,u){var l=a.length,c=t.length;H(r,n,null!=i?33639248:67324752),n+=4,null!=i&&(r[n]=20,n+=2),r[n]=20,n+=2,r[n++]=8==u&&(1==v.level?6:v.level<6?4:9==v.level?2:0),r[n++]=o&&8,r[n]=u,n+=2;var s=new Date(v.mtime||Date.now()),h=s.getFullYear()-1980;if(h<0||h>119)throw"date not in range 1980-2099";H(r,n,2*(h<<24)|s.getMonth()+1<<21|s.getDate()<<16|s.getHours()<<11|s.getMinutes()<<5|s.getSeconds()>>>1),H(r,n+=4,e),H(r,n+4,c),H(r,n+8,f),H(r,n+12,l),n+=16,null!=i&&(H(r,n+=10,i),n+=4),r.set(a,n),n+=l,null==i&&r.set(t,n)},B=new e(256),G=0;G<256;++G){for(var I=G,J=9;--J;)I=(1&I&&3988292384)^I>>>1;B[G]=I}var K=function(){var r=4294967295;return{p:function(n){for(var e=r,t=0;t<n.length;++t)e=B[255&e^n[t]]^e>>>8;r=e},d:function(){return 4294967295^r}}};_e.zipSync=function(n,e){void 0===e&&(e={});var t={},f=[];Y(n,"",t,e);var a=0,o=0;for(var v in t){var i=t[v],u=i[0],l=i[1],c=0==l.level?0:8,s=j(v),h=s.length;if(s.length>65535)throw"filename too long";var g=c?F(u,l,0,0):u,w=g.length,d=K();d.p(u),f.push({t:c,d:g,m:u.length,c:d.d(),u:v.length!=h,n:s,o:a,p:l}),a+=30+h+w,o+=76+2*h+w}for(var m=new r(o+22),p=a,y=o-a,M=0;M<f.length;++M){var b=f[M];q(m,b.o,b.c,b.d,b.m,b.n,b.u,b.p,null,b.t),q(m,a,b.c,b.d,b.m,b.n,b.u,b.p,b.o,b.t),a+=46+b.n.length}return function(r,n,e,t,f){H(r,n,101010256),H(r,n+8,e),H(r,n+10,e),H(r,n+12,t),H(r,n+16,f)}(m,a,f.length,y,p),m};return _e})

fflate-deflate.min.module.js:

/*!
fflate - fast JavaScript compression/decompression
<https://101arrowz.github.io/fflate>
Licensed under MIT. https://github.com/101arrowz/fflate/blob/master/LICENSE
Subset included: synchronous deflate, synchronous zip
*/
"use strict";var r=Uint8Array,n=Uint16Array,e=Uint32Array,t=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]),a=new r([16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15]),o=function(r,t){for(var f=new n(31),a=0;a<31;++a)f[a]=t+=1<<r[a-1];var o=new e(f[30]);for(a=1;a<30;++a)for(var v=f[a];v<f[a+1];++v)o[v]=v-f[a]<<5|a;return[f,o]},v=o(t,2),i=v[0],u=v[1];i[28]=258,u[258]=28;for(var l=o(f,0),c=(l[0],l[1]),s=new n(32768),h=0;h<32768;++h){var g=(43690&h)>>>1|(21845&h)<<1;g=(61680&(g=(52428&g)>>>2|(13107&g)<<2))>>>4|(3855&g)<<4,s[h]=((65280&g)>>>8|(255&g)<<8)>>>1}var w=function(r,e,t){for(var f=r.length,a=0,o=new n(e);a<f;++a)++o[r[a]-1];var v,i=new n(e);for(a=0;a<e;++a)i[a]=i[a-1]+o[a-1]<<1;if(t){v=new n(1<<e);var u=15-e;for(a=0;a<f;++a)if(r[a])for(var l=a<<4|r[a],c=e-r[a],h=i[r[a]-1]++<<c,g=h|(1<<c)-1;h<=g;++h)v[s[h]>>>u]=l}else for(v=new n(f),a=0;a<f;++a)v[a]=s[i[r[a]-1]++]>>>15-r[a];return v},d=new r(288);for(h=0;h<144;++h)d[h]=8;for(h=144;h<256;++h)d[h]=9;for(h=256;h<280;++h)d[h]=7;for(h=280;h<288;++h)d[h]=8;var m=new r(32);for(h=0;h<32;++h)m[h]=5;var p=w(d,9,0),y=w(m,5,0),M=function(r){return(r/8>>0)+(7&r&&1)},b=function(r,n,e){e<<=7&n;var t=n/8>>0;r[t]|=e,r[t+1]|=e>>>8},x=function(r,n,e){e<<=7&n;var t=n/8>>0;r[t]|=e,r[t+1]|=e>>>8,r[t+2]|=e>>>16},A=function(e,t){for(var f=[],a=0;a<e.length;++a)e[a]&&f.push({s:a,f:e[a]});var o=f.length,v=f.slice();if(!o)return[new r(0),0];if(1==o){var i=new r(f[0].s+1);return i[f[0].s]=1,[i,1]}f.sort((function(r,n){return r.f-n.f})),f.push({s:-1,f:25001});var u=f[0],l=f[1],c=0,s=1,h=2;for(f[0]={s:-1,f:u.f+l.f,l:u,r:l};s!=o-1;)u=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:u.f+l.f,l:u,r:l};var g=v[0].s;for(a=1;a<o;++a)v[a].s>g&&(g=v[a].s);var w=new n(g+1),d=U(f[s-1],w,0);if(d>t){a=0;var m=0,p=d-t,y=1<<p;for(v.sort((function(r,n){return w[n.s]-w[r.s]||r.f-n.f}));a<o;++a){var M=v[a].s;if(!(w[M]>t))break;m+=y-(1<<d-w[M]),w[M]=t}for(m>>>=p;m>0;){var b=v[a].s;w[b]<t?m-=1<<t-w[b]++-1:++a}for(;a>=0&&m;--a){var x=v[a].s;w[x]==t&&(--w[x],++m)}d=t}return[new r(w),d]},U=function(r,n,e){return-1==r.s?Math.max(U(r.l,n,e+1),U(r.r,n,e+1)):n[r.s]=e},D=function(r){for(var e=r.length;e&&!r[--e];);for(var t=new n(++e),f=0,a=r[0],o=1,v=function(r){t[f++]=r},i=1;i<=e;++i)if(r[i]==a&&i!=e)++o;else{if(!a&&o>2){for(;o>138;o-=138)v(32754);o>2&&(v(o>10?o-11<<5|28690:o-3<<5|12305),o=0)}else if(o>3){for(v(a),--o;o>6;o-=6)v(8304);o>2&&(v(o-3<<5|8208),o=0)}for(;o--;)v(a);o=1,a=r[i]}return[t.subarray(0,f),e]},S=function(r,n){for(var e=0,t=0;t<n.length;++t)e+=r[t]*n[t];return e},T=function(r,n,e){var t=e.length,f=M(n+2);r[f]=255&t,r[f+1]=t>>>8,r[f+2]=255^r[f],r[f+3]=255^r[f+1];for(var a=0;a<t;++a)r[f+a+4]=e[a];return 8*(f+4+t)},k=function(r,e,o,v,i,u,l,c,s,h,g){b(e,g++,o),++i[256];for(var M=A(i,15),U=M[0],k=M[1],z=A(u,15),C=z[0],E=z[1],F=D(U),H=F[0],Y=F[1],j=D(C),q=j[0],B=j[1],G=new n(19),I=0;I<H.length;++I)G[31&H[I]]++;for(I=0;I<q.length;++I)G[31&q[I]]++;for(var J=A(G,7),K=J[0],L=J[1],N=19;N>4&&!K[a[N-1]];--N);var O,P,Q,R,V=h+5<<3,W=S(i,d)+S(u,m)+l,X=S(i,U)+S(u,C)+l+14+3*N+S(G,K)+(2*G[16]+3*G[17]+7*G[18]);if(V<=W&&V<=X)return T(e,g,r.subarray(s,s+h));if(b(e,g,1+(X<W)),g+=2,X<W){O=w(U,k,0),P=U,Q=w(C,E,0),R=C;var Z=w(K,L,0);for(b(e,g,Y-257),b(e,g+5,B-1),b(e,g+10,N-4),g+=14,I=0;I<N;++I)b(e,g+3*I,K[a[I]]);g+=3*N;for(var $=[H,q],_=0;_<2;++_){var rr=$[_];for(I=0;I<rr.length;++I){var nr=31&rr[I];b(e,g,Z[nr]),g+=K[nr],nr>15&&(b(e,g,rr[I]>>>5&127),g+=rr[I]>>>12)}}}else O=p,P=d,Q=y,R=m;for(I=0;I<c;++I)if(v[I]>255){nr=v[I]>>>18&31,x(e,g,O[nr+257]),g+=P[nr+257],nr>7&&(b(e,g,v[I]>>>23&31),g+=t[nr]);var er=31&v[I];x(e,g,Q[er]),g+=R[er],er>3&&(x(e,g,v[I]>>>5&8191),g+=f[er])}else x(e,g,O[v[I]]),g+=P[v[I]];return x(e,g,O[256]),g+P[256]},z=new e([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),C=new r(0),E=function(a,o,v,i,l,s){var h=a.length,g=new r(i+h+5*(1+Math.floor(h/7e3))+l),w=g.subarray(i,g.length-l),d=0;if(!o||h<8)for(var m=0;m<=h;m+=65535){var p=m+65535;p<h?d=T(w,d,a.subarray(m,p)):(w[m]=s,d=T(w,d,a.subarray(m,h)))}else{for(var y=z[o-1],b=y>>>13,x=8191&y,A=(1<<v)-1,U=new n(32768),D=new n(A+1),S=Math.ceil(v/3),E=2*S,F=function(r){return(a[r]^a[r+1]<<S^a[r+2]<<E)&A},H=new e(25e3),Y=new n(288),j=new n(32),q=0,B=0,G=(m=0,0),I=0,J=0;m<h;++m){var K=F(m),L=32767&m,N=D[K];if(U[L]=N,D[K]=L,I<=m){var O=h-m;if((q>7e3||G>24576)&&O>423){d=k(a,w,0,H,Y,j,B,G,J,m-J,d),G=q=B=0,J=m;for(var P=0;P<286;++P)Y[P]=0;for(P=0;P<30;++P)j[P]=0}var Q=2,R=0,V=x,W=L-N&32767;if(O>2&&K==F(m-W))for(var X=Math.min(b,O)-1,Z=Math.min(32767,m),$=Math.min(258,O);W<=Z&&--V&&L!=N;){if(a[m+Q]==a[m+Q-W]){for(var _=0;_<$&&a[m+_]==a[m+_-W];++_);if(_>Q){if(Q=_,R=W,_>X)break;var rr=Math.min(W,_-2),nr=0;for(P=0;P<rr;++P){var er=m-W+P+32768&32767,tr=er-U[er]+32768&32767;tr>nr&&(nr=tr,N=er)}}}W+=(L=N)-(N=U[L])+32768&32767}if(R){H[G++]=268435456|u[Q]<<18|c[R];var fr=31&u[Q],ar=31&c[R];B+=t[fr]+f[ar],++Y[257+fr],++j[ar],I=m+Q,++q}else H[G++]=a[m],++Y[a[m]]}}d=k(a,w,s,H,Y,j,B,G,J,m-J,d),s||(d=T(w,d,C))}return function(t,f,a){(null==f||f<0)&&(f=0),(null==a||a>t.length)&&(a=t.length);var o=new(t instanceof n?n:t instanceof e?e:r)(a-f);return o.set(t.subarray(f,a)),o}(g,0,i+M(d)+l)},F=function(r,n,e,t,f){return E(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,t,!f)},H=function(r,n,e){for(;e;++n)r[n]=e,e>>>=8};export var zlibSync=function(r,n){void 0===n&&(n={});var e=function(){var r=1,n=0;return{p:function(e){for(var t=r,f=n,a=e.length,o=0;o!=a;){for(var v=Math.min(o+5552,a);o<v;++o)f+=t+=e[o];t%=65521,f%=65521}r=t,n=f},d:function(){return(r>>>8<<16|(255&n)<<8|n>>>8)+2*((255&r)<<23)}}}();e.p(r);var t=F(r,n,2,4);return function(r,n){var e=n.level,t=0==e?0:e<6?1:9==e?3:2;r[0]=120,r[1]=t<<6|(t?32-2*t:1)}(t,n),H(t,t.length-4,e.d()),t};var Y=function(n,e,t,f){for(var a in n){var o=n[a],v=e+a;o instanceof r?t[v]=[o,f]:Array.isArray(o)?t[v]=[o[0],mrg(f,o[1])]:Y(o,v+"/",t,f)}};function j(n,e){var t=n.length;if(!e&&"undefined"!=typeof TextEncoder)return(new TextEncoder).encode(n);for(var f=new r(n.length+(n.length>>>1)),a=0,o=function(r){f[a++]=r},v=0;v<t;++v){if(a+5>f.length){var i=new r(a+8+(t-v<<1));i.set(f),f=i}var u=n.charCodeAt(v);u<128||e?o(u):u<2048?(o(192|u>>>6),o(128|63&u)):u>55295&&u<57344?(o(240|(u=65536+(1047552&u)|1023&n.charCodeAt(++v))>>>18),o(128|u>>>12&63),o(128|u>>>6&63),o(128|63&u)):(o(224|u>>>12),o(128|u>>>6&63),o(128|63&u))}return slc(f,0,a)}export var strToU8=j;for(var q=function(r,n,e,t,f,a,o,v,i,u){var l=a.length,c=t.length;H(r,n,null!=i?33639248:67324752),n+=4,null!=i&&(r[n]=20,n+=2),r[n]=20,n+=2,r[n++]=8==u&&(1==v.level?6:v.level<6?4:9==v.level?2:0),r[n++]=o&&8,r[n]=u,n+=2;var s=new Date(v.mtime||Date.now()),h=s.getFullYear()-1980;if(h<0||h>119)throw"date not in range 1980-2099";H(r,n,2*(h<<24)|s.getMonth()+1<<21|s.getDate()<<16|s.getHours()<<11|s.getMinutes()<<5|s.getSeconds()>>>1),H(r,n+=4,e),H(r,n+4,c),H(r,n+8,f),H(r,n+12,l),n+=16,null!=i&&(H(r,n+=10,i),n+=4),r.set(a,n),n+=l,null==i&&r.set(t,n)},B=new e(256),G=0;G<256;++G){for(var I=G,J=9;--J;)I=(1&I&&3988292384)^I>>>1;B[G]=I}var K=function(){var r=4294967295;return{p:function(n){for(var e=r,t=0;t<n.length;++t)e=B[255&e^n[t]]^e>>>8;r=e},d:function(){return 4294967295^r}}};export var zipSync=function(n,e){void 0===e&&(e={});var t={},f=[];Y(n,"",t,e);var a=0,o=0;for(var v in t){var i=t[v],u=i[0],l=i[1],c=0==l.level?0:8,s=j(v),h=s.length;if(s.length>65535)throw"filename too long";var g=c?F(u,l,0,0):u,w=g.length,d=K();d.p(u),f.push({t:c,d:g,m:u.length,c:d.d(),u:v.length!=h,n:s,o:a,p:l}),a+=30+h+w,o+=76+2*h+w}for(var m=new r(o+22),p=a,y=o-a,M=0;M<f.length;++M){var b=f[M];q(m,b.o,b.c,b.d,b.m,b.n,b.u,b.p,null,b.t),q(m,a,b.c,b.d,b.m,b.n,b.u,b.p,b.o,b.t),a+=46+b.n.length}return function(r,n,e,t,f){H(r,n,101010256),H(r,n+8,e),H(r,n+10,e),H(r,n+12,t),H(r,n+16,f)}(m,a,f.length,y,p),m}

Usage:

import { zipSync, strToU8 } from 'fflate';

const toZip = {};
// instead of zip.file(name, strData)
toZip[name] = strToU8(strData);
// instead of zip.file(name, arrayBufferData)
toZip[name] = new Uint8Array(arrayBufferData);
// instead of zip.file(name, uint8ArrayData)
toZip[name] = uint8ArrayData;

// If you have incompressible data (e.g. PNG file)
// set per-file options
toZip[name] = [uint8ArrayData, { level: 0 }];

// instead of zip.generate
const zipped = zipSync(toZip, {
  // You can change the level to 0 to not waste time
  // Better to use per-file options - this level only
  // has effect if no per-file options set
  level: 9
});

// to create a blob:
const zippedBlob = new Blob([zipped.buffer], {
  type: 'application/zip'
});

Side note: in case @sciecode is still working on this, fflate.unzlibSync(u8Data, new Uint8Array(uncompressedSize)) will work well for you. See the docs.

Also, if you’re still looking into the EXR exporter, try fflateDeflate.zlibSync(u8Data, options). Docs

Read more comments on GitHub >

github_iconTop Results From Across the Web

Caterpillar Performance Handbook - MacAllister Machinery
Machine performance must ultimately be meas ured in unit cost of material moved, a measure that includes both production and costs.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found