From 384b80ee41d7547a00d8dc17c50c8542629264b5 Mon Sep 17 00:00:00 2001 From: Luan Date: Wed, 5 Jun 2024 12:30:12 -0300 Subject: [PATCH] fix(Cache): Use `TextEncoder` to encode compressed data --- src/core/Player.ts | 6 ++++-- src/core/Session.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/Player.ts b/src/core/Player.ts index 4c8648d1..80ff265c 100644 --- a/src/core/Player.ts +++ b/src/core/Player.ts @@ -186,8 +186,10 @@ export default class Player { async cache(cache?: ICache): Promise { if (!cache) return; - const sig_buf = Buffer.from(LZW.compress(this.sig_sc)); - const nsig_buf = Buffer.from(LZW.compress(this.nsig_sc)); + const encoder = new TextEncoder(); + + const sig_buf = encoder.encode(LZW.compress(this.sig_sc)); + const nsig_buf = encoder.encode(LZW.compress(this.nsig_sc)); const buffer = new ArrayBuffer(12 + sig_buf.byteLength + nsig_buf.byteLength); const view = new DataView(buffer); diff --git a/src/core/Session.ts b/src/core/Session.ts index c21456df..c021ea08 100644 --- a/src/core/Session.ts +++ b/src/core/Session.ts @@ -392,7 +392,7 @@ export default class Session extends EventEmitter { Log.info(TAG, 'Compressing and caching session data.'); - const compressed_session_data = Buffer.from(LZW.compress(JSON.stringify(session_data))); + const compressed_session_data = new TextEncoder().encode(LZW.compress(JSON.stringify(session_data))); const buffer = new ArrayBuffer(4 + compressed_session_data.byteLength); new DataView(buffer).setUint32(0, compressed_session_data.byteLength, true); // (Luan) XX: Leave this here for debugging purposes