fzstd
fzstd copied to clipboard
Fail if Uint8Array not passed
index.html
<!DOCTYPE html>
<html>
<head>
<script type="module" src="zstandard-test.js"></script>
</head>
</html>
zstandard-test.js
import * as fzstd from 'https://cdn.skypack.dev/[email protected]?min';
console.time('fzstd fetch');
const compressedData = await fetch('data.bin.zst').then(
res => res.arrayBuffer()
);
console.timeEnd('fzstd fetch');
console.log('fzstd compressed size:', compressedData.byteLength);
console.time('fzstd decompress');
const decompressed = fzstd.decompress(compressedData);
console.timeEnd('fzstd decompress');
console.log('fzstd decompressed size:', decompressed.byteLength);
console.time('fzstd decompress2');
const outBuf = new Uint8Array(100000000);
const decompressed2 = fzstd.decompress(compressedData, outBuf);
console.timeEnd('fzstd decompress2');
console.log('fzstd decompressed2 size:', decompressed2.byteLength);
Results:
fzstd fetch: 345.969970703125 ms
fzstd compressed size: 31354107
fzstd decompress: 0.135986328125 ms
fzstd decompressed size: 0
decompress2: 0.2998046875 ms
decompressed2 size: 0
Size should be ~80MB:
$ ls -lh data.bin.zst
-rw-r--r-- 1 user user 30M Aug 5 12:25 data.bin.zst
$ zstd -d data.bin.zst
data.bin.zst : 88604716 bytes
Edit: I figured out I missed this step
const compressed = new Uint8Array(compressedData);
Probably a good idea to error out if a non-Uint8Array is passed vs. silent failure