Created
January 22, 2024 11:29
-
-
Save emlyn/e30ff8fa5b9f785db91a069fca3bf728 to your computer and use it in GitHub Desktop.
Decode base64 encoded gzipped string in Javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const decodePart = async function(data) { | |
const ds = new DecompressionStream("gzip"); | |
const resp = await fetch(`data:application/octet-stream;base64,${data}`); | |
const blob = await resp.blob(); | |
return new Response(blob.stream().pipeThrough(ds)).text(); | |
} | |
const decodeLine = async function(line) { | |
const GzipCompressionMagicHeader = 'H4sI'; | |
for (const part of line.split(',')) { | |
if (part.startsWith(GzipCompressionMagicHeader)) { | |
console.log(await decodePart(split)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment