UNPKG

@citizenwallet/sdk

Version:

An sdk to easily work with citizen wallet.

18 lines (15 loc) 660 B
import { gzipSync, gunzipSync } from "fflate"; export const compress = (data: string): string => { const encodedData = new TextEncoder().encode(data); const gzippedData = gzipSync(encodedData, { level: 6 }); const base64Data = btoa(String.fromCharCode(...gzippedData)) .replace(/\+/g, "-") .replace(/\//g, "_"); return base64Data; }; export const decompress = (data: string): string => { const base64Data = data.replace(/-/g, "+").replace(/_/g, "/"); const gzippedData = Uint8Array.from(atob(base64Data), (c) => c.charCodeAt(0)); const decompressedData = new TextDecoder().decode(gunzipSync(gzippedData)); return decompressedData; };