Node.js Decompress base64 encoded zipped string with gzip

Viewed 1984

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?

1 Answers

Use this function to decode the binary.

Usage Example:

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

Related