change(player): detect gzip file after decoding

This commit is contained in:
nick-delirium 2023-04-19 10:45:20 +02:00
parent 4ac476f9e1
commit 659c5b4b0f
3 changed files with 18 additions and 16 deletions

View file

@ -21,18 +21,21 @@ export function decryptSessionBytes(cypher: Uint8Array, keyString: string): Prom
.then(key => crypto.subtle.decrypt({ name: "AES-CBC", iv: iv}, key, cypher))
.then((bArray: ArrayBuffer) => new Uint8Array(bArray))
.then(async (u8Array: Uint8Array) => {
const now = performance.now()
const data = gunzipSync(u8Array)
console.debug(
"Decompression time",
performance.now() - now,
'size',
Math.floor(u8Array.byteLength/1024),
'->',
Math.floor(data.byteLength/1024),
'kb'
)
return data
const isGzip = u8Array[0] === 0x1F && u8Array[1] === 0x8B && u8Array[2] === 0x08;
if (isGzip) {
const now = performance.now()
const data = gunzipSync(u8Array)
console.debug(
"Decompression time",
performance.now() - now,
'size',
Math.floor(u8Array.byteLength/1024),
'->',
Math.floor(data.byteLength/1024),
'kb'
)
return data
} else return u8Array
})
//?? TS doesn not catch the `decrypt`` returning type
}

View file

@ -180,7 +180,7 @@ export default class App {
} else if (data.type === 'compress') {
const batch = data.batch
const batchSize = batch.byteLength
if (batchSize > this.compressionThreshold) {
if (batchSize > 10) {
gzip(data.batch, { mtime: 0 }, (err, result) => {
if (err) console.error(err)
// @ts-ignore

View file

@ -102,7 +102,7 @@ self.onmessage = ({ data }: any): any => {
if (data.type === 'compressed') {
if (!sender) {
console.debug('WebWorker: sender not initialised. Received auth.')
console.debug('WebWorker: sender not initialised. Compressed batch.')
initiateRestart()
return
}
@ -110,7 +110,7 @@ self.onmessage = ({ data }: any): any => {
}
if (data.type === 'uncompressed') {
if (!sender) {
console.debug('WebWorker: sender not initialised. Received auth.')
console.debug('WebWorker: sender not initialised. Uncompressed batch.')
initiateRestart()
return
}
@ -139,7 +139,6 @@ self.onmessage = ({ data }: any): any => {
data.pageNo,
data.timestamp,
data.url,
// onBatch
(batch) => sender && sender.push(batch),
)
if (sendIntervalID === null) {