Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js Decompress base64 encoded zipped string with gzip

First time posting on here, so sorry if I'm missing anything. I'm trying to decode this base64 string in Node.js like so:

encoded_string = H4sIAAAAAAAA//NIzcnJVwjPL8pJUQQAoxwpHAwAAAA=
decoded_string = Buffer.from(encoded_string, 'base64').toString('binary')

My goal is for decoded_string to evaluate to "Hello world!", but I need to use the gzip algorithm to output the correct value. Any pointers?

like image 630
magscodes Avatar asked Sep 17 '25 03:09

magscodes


1 Answers

Use this function to decode the binary.

Usage Example:

zlib.gunzipSync(Buffer.from(encoded_string, 'base64')).toString('utf8');

like image 86
Mark Adler Avatar answered Sep 18 '25 16:09

Mark Adler