Skip to content

Commit

Permalink
fix(Cache): Use TextEncoder to encode compressed data
Browse files Browse the repository at this point in the history
  • Loading branch information
LuanRT committed Jun 5, 2024
1 parent b588554 commit 384b80e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/core/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ export default class Player {
async cache(cache?: ICache): Promise<void> {
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);
Expand Down
2 changes: 1 addition & 1 deletion src/core/Session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 384b80e

Please sign in to comment.