forked from babel/sandboxes
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgzip.js
62 lines (59 loc) · 1.47 KB
/
gzip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* eslint-disable */
// from developit
function memo(fn, c = {}) {
return p => c[p] || (c[p] = fn(p));
}
// npm.im/greenlet
function greenlet(e) {
var n = new Worker(
URL.createObjectURL(
new Blob([
"onmessage=(" +
function (e) {
return function (n) {
var t = n.data;
return Promise.resolve()
.then(function () {
return e.apply(e, t[1]);
})
.then(
function (e) {
postMessage([t[0], null, e]);
},
function (e) {
postMessage([t[0], "" + e]);
}
);
};
} +
")(" +
e +
")",
])
)
),
t = 0,
r = {};
return (
(n.onmessage = function (e) {
var n = e.data,
t = n[0],
o = n[1];
r[t][o ? 1 : 0](o || n[2]), delete r[t];
}),
function () {
for (var e = [], o = arguments.length; o--; ) e[o] = arguments[o];
return new Promise(function (o, a) {
(r[++t] = [o, a]), n.postMessage([t, e]);
});
}
);
}
export const gzipSize = memo(
greenlet(code => {
if (!self.pako)
importScripts("https://unpkg.com/[email protected]/dist/pako_deflate.min.js");
const compressed = self.pako.gzip(code);
return compressed.byteLength || compressed.length;
})
);