Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[124] TiltLoader breaks in a module env #20941

Closed
drcmda opened this issue Dec 24, 2020 · 32 comments · Fixed by #20959
Closed

[124] TiltLoader breaks in a module env #20941

drcmda opened this issue Dec 24, 2020 · 32 comments · Fixed by #20959
Assignees
Labels

Comments

@drcmda
Copy link
Contributor

drcmda commented Dec 24, 2020

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)
@drcmda
Copy link
Contributor Author

drcmda commented Dec 24, 2020

PS. it looks like the import statement is wrong, TiltLoader imports jszip as:

import { JSZip } from 'three/examples/jsm/libs/jszip.module.min.js'

but the library doesn't seem to have a named export called "JSZip", it's undefined. The default export on the other hand yields a function:

import JSZip from 'three/examples/jsm/libs/jszip.module.min.js'

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.

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 24, 2020

import JSZip from 'three/examples/jsm/libs/jszip.module.min.js'

If we do this, the example would report:

Uncaught SyntaxError: The requested module '../libs/jszip.module.min.js' does not provide an export named 'default'

So it seems the current import is correct. Could this be a problem of Parcel?

Why would threejs use a local copy?

We do not want to force users into using npm for just working with the example code. Ideally, they can download the repository and host it on a local webserver.

@drcmda
Copy link
Contributor Author

drcmda commented Dec 24, 2020

Could this be a problem of Parcel?

I looked, it's a problem with JSzip: Stuk/jszip#349 The lib appears unmaintained and i don't think they will fix it. In that case the loader won't be of much use imo.

Some people have suggested to use https://github.com/101arrowz/fflate instead.

Other projects have moved on as well for the same reason, this PR explains some of the problems with JSZip:

  • require cycle
  • missing support for es6 modules
  • incompatible with Rollup (Parcel, CSB, ...)

We do not want to force users into using npm for just working with the example code. Ideally, they can download the repository and host it on a local webserver.

Not complaining, i was just curious, i just hope at some point in the future this will be re-considered because JSM has incredible value that is held back atm.

@drcmda
Copy link
Contributor Author

drcmda commented Dec 24, 2020

Just found this: https://www.npmjs.com/package/@progress/jszip-esm

This is a fork maintained by Telerik where they have fixed it. If you use their package, that's the easiest solution.

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 24, 2020

We could not upgrade JSZip or use forks so far since we rely on an older version of the lib that supports sync unzip. We can only switch to a new library if it also supports this feature.

@drcmda
Copy link
Contributor Author

drcmda commented Dec 24, 2020

Understood, wasn't aware they changed the api that drastically. Fflate supports both async and sync, for instance fflate.unzipSync(...). It's smaller (~5kb vs 80kb), faster (they say up to 50%), no module bugs, maintained, seems like a good replacement. For me it's not so pressing, just wanted to try out TiltLoader really, but maybe if time allows it could be amended. =)

@mrdoob
Copy link
Owner

mrdoob commented Dec 26, 2020

Switching to fflate sounds good to me! 👍

@101arrowz
Copy link

101arrowz commented 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.

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 28, 2020

The library works with TiltLoader but using it with 3MFLoader produces a runtime error:

invalid zip file

This is the place where it happens:

zip = new JSZip( data ); // eslint-disable-line no-undef

Here is the current example of 3MFLoader: https://threejs.org/examples/webgl_loader_3mf

@Mugen87 Mugen87 self-assigned this Dec 28, 2020
@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 28, 2020

And here is the 3MF example on my dev branch using fflate:

https://raw.githack.com/Mugen87/three.js/dev1/examples/webgl_loader_3mf.html

@101arrowz
Copy link

101arrowz commented Dec 28, 2020

The issue there is that in your source code, you pass an ArrayBuffer to fflate.unzipSync but you need to pass a Uint8Array. To fix the problem, use fflate.unzipSync(new Uint8Array(data)). I applied this hotfix within DevTools and the assets were displayed fine after that. Don't worry about performance cost, this is a free operation (just creates an interface to view the same chunk of memory without any copying).

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 28, 2020

Okay, webgl_loader_3mf works now but I get an empty object zip object in webgl_loader_3mf_materials. Please check out:

https://raw.githack.com/Mugen87/three.js/0b388b5f6fa9228425acae87775d3a28088501a9/examples/webgl_loader_3mf_materials.html

Current prod version: https://threejs.org/examples/webgl_loader_3mf_materials

@101arrowz
Copy link

101arrowz commented Dec 28, 2020

That's a bug in either the compressed version or the actual library. Looking into it now. Thanks for the help with debugging.

EDIT: This is actually the result of that file being Zip64. fflate has no plans to support this format because it's designed for files above 4 GB compressed, and JavaScript typed arrays cannot be that big. This can be resolved by unzipping and rezipping the file; when this is done, the unnecessary Zip64 data is removed and a standard ZIP file is produced, which can be read by fflate. @Mugen87 is this a feasible compromise? If not I can probably hack together a Zip64 reader in a few days.

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 28, 2020

@Mugen87 is this a feasible compromise?

I'm afraid no since we can't ask users to unpack and pack 3MF files again. Such things have to work out of the box.

Besides, if JSZip supports Zip64 I expect to have proper supported in other zip libs, too.

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 28, 2020

and JavaScript typed arrays cannot be that big.

Is that really true? I've read this solely depends on the system.

https://stackoverflow.com/a/25741940/5250847

@101arrowz
Copy link

101arrowz commented Dec 28, 2020

You have the spec, and you have reality. V8 and Gecko use a 64 bit unsigned integer to store the size of typed arrays, which means a theoretical max of a lot, but they both cap the actual size at 231 on all devices I've tested. Node caps it at 232. No Zip64 data is strictly necessary while still being possible in JavaScript.

I understand that Zip64 is important, so I'll add support for it. However, this might be a few days of work since it's a much more messy specification.

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 28, 2020

I understand that Zip64 is important, so I'll add support for it.

👍

101arrowz added a commit to 101arrowz/fflate that referenced this issue Dec 28, 2020
@101arrowz
Copy link

101arrowz commented Dec 29, 2020

Turns out the problem was way easier to fix than I thought. Zip64 support was just added; it works on the 3MF files from what i can tell.

New code (4.6kB, 2.3kB gzipped):

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

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 29, 2020

Can you please also share an updated version of fflate.min.js? We need an UMD version for loaders in examples/js.

Besides, when using the above code I get:

fflate.module.min.js:1 Uncaught ReferenceError: exports is not defined

@101arrowz
Copy link

101arrowz commented Dec 29, 2020

My bad, updated the code in my most recent comment. I had forgotten to switch the CommonJS exports to ESM. UMD build should already be live on jsDelivr, I believe, but you could probably wrap the minified code to make the UMD build smaller too.

On looking again at the source code here, it seems that a lot of compression libraries could be replaced by a single one, which is probably better to avoid fragmentation...Will create a more complete minified copy soon and create a PR.

EDIT: Here are my (semi) final revisions for the versions:

fflate.min.js (replaces gunzip.js, inflate.js, jszip.js):

!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).fflate=f()}(function(_e){"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]),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]),o=function(r,t){for(var a=new n(31),i=0;i<31;++i)a[i]=t+=1<<r[i-1];var o=new e(a[30]);for(i=1;i<30;++i)for(var f=a[i];f<a[i+1];++f)o[f]=f-a[i]<<5|i;return[a,o]},f=o(t,2),u=f[0],v=f[1];u[28]=258,v[258]=28;for(var c=o(a,0),l=c[0],w=(c[1],new n(32768)),h=0;h<32768;++h){var s=(43690&h)>>>1|(21845&h)<<1;s=(61680&(s=(52428&s)>>>2|(13107&s)<<2))>>>4|(3855&s)<<4,w[h]=((65280&s)>>>8|(255&s)<<8)>>>1}var d=function(r,e){for(var t=r.length,a=0,i=new n(e);a<t;++a)++i[r[a]-1];var o=new n(e);for(a=0;a<e;++a)o[a]=o[a-1]+i[a-1]<<1;var f=new n(1<<e),u=15-e;for(a=0;a<t;++a)if(r[a])for(var v=a<<4|r[a],c=e-r[a],l=o[r[a]-1]++<<c,h=l|(1<<c)-1;l<=h;++l)f[w[l]>>>u]=v;return f},p=new r(288);for(h=0;h<144;++h)p[h]=8;for(h=144;h<256;++h)p[h]=9;for(h=256;h<280;++h)p[h]=7;for(h=280;h<288;++h)p[h]=8;var g=new r(32);for(h=0;h<32;++h)g[h]=5;var y=d(p,9),b=d(g,5),x=function(r){for(var n=r[0],e=1;e<r.length;++e)r[e]>n&&(n=r[e]);return n},z=function(r,n,e){var t=n/8>>0;return(r[t]|r[t+1]<<8)>>>(7&n)&e},C=function(r,n){var e=n/8>>0;return(r[e]|r[e+1]<<8|r[e+2]<<16)>>>(7&n)},m=function(r){return(r/8>>0)+(7&r&&1)},S=function(t,a,i){(null==a||a<0)&&(a=0),(null==i||i>t.length)&&(i=t.length);var o=new(t instanceof n?n:t instanceof e?e:r)(i-a);return o.set(t.subarray(a,i)),o},F=function(n,e){var o=n.length,f=!e;e||(e=new r(3*o));var v,c,w,h,s=function(n){var t=e.length;if(n>t){var a=new r(Math.max(2*t,n));a.set(e),e=a}},p=0,g=0,F=0;if(p&&!v)return e;var E=8*o;do{p=z(n,g,1);var O=z(n,g+1,3);if(g+=3,O){if(1==O)v=y,c=b,w=9,h=5;else{if(2!=O)throw"invalid block type";var U=z(n,g,31)+257,k=z(n,g+10,15)+4,A=U+z(n,g+5,31)+1;g+=14;for(var D=new r(A),T=new r(19),M=0;M<k;++M)T[i[M]]=z(n,g+3*M,7);g+=3*k;var j=x(T),q=(1<<j)-1,B=d(T,j);for(M=0;M<A;){var G=B[z(n,g,q)];if(g+=15&G,(Y=G>>>4)<16)D[M++]=Y;else{var H=0,I=0;for(16==Y?(I=3+z(n,g,3),g+=2,H=D[M-1]):17==Y?(I=3+z(n,g,7),g+=3):18==Y&&(I=11+z(n,g,127),g+=7);I--;)D[M++]=H}}var J=D.subarray(0,U),K=D.subarray(U);w=x(J),h=x(K),v=d(J,w),c=d(K,h)}if(g>E)throw"unexpected EOF";f&&s(F+131072);for(var L=(1<<w)-1,N=(1<<h)-1;;){var P=(H=v[C(n,g)&L])>>>4;if((g+=15&H)>E)throw"unexpected EOF";if(!H)throw"invalid length/literal";if(P<256)e[F++]=P;else{if(256==P)break;var Q=P-254;if(P>264){var R=t[M=P-257];Q=z(n,g,(1<<R)-1)+u[M],g+=R}var V=c[C(n,g)&N],W=V>>>4;if(!V)throw"invalid distance";g+=15&V;K=l[W];if(W>3){R=a[W];K+=C(n,g)&(1<<R)-1,g+=R}if(g>E)throw"unexpected EOF";f&&s(F+131072);for(var X=F+Q;F<X;F+=4)e[F]=e[F-K],e[F+1]=e[F+1-K],e[F+2]=e[F+2-K],e[F+3]=e[F+3-K];F=X}}}else{var Y,Z=n[(Y=m(g)+4)-4]|n[Y-3]<<8,$=Y+Z;if($>o)throw"unexpected EOF";f&&s(F+Z),e.set(n.subarray(Y,$),F),F+=Z,g=8*$}}while(!p);return F==e.length?e:S(e,0,F)},E=function(r,n){return r[n]|r[n+1]<<8},O=function(r,n){return(r[n]|r[n+1]<<8|r[n+2]<<16)+2*(r[n+3]<<23)},U=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)},k=function(r){var n=r.length;return(r[n-4]|r[n-3]<<8|r[n-2]<<16)+2*(r[n-1]<<23)},A=function(r){if(8!=(15&r[0])||r[0]>>>4>7||(r[0]<<8|r[1])%31)throw"invalid zlib data";if(32&r[1])throw"invalid zlib data: preset dictionaries not supported"};function D(r,n){return F(r,n)}function T(n,e){return F(n.subarray(U(n),-8),e||new r(k(n)))}_e.gunzipSync=T;function M(r,n){return F((A(r),r.subarray(2,-4)),n)}_e.unzlibSync=M;function j(r,n){var e="";if(!n&&"undefined"!=typeof TextDecoder)return(new TextDecoder).decode(r);for(var t=0;t<r.length;){var a=r[t++];a<128||n?e+=String.fromCharCode(a):a<224?e+=String.fromCharCode((31&a)<<6|63&r[t++]):a<240?e+=String.fromCharCode((15&a)<<12|(63&r[t++])<<6|63&r[t++]):(a=((15&a)<<18|(63&r[t++])<<12|(63&r[t++])<<6|63&r[t++])-65536,e+=String.fromCharCode(55296|a>>10,56320|1023&a))}return e}_e.strFromU8=j;var q=function(r,n){return n+30+E(r,n+26)+E(r,n+28)},B=function(r,n,e){var t=E(r,n+28),a=j(r.subarray(n+46,n+46+t),!(2048&E(r,n+8))),i=n+46+t,o=e?G(r,i):[O(r,n+20),O(r,n+24),O(r,n+42)],f=o[0],u=o[1],v=o[2];return[E(r,n+10),f,u,a,i+E(r,n+30)+E(r,n+32),v]},G=function(r,n){for(;1!=E(r,n);n+=4+E(r,n+2));return[O(r,n+12),O(r,n+4),O(r,n+20)]};_e.unzipSync=function(n){for(var e={},t=n.length-22;101010256!=O(n,t);--t)if(!t||n.length-t>65558)throw"invalid zip file";var a=E(n,t+8);if(!a)return{};var i=O(n,t+16),o=4294967295==i;if(o){if(t=O(n,t-12),101075792!=O(n,t))throw"invalid zip file";a=O(n,t+32),i=O(n,t+48)}for(var f=0;f<a;++f){var u=B(n,i,o),v=u[0],c=u[1],l=u[2],w=u[3],h=u[4],s=u[5],d=q(n,s);if(i=h,v){if(8!=v)throw"unknown compression type "+v;e[w]=D(n.subarray(d,d+c),new r(l))}else e[w]=S(n,d,d+c)}return e};return _e})

fflate.module.min.js:

"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]),o=function(r,t){for(var a=new n(31),i=0;i<31;++i)a[i]=t+=1<<r[i-1];var o=new e(a[30]);for(i=1;i<30;++i)for(var f=a[i];f<a[i+1];++f)o[f]=f-a[i]<<5|i;return[a,o]},f=o(t,2),u=f[0],v=f[1];u[28]=258,v[258]=28;for(var c=o(a,0),l=c[0],w=(c[1],new n(32768)),h=0;h<32768;++h){var s=(43690&h)>>>1|(21845&h)<<1;s=(61680&(s=(52428&s)>>>2|(13107&s)<<2))>>>4|(3855&s)<<4,w[h]=((65280&s)>>>8|(255&s)<<8)>>>1}var d=function(r,e){for(var t=r.length,a=0,i=new n(e);a<t;++a)++i[r[a]-1];var o=new n(e);for(a=0;a<e;++a)o[a]=o[a-1]+i[a-1]<<1;var f=new n(1<<e),u=15-e;for(a=0;a<t;++a)if(r[a])for(var v=a<<4|r[a],c=e-r[a],l=o[r[a]-1]++<<c,h=l|(1<<c)-1;l<=h;++l)f[w[l]>>>u]=v;return f},p=new r(288);for(h=0;h<144;++h)p[h]=8;for(h=144;h<256;++h)p[h]=9;for(h=256;h<280;++h)p[h]=7;for(h=280;h<288;++h)p[h]=8;var g=new r(32);for(h=0;h<32;++h)g[h]=5;var y=d(p,9),b=d(g,5),x=function(r){for(var n=r[0],e=1;e<r.length;++e)r[e]>n&&(n=r[e]);return n},z=function(r,n,e){var t=n/8>>0;return(r[t]|r[t+1]<<8)>>>(7&n)&e},C=function(r,n){var e=n/8>>0;return(r[e]|r[e+1]<<8|r[e+2]<<16)>>>(7&n)},m=function(r){return(r/8>>0)+(7&r&&1)},S=function(t,a,i){(null==a||a<0)&&(a=0),(null==i||i>t.length)&&(i=t.length);var o=new(t instanceof n?n:t instanceof e?e:r)(i-a);return o.set(t.subarray(a,i)),o},F=function(n,e){var o=n.length,f=!e;e||(e=new r(3*o));var v,c,w,h,s=function(n){var t=e.length;if(n>t){var a=new r(Math.max(2*t,n));a.set(e),e=a}},p=0,g=0,F=0;if(p&&!v)return e;var E=8*o;do{p=z(n,g,1);var O=z(n,g+1,3);if(g+=3,O){if(1==O)v=y,c=b,w=9,h=5;else{if(2!=O)throw"invalid block type";var U=z(n,g,31)+257,k=z(n,g+10,15)+4,A=U+z(n,g+5,31)+1;g+=14;for(var D=new r(A),T=new r(19),M=0;M<k;++M)T[i[M]]=z(n,g+3*M,7);g+=3*k;var j=x(T),q=(1<<j)-1,B=d(T,j);for(M=0;M<A;){var G=B[z(n,g,q)];if(g+=15&G,(Y=G>>>4)<16)D[M++]=Y;else{var H=0,I=0;for(16==Y?(I=3+z(n,g,3),g+=2,H=D[M-1]):17==Y?(I=3+z(n,g,7),g+=3):18==Y&&(I=11+z(n,g,127),g+=7);I--;)D[M++]=H}}var J=D.subarray(0,U),K=D.subarray(U);w=x(J),h=x(K),v=d(J,w),c=d(K,h)}if(g>E)throw"unexpected EOF";f&&s(F+131072);for(var L=(1<<w)-1,N=(1<<h)-1;;){var P=(H=v[C(n,g)&L])>>>4;if((g+=15&H)>E)throw"unexpected EOF";if(!H)throw"invalid length/literal";if(P<256)e[F++]=P;else{if(256==P)break;var Q=P-254;if(P>264){var R=t[M=P-257];Q=z(n,g,(1<<R)-1)+u[M],g+=R}var V=c[C(n,g)&N],W=V>>>4;if(!V)throw"invalid distance";g+=15&V;K=l[W];if(W>3){R=a[W];K+=C(n,g)&(1<<R)-1,g+=R}if(g>E)throw"unexpected EOF";f&&s(F+131072);for(var X=F+Q;F<X;F+=4)e[F]=e[F-K],e[F+1]=e[F+1-K],e[F+2]=e[F+2-K],e[F+3]=e[F+3-K];F=X}}}else{var Y,Z=n[(Y=m(g)+4)-4]|n[Y-3]<<8,$=Y+Z;if($>o)throw"unexpected EOF";f&&s(F+Z),e.set(n.subarray(Y,$),F),F+=Z,g=8*$}}while(!p);return F==e.length?e:S(e,0,F)},E=function(r,n){return r[n]|r[n+1]<<8},O=function(r,n){return(r[n]|r[n+1]<<8|r[n+2]<<16)+2*(r[n+3]<<23)},U=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)},k=function(r){var n=r.length;return(r[n-4]|r[n-3]<<8|r[n-2]<<16)+2*(r[n-1]<<23)},A=function(r){if(8!=(15&r[0])||r[0]>>>4>7||(r[0]<<8|r[1])%31)throw"invalid zlib data";if(32&r[1])throw"invalid zlib data: preset dictionaries not supported"};function D(r,n){return F(r,n)}function T(n,e){return F(n.subarray(U(n),-8),e||new r(k(n)))};export var gunzipSync=T;function M(r,n){return F((A(r),r.subarray(2,-4)),n)};export var unzlibSync=M;function j(r,n){var e="";if(!n&&"undefined"!=typeof TextDecoder)return(new TextDecoder).decode(r);for(var t=0;t<r.length;){var a=r[t++];a<128||n?e+=String.fromCharCode(a):a<224?e+=String.fromCharCode((31&a)<<6|63&r[t++]):a<240?e+=String.fromCharCode((15&a)<<12|(63&r[t++])<<6|63&r[t++]):(a=((15&a)<<18|(63&r[t++])<<12|(63&r[t++])<<6|63&r[t++])-65536,e+=String.fromCharCode(55296|a>>10,56320|1023&a))}return e};export var strFromU8=j;var q=function(r,n){return n+30+E(r,n+26)+E(r,n+28)},B=function(r,n,e){var t=E(r,n+28),a=j(r.subarray(n+46,n+46+t),!(2048&E(r,n+8))),i=n+46+t,o=e?G(r,i):[O(r,n+20),O(r,n+24),O(r,n+42)],f=o[0],u=o[1],v=o[2];return[E(r,n+10),f,u,a,i+E(r,n+30)+E(r,n+32),v]},G=function(r,n){for(;1!=E(r,n);n+=4+E(r,n+2));return[O(r,n+12),O(r,n+4),O(r,n+20)]};export var unzipSync=function(n){for(var e={},t=n.length-22;101010256!=O(n,t);--t)if(!t||n.length-t>65558)throw"invalid zip file";var a=E(n,t+8);if(!a)return{};var i=O(n,t+16),o=4294967295==i;if(o){if(t=O(n,t-12),101075792!=O(n,t))throw"invalid zip file";a=O(n,t+32),i=O(n,t+48)}for(var f=0;f<a;++f){var u=B(n,i,o),v=u[0],c=u[1],l=u[2],w=u[3],h=u[4],s=u[5],d=q(n,s);if(i=h,v){if(8!=v)throw"unknown compression type "+v;e[w]=D(n.subarray(d,d+c),new r(l))}else e[w]=S(n,d,d+c)}return e}

fflate-deflate.min.js (replaces deflate.js):

!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,f=Uint32Array,e=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]),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,e){for(var a=new n(31),t=0;t<31;++t)a[t]=e+=1<<r[t-1];var o=new f(a[30]);for(t=1;t<30;++t)for(var i=a[t];i<a[t+1];++i)o[i]=i-a[t]<<5|t;return[a,o]},i=o(e,2),v=i[0],u=i[1];v[28]=258,u[258]=28;for(var l=o(a,0),s=(l[0],l[1]),c=new n(32768),h=0;h<32768;++h){var w=(43690&h)>>>1|(21845&h)<<1;w=(61680&(w=(52428&w)>>>2|(13107&w)<<2))>>>4|(3855&w)<<4,c[h]=((65280&w)>>>8|(255&w)<<8)>>>1}var g=function(r,f,e){for(var a=r.length,t=0,o=new n(f);t<a;++t)++o[r[t]-1];var i,v=new n(f);for(t=0;t<f;++t)v[t]=v[t-1]+o[t-1]<<1;if(e){i=new n(1<<f);var u=15-f;for(t=0;t<a;++t)if(r[t])for(var l=t<<4|r[t],s=f-r[t],h=v[r[t]-1]++<<s,w=h|(1<<s)-1;h<=w;++h)i[c[h]>>>u]=l}else for(i=new n(a),t=0;t<a;++t)i[t]=c[v[r[t]-1]++]>>>15-r[t];return i},m=new r(288);for(h=0;h<144;++h)m[h]=8;for(h=144;h<256;++h)m[h]=9;for(h=256;h<280;++h)m[h]=7;for(h=280;h<288;++h)m[h]=8;var M=new r(32);for(h=0;h<32;++h)M[h]=5;var y=g(m,9,0),b=g(M,5,0),p=function(r){return(r/8>>0)+(7&r&&1)},d=function(e,a,t){(null==a||a<0)&&(a=0),(null==t||t>e.length)&&(t=e.length);var o=new(e instanceof n?n:e instanceof f?f:r)(t-a);return o.set(e.subarray(a,t)),o},x=function(r,n,f){f<<=7&n;var e=n/8>>0;r[e]|=f,r[e+1]|=f>>>8},A=function(r,n,f){f<<=7&n;var e=n/8>>0;r[e]|=f,r[e+1]|=f>>>8,r[e+2]|=f>>>16},U=function(f,e){for(var a=[],t=0;t<f.length;++t)f[t]&&a.push({s:t,f:f[t]});var o=a.length,i=a.slice();if(!o)return[new r(0),0];if(1==o){var v=new r(a[0].s+1);return v[a[0].s]=1,[v,1]}a.sort((function(r,n){return r.f-n.f})),a.push({s:-1,f:25001});var u=a[0],l=a[1],s=0,c=1,h=2;for(a[0]={s:-1,f:u.f+l.f,l:u,r:l};c!=o-1;)u=a[a[s].f<a[h].f?s++:h++],l=a[s!=c&&a[s].f<a[h].f?s++:h++],a[c++]={s:-1,f:u.f+l.f,l:u,r:l};var w=i[0].s;for(t=1;t<o;++t)i[t].s>w&&(w=i[t].s);var g=new n(w+1),m=k(a[c-1],g,0);if(m>e){t=0;var M=0,y=m-e,b=1<<y;for(i.sort((function(r,n){return g[n.s]-g[r.s]||r.f-n.f}));t<o;++t){var p=i[t].s;if(!(g[p]>e))break;M+=b-(1<<m-g[p]),g[p]=e}for(M>>>=y;M>0;){var d=i[t].s;g[d]<e?M-=1<<e-g[d]++-1:++t}for(;t>=0&&M;--t){var x=i[t].s;g[x]==e&&(--g[x],++M)}m=e}return[new r(g),m]},k=function(r,n,f){return-1==r.s?Math.max(k(r.l,n,f+1),k(r.r,n,f+1)):n[r.s]=f},z=function(r){for(var f=r.length;f&&!r[--f];);for(var e=new n(++f),a=0,t=r[0],o=1,i=function(r){e[a++]=r},v=1;v<=f;++v)if(r[v]==t&&v!=f)++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[v]}return[e.subarray(0,a),f]},S=function(r,n){for(var f=0,e=0;e<n.length;++e)f+=r[e]*n[e];return f},j=function(r,n,f){var e=f.length,a=p(n+2);r[a]=255&e,r[a+1]=e>>>8,r[a+2]=255^r[a],r[a+3]=255^r[a+1];for(var t=0;t<e;++t)r[a+t+4]=f[t];return 8*(a+4+e)},q=function(r,f,o,i,v,u,l,s,c,h,w){x(f,w++,o),++v[256];for(var p=U(v,15),d=p[0],k=p[1],q=U(u,15),B=q[0],C=q[1],D=z(d),E=D[0],F=D[1],G=z(B),H=G[0],I=G[1],J=new n(19),K=0;K<E.length;++K)J[31&E[K]]++;for(K=0;K<H.length;++K)J[31&H[K]]++;for(var L=U(J,7),N=L[0],O=L[1],P=19;P>4&&!N[t[P-1]];--P);var Q,R,T,V,W=h+5<<3,X=S(v,m)+S(u,M)+l,Y=S(v,d)+S(u,B)+l+14+3*P+S(J,N)+(2*J[16]+3*J[17]+7*J[18]);if(W<=X&&W<=Y)return j(f,w,r.subarray(c,c+h));if(x(f,w,1+(Y<X)),w+=2,Y<X){Q=g(d,k,0),R=d,T=g(B,C,0),V=B;var Z=g(N,O,0);x(f,w,F-257),x(f,w+5,I-1),x(f,w+10,P-4),w+=14;for(K=0;K<P;++K)x(f,w+3*K,N[t[K]]);w+=3*P;for(var $=[E,H],_=0;_<2;++_){var rr=$[_];for(K=0;K<rr.length;++K){var nr=31&rr[K];x(f,w,Z[nr]),w+=N[nr],nr>15&&(x(f,w,rr[K]>>>5&127),w+=rr[K]>>>12)}}}else Q=y,R=m,T=b,V=M;for(K=0;K<s;++K)if(i[K]>255){nr=i[K]>>>18&31;A(f,w,Q[nr+257]),w+=R[nr+257],nr>7&&(x(f,w,i[K]>>>23&31),w+=e[nr]);var fr=31&i[K];A(f,w,T[fr]),w+=V[fr],fr>3&&(A(f,w,i[K]>>>5&8191),w+=a[fr])}else A(f,w,Q[i[K]]),w+=R[i[K]];return A(f,w,Q[256]),w+R[256]},B=new f([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),C=new r(0),D=function(t,o,i,v,l,c){var h=t.length,w=new r(v+h+5*(1+Math.floor(h/7e3))+l),g=w.subarray(v,w.length-l),m=0;if(!o||h<8)for(var M=0;M<=h;M+=65535){var y=M+65535;y<h?m=j(g,m,t.subarray(M,y)):(g[M]=c,m=j(g,m,t.subarray(M,h)))}else{for(var b=B[o-1],x=b>>>13,A=8191&b,U=(1<<i)-1,k=new n(32768),z=new n(U+1),S=Math.ceil(i/3),D=2*S,E=function(r){return(t[r]^t[r+1]<<S^t[r+2]<<D)&U},F=new f(25e3),G=new n(288),H=new n(32),I=0,J=0,K=(M=0,0),L=0,N=0;M<h;++M){var O=E(M),P=32767&M,Q=z[O];if(k[P]=Q,z[O]=P,L<=M){var R=h-M;if((I>7e3||K>24576)&&R>423){m=q(t,g,0,F,G,H,J,K,N,M-N,m),K=I=J=0,N=M;for(var T=0;T<286;++T)G[T]=0;for(T=0;T<30;++T)H[T]=0}var V=2,W=0,X=A,Y=P-Q&32767;if(R>2&&O==E(M-Y))for(var Z=Math.min(x,R)-1,$=Math.min(32767,M),_=Math.min(258,R);Y<=$&&--X&&P!=Q;){if(t[M+V]==t[M+V-Y]){for(var rr=0;rr<_&&t[M+rr]==t[M+rr-Y];++rr);if(rr>V){if(V=rr,W=Y,rr>Z)break;var nr=Math.min(Y,rr-2),fr=0;for(T=0;T<nr;++T){var er=M-Y+T+32768&32767,ar=er-k[er]+32768&32767;ar>fr&&(fr=ar,Q=er)}}}Y+=(P=Q)-(Q=k[P])+32768&32767}if(W){F[K++]=268435456|u[V]<<18|s[W];var tr=31&u[V],or=31&s[W];J+=e[tr]+a[or],++G[257+tr],++H[or],L=M+V,++I}else F[K++]=t[M],++G[t[M]]}}m=q(t,g,c,F,G,H,J,K,N,M-N,m),c||(m=j(g,m,C))}return d(w,0,v+p(m)+l)},E=function(){var r=1,n=0;return{p:function(f){for(var e=r,a=n,t=f.length,o=0;o!=t;){for(var i=Math.min(o+5552,t);o<i;++o)a+=e+=f[o];e%=65521,a%=65521}r=e,n=a},d:function(){return(r>>>8<<16|(255&n)<<8|n>>>8)+2*((255&r)<<23)}}},F=function(r,n,f,e,a){return D(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,f,e,!a)},G=function(r,n,f){for(;f;++n)r[n]=f,f>>>=8},H=function(r,n){var f=n.level,e=0==f?0:f<6?1:9==f?3:2;r[0]=120,r[1]=e<<6|(e?32-2*e:1)};function I(r,n){void 0===n&&(n={});var f=E();f.p(r);var e=F(r,n,2,4);return H(e,n),G(e,e.length-4,f.d()),e}_e.zlibSync=I;return _e})

fflate-deflate.module.min.js:

"use strict";var r=Uint8Array,n=Uint16Array,f=Uint32Array,e=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]),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,e){for(var a=new n(31),t=0;t<31;++t)a[t]=e+=1<<r[t-1];var o=new f(a[30]);for(t=1;t<30;++t)for(var i=a[t];i<a[t+1];++i)o[i]=i-a[t]<<5|t;return[a,o]},i=o(e,2),v=i[0],u=i[1];v[28]=258,u[258]=28;for(var l=o(a,0),s=(l[0],l[1]),c=new n(32768),h=0;h<32768;++h){var w=(43690&h)>>>1|(21845&h)<<1;w=(61680&(w=(52428&w)>>>2|(13107&w)<<2))>>>4|(3855&w)<<4,c[h]=((65280&w)>>>8|(255&w)<<8)>>>1}var g=function(r,f,e){for(var a=r.length,t=0,o=new n(f);t<a;++t)++o[r[t]-1];var i,v=new n(f);for(t=0;t<f;++t)v[t]=v[t-1]+o[t-1]<<1;if(e){i=new n(1<<f);var u=15-f;for(t=0;t<a;++t)if(r[t])for(var l=t<<4|r[t],s=f-r[t],h=v[r[t]-1]++<<s,w=h|(1<<s)-1;h<=w;++h)i[c[h]>>>u]=l}else for(i=new n(a),t=0;t<a;++t)i[t]=c[v[r[t]-1]++]>>>15-r[t];return i},m=new r(288);for(h=0;h<144;++h)m[h]=8;for(h=144;h<256;++h)m[h]=9;for(h=256;h<280;++h)m[h]=7;for(h=280;h<288;++h)m[h]=8;var M=new r(32);for(h=0;h<32;++h)M[h]=5;var y=g(m,9,0),b=g(M,5,0),p=function(r){return(r/8>>0)+(7&r&&1)},d=function(e,a,t){(null==a||a<0)&&(a=0),(null==t||t>e.length)&&(t=e.length);var o=new(e instanceof n?n:e instanceof f?f:r)(t-a);return o.set(e.subarray(a,t)),o},x=function(r,n,f){f<<=7&n;var e=n/8>>0;r[e]|=f,r[e+1]|=f>>>8},A=function(r,n,f){f<<=7&n;var e=n/8>>0;r[e]|=f,r[e+1]|=f>>>8,r[e+2]|=f>>>16},U=function(f,e){for(var a=[],t=0;t<f.length;++t)f[t]&&a.push({s:t,f:f[t]});var o=a.length,i=a.slice();if(!o)return[new r(0),0];if(1==o){var v=new r(a[0].s+1);return v[a[0].s]=1,[v,1]}a.sort((function(r,n){return r.f-n.f})),a.push({s:-1,f:25001});var u=a[0],l=a[1],s=0,c=1,h=2;for(a[0]={s:-1,f:u.f+l.f,l:u,r:l};c!=o-1;)u=a[a[s].f<a[h].f?s++:h++],l=a[s!=c&&a[s].f<a[h].f?s++:h++],a[c++]={s:-1,f:u.f+l.f,l:u,r:l};var w=i[0].s;for(t=1;t<o;++t)i[t].s>w&&(w=i[t].s);var g=new n(w+1),m=k(a[c-1],g,0);if(m>e){t=0;var M=0,y=m-e,b=1<<y;for(i.sort((function(r,n){return g[n.s]-g[r.s]||r.f-n.f}));t<o;++t){var p=i[t].s;if(!(g[p]>e))break;M+=b-(1<<m-g[p]),g[p]=e}for(M>>>=y;M>0;){var d=i[t].s;g[d]<e?M-=1<<e-g[d]++-1:++t}for(;t>=0&&M;--t){var x=i[t].s;g[x]==e&&(--g[x],++M)}m=e}return[new r(g),m]},k=function(r,n,f){return-1==r.s?Math.max(k(r.l,n,f+1),k(r.r,n,f+1)):n[r.s]=f},z=function(r){for(var f=r.length;f&&!r[--f];);for(var e=new n(++f),a=0,t=r[0],o=1,i=function(r){e[a++]=r},v=1;v<=f;++v)if(r[v]==t&&v!=f)++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[v]}return[e.subarray(0,a),f]},S=function(r,n){for(var f=0,e=0;e<n.length;++e)f+=r[e]*n[e];return f},j=function(r,n,f){var e=f.length,a=p(n+2);r[a]=255&e,r[a+1]=e>>>8,r[a+2]=255^r[a],r[a+3]=255^r[a+1];for(var t=0;t<e;++t)r[a+t+4]=f[t];return 8*(a+4+e)},q=function(r,f,o,i,v,u,l,s,c,h,w){x(f,w++,o),++v[256];for(var p=U(v,15),d=p[0],k=p[1],q=U(u,15),B=q[0],C=q[1],D=z(d),E=D[0],F=D[1],G=z(B),H=G[0],I=G[1],J=new n(19),K=0;K<E.length;++K)J[31&E[K]]++;for(K=0;K<H.length;++K)J[31&H[K]]++;for(var L=U(J,7),N=L[0],O=L[1],P=19;P>4&&!N[t[P-1]];--P);var Q,R,T,V,W=h+5<<3,X=S(v,m)+S(u,M)+l,Y=S(v,d)+S(u,B)+l+14+3*P+S(J,N)+(2*J[16]+3*J[17]+7*J[18]);if(W<=X&&W<=Y)return j(f,w,r.subarray(c,c+h));if(x(f,w,1+(Y<X)),w+=2,Y<X){Q=g(d,k,0),R=d,T=g(B,C,0),V=B;var Z=g(N,O,0);x(f,w,F-257),x(f,w+5,I-1),x(f,w+10,P-4),w+=14;for(K=0;K<P;++K)x(f,w+3*K,N[t[K]]);w+=3*P;for(var $=[E,H],_=0;_<2;++_){var rr=$[_];for(K=0;K<rr.length;++K){var nr=31&rr[K];x(f,w,Z[nr]),w+=N[nr],nr>15&&(x(f,w,rr[K]>>>5&127),w+=rr[K]>>>12)}}}else Q=y,R=m,T=b,V=M;for(K=0;K<s;++K)if(i[K]>255){nr=i[K]>>>18&31;A(f,w,Q[nr+257]),w+=R[nr+257],nr>7&&(x(f,w,i[K]>>>23&31),w+=e[nr]);var fr=31&i[K];A(f,w,T[fr]),w+=V[fr],fr>3&&(A(f,w,i[K]>>>5&8191),w+=a[fr])}else A(f,w,Q[i[K]]),w+=R[i[K]];return A(f,w,Q[256]),w+R[256]},B=new f([65540,131080,131088,131104,262176,1048704,1048832,2114560,2117632]),C=new r(0),D=function(t,o,i,v,l,c){var h=t.length,w=new r(v+h+5*(1+Math.floor(h/7e3))+l),g=w.subarray(v,w.length-l),m=0;if(!o||h<8)for(var M=0;M<=h;M+=65535){var y=M+65535;y<h?m=j(g,m,t.subarray(M,y)):(g[M]=c,m=j(g,m,t.subarray(M,h)))}else{for(var b=B[o-1],x=b>>>13,A=8191&b,U=(1<<i)-1,k=new n(32768),z=new n(U+1),S=Math.ceil(i/3),D=2*S,E=function(r){return(t[r]^t[r+1]<<S^t[r+2]<<D)&U},F=new f(25e3),G=new n(288),H=new n(32),I=0,J=0,K=(M=0,0),L=0,N=0;M<h;++M){var O=E(M),P=32767&M,Q=z[O];if(k[P]=Q,z[O]=P,L<=M){var R=h-M;if((I>7e3||K>24576)&&R>423){m=q(t,g,0,F,G,H,J,K,N,M-N,m),K=I=J=0,N=M;for(var T=0;T<286;++T)G[T]=0;for(T=0;T<30;++T)H[T]=0}var V=2,W=0,X=A,Y=P-Q&32767;if(R>2&&O==E(M-Y))for(var Z=Math.min(x,R)-1,$=Math.min(32767,M),_=Math.min(258,R);Y<=$&&--X&&P!=Q;){if(t[M+V]==t[M+V-Y]){for(var rr=0;rr<_&&t[M+rr]==t[M+rr-Y];++rr);if(rr>V){if(V=rr,W=Y,rr>Z)break;var nr=Math.min(Y,rr-2),fr=0;for(T=0;T<nr;++T){var er=M-Y+T+32768&32767,ar=er-k[er]+32768&32767;ar>fr&&(fr=ar,Q=er)}}}Y+=(P=Q)-(Q=k[P])+32768&32767}if(W){F[K++]=268435456|u[V]<<18|s[W];var tr=31&u[V],or=31&s[W];J+=e[tr]+a[or],++G[257+tr],++H[or],L=M+V,++I}else F[K++]=t[M],++G[t[M]]}}m=q(t,g,c,F,G,H,J,K,N,M-N,m),c||(m=j(g,m,C))}return d(w,0,v+p(m)+l)},E=function(){var r=1,n=0;return{p:function(f){for(var e=r,a=n,t=f.length,o=0;o!=t;){for(var i=Math.min(o+5552,t);o<i;++o)a+=e+=f[o];e%=65521,a%=65521}r=e,n=a},d:function(){return(r>>>8<<16|(255&n)<<8|n>>>8)+2*((255&r)<<23)}}},F=function(r,n,f,e,a){return D(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,f,e,!a)},G=function(r,n,f){for(;f;++n)r[n]=f,f>>>=8},H=function(r,n){var f=n.level,e=0==f?0:f<6?1:9==f?3:2;r[0]=120,r[1]=e<<6|(e?32-2*e:1)};function I(r,n){void 0===n&&(n={});var f=E();f.p(r);var e=F(r,n,2,4);return H(e,n),G(e,e.length-4,f.d()),e}export var zlibSync=I

Sorry to waste your time with the bugs @Mugen87!

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 29, 2020

Great! I've completed my first PR to migrate loaders from JSZip.js and gunzip.js to fflate.

I change inflate to fflate in a separate PR when the first one was merged.

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 29, 2020

In FBXLoader, the following code is used from decompression right now:

var inflate = new Inflate( new Uint8Array( reader.getArrayBuffer( compressedLength ) ) ); // eslint-disable-line no-undef
var reader2 = new BinaryReader( inflate.decompress().buffer );

This can be converted to the following when using fflate which seems to work fine:

var data = fflate.unzlibSync( new Uint8Array( reader.getArrayBuffer( compressedLength ) ) ); // eslint-disable-line no-undef
var reader2 = new BinaryReader( data.buffer );

However, VTKLoader and EXRLoader uses Inflate like so:

var inflate = new Inflate( compressed, { resize: true, verify: true } ); // eslint-disable-line no-undef

Notice the additional option parameter. According to the docs resize means:

resize buffer(ArrayBuffer) when end of decompression (default: false)

Both loaders set resize to true. How should this be handled with fflate? Is this even relevant? It seems loading works fine if I use the same approach like FBXLoader.

@101arrowz
Copy link

101arrowz commented Dec 29, 2020

I'm not exactly sure what the resize option does, but it seems like an optimization more than anything. I checked its usage in the source code and it seems to change basically nothing; the only difference is allocating a new array of length LEN and copying bytes 0 to LEN into the new array vs. taking the subarray from 0 to LEN directly. If anything, the O(n) allocation + copy would be slower...

I actually took a closer look and found this comment that indicates that it's a memory optimization. This is applied by default in fflate because if it weren't, memory would be about 2x worse.

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 29, 2020

Okay, thanks! As mentioned in my previous post it already works with fflate but I thought it's a good opportunity to clarify the different usages of Inflate.

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 30, 2020

There is one place in the repository where a zip is generated. In the editor in Menubar.File.js:

var zip = new JSZip();
//
var output = editor.toJSON();
output.metadata.type = 'App';
delete output.history;
output = JSON.stringify( output, parseNumber, '\t' );
output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' );
zip.file( 'app.json', output );
//
var title = config.getKey( 'project/title' );
var manager = new THREE.LoadingManager( function () {
save( zip.generate( { type: 'blob' } ), ( title !== '' ? title : 'untitled' ) + '.zip' );
} );
var loader = new THREE.FileLoader( manager );
loader.load( 'js/libs/app/index.html', function ( content ) {
content = content.replace( '<!-- title -->', title );
var includes = [];
content = content.replace( '<!-- includes -->', includes.join( '\n\t\t' ) );
var editButton = '';
if ( config.getKey( 'project/editable' ) ) {
editButton = [
'',
' var button = document.createElement( \'a\' );',
' button.href = \'https://threejs.org/editor/#file=\' + location.href.split( \'/\' ).slice( 0, - 1 ).join( \'/\' ) + \'/app.json\';',
' button.style.cssText = \'position: absolute; bottom: 20px; right: 20px; padding: 10px 16px; color: #fff; border: 1px solid #fff; border-radius: 20px; text-decoration: none;\';',
' button.target = \'_blank\';',
' button.textContent = \'EDIT\';',
' document.body.appendChild( button );',
''
].join( '\n' );
}
content = content.replace( '\n\t\t\t/* edit button */\n', editButton );
zip.file( 'index.html', content );
} );
loader.load( 'js/libs/app.js', function ( content ) {
zip.file( 'js/app.js', content );
} );
loader.load( '../build/three.module.js', function ( content ) {
zip.file( 'js/three.module.js', content );
} );
loader.load( '../examples/jsm/webxr/VRButton.js', function ( content ) {
zip.file( 'js/VRButton.js', content );
} );

How could we replace this usage of JSZip with fflate? I guess we need an additional fflate build for this?

@101arrowz
Copy link

Yes, probably adding to fflate-deflate.js is the best solution.

@Mugen87
Copy link
Collaborator

Mugen87 commented Dec 30, 2020

Yes, that sounds good. I vote to place this file in editor/js/libs as long as it is not required elsewhere.

@101arrowz
Copy link

101arrowz commented 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

@sciecode
Copy link
Contributor

sciecode commented Jan 1, 2021

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

yep, still plan on finalizing the exporter. I had already taken a note to update current deflate to fflate's deflate, but thanks for the heads up 👍

@mrdoob
Copy link
Owner

mrdoob commented Jan 8, 2021

@101arrowz rather than doing custom subset builds, would it make sense to do something like fflate-deflate.module.js, fflate-zip.module.js, fflate-gunzip.module.js, fflate-zlib.module.js, ...?

@101arrowz
Copy link

101arrowz commented Jan 8, 2021

Not really, that wastes time just by HTTP overhead. Since ZIP and Zlib are literally a few hundred bytes different, it's worth bundling them together for reusability and if multiple examples are loaded with different API calls. If you worry about maintainability, unfortunately not much can be done unless NPM being required is OK.

@mrdoob
Copy link
Owner

mrdoob commented Jan 8, 2021

I see. Okay, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants