Skip to content

Instantly share code, notes, and snippets.

@cristoslc
Created September 7, 2023 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cristoslc/43a08ee1ce2ec9ac337da0271b87ecfa to your computer and use it in GitHub Desktop.
Save cristoslc/43a08ee1ce2ec9ac337da0271b87ecfa to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Base64Url Decompress</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.1.0/pako.min.js"></script>
</head>
<body>
<pre id="output"></pre>
<script>
function base64UrlToBase64(base64Url) {
let base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
const padding = base64.length % 4;
if (padding) {
base64 += '='.repeat(4 - padding);
}
return base64;
}
const encodedData = "YOUR DATA HERE"; // your data here
// Convert base64url to standard base64
const base64 = base64UrlToBase64(encodedData);
// Base64 decode
const base64Decoded = atob(base64);
// Convert the base64-decoded data to a Uint8Array
const charData = base64Decoded.split('').map(x => x.charCodeAt(0));
const byteArray = new Uint8Array(charData);
// Decompress using Pako
const decompressed = pako.inflate(byteArray, { to: 'string' });
// Displaying the decompressed data
document.getElementById("output").textContent = decompressed;
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment