openreplay/frontend/app/player/common/unpack.ts
Delirium e207d37e69
Ios player v2 (#1901)
* feat(ui): new ios player start

* fix(ui): image player

* fix(ui): fix autoplay

* fix(ui): fix copy paste code; error handler; default mode null

* fix(ui): fix loader animation

* fix(ui): memory cleanup

* fix(ui): memory cleanup
2024-02-22 12:50:19 +01:00

40 lines
1,020 B
TypeScript

import * as fzstd from 'fzstd';
import { gunzipSync } from 'fflate';
const unpack = (b: Uint8Array): Uint8Array => {
// zstd magical numbers 40 181 47 253
const isZstd = b[0] === 0x28 && b[1] === 0xb5 && b[2] === 0x2f && b[3] === 0xfd;
const isGzip = b[0] === 0x1f && b[1] === 0x8b && b[2] === 0x08;
let data = b;
if (isGzip) {
const now = performance.now();
const uData = gunzipSync(b);
console.debug(
'Gunzip time',
Math.floor(performance.now() - now) + 'ms',
'size',
Math.floor(b.byteLength / 1024),
'->',
Math.floor(uData.byteLength / 1024),
'kb'
);
data = uData;
}
if (isZstd) {
const now = performance.now();
const uData = fzstd.decompress(b);
console.debug(
'Zstd unpack time',
Math.floor(performance.now() - now) + 'ms',
'size',
Math.floor(b.byteLength / 1024),
'->',
Math.floor(uData.byteLength / 1024),
'kb'
);
data = uData;
}
return data;
};
export default unpack;