import { gunzipSync, gzipSync } from 'fflate'; export const objectToPayload = (object: any) => { const asString = JSON.stringify(object); const asUint8Array = new TextEncoder().encode(asString); const asCompressedUint8Array = gzipSync(asUint8Array, { level: 9 }); const asCompressedString = String.fromCharCode(...asCompressedUint8Array); const asBase64 = btoa(asCompressedString); return asBase64; }; export const payloadToObject = (payload: string): any => { const asGzippedUint8String = atob(payload); const asGzippedUint8 = new Uint8Array(asGzippedUint8String.length); for (let i = 0; i < asGzippedUint8String.length; i++) { asGzippedUint8[i] = asGzippedUint8String.charCodeAt(i); } const asUint8 = gunzipSync(asGzippedUint8); const asString = new TextDecoder().decode(asUint8); return JSON.parse(asString); };