-
Notifications
You must be signed in to change notification settings - Fork 24
/
hw-zstd.html
35 lines (29 loc) · 1.25 KB
/
hw-zstd.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Zstandard WASM</title>
</head>
<body>
<div id="placeholder"></div>
<script type="module">
// Prefer local version (if available) ---
const ZstdLocal = await import("./dist/index.js").then(m => m.Zstd).catch(() => undefined);
import { Zstd as ZstdExternal } from "https://cdn.jsdelivr.net/npm/@hpcc-js/wasm/dist/index.js";
const Zstd = ZstdLocal ?? ZstdExternal;
const zstd = await Zstd.load();
const data = new Uint8Array(Array.from({ length: 100000 }, (_, i) => i % 256));
const compressed_data = await zstd.compress(data);
const decompressed_data = await zstd.decompress(compressed_data);
document.getElementById("placeholder").innerHTML = `\
<ul>
<li>Default Compression Level: ${await zstd.defaultCLevel()}</li>
<li>Decompressed Size (bytes): ${decompressed_data.byteLength}</li>
<li>Data Size (bytes): ${data.byteLength}</li>
<li>Compressed Size (bytes): ${compressed_data.byteLength}</li>
<li>Decompressed Size (bytes): ${decompressed_data.byteLength}</li>
</ul>
`;
</script>
</body>
</html>