| 12 | // Bun's test runner doesn't have CompressionStream (browser API). |
| 13 | // Use Bun's native zlib for the same deflate-raw + base64url pipeline. |
| 14 | function compress(data: unknown): string { |
| 15 | const json = JSON.stringify(data); |
| 16 | const compressed = deflateSync(new TextEncoder().encode(json)); |
| 17 | let binary = ""; |
| 18 | for (let i = 0; i < compressed.length; i++) { |
| 19 | binary += String.fromCharCode(compressed[i]); |
| 20 | } |
| 21 | return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, ""); |
| 22 | } |
| 23 | |
| 24 | function decompress(b64: string): unknown { |
| 25 | const base64 = b64.replace(/-/g, "+").replace(/_/g, "/"); |