How to decompress zlib-compressed data in Go?

To decompress zlib-compressed data in Go, you can use the compress/zlib package from the Go standard library. Here's an example of how to do it:

package main import ( "bytes" "compress/zlib" "fmt" "io/ioutil" ) func main() { // Compressed data compressedData := []byte{120, 156, 202, 72, 205, 201, 201, 215, 81, 40, 207, 47, 202, 73, 1, 0, 2, 198, 1, 62} // Create a reader from the compressed data r := bytes.NewReader(compressedData) // Create a zlib reader zr, err := zlib.NewReader(r) if err != nil { panic(err) } defer zr.Close() // Decompress the data decompressedData, err := ioutil.ReadAll(zr) if err != nil { panic(err) } fmt.Println("Decompressed data:", decompressedData) }

In this example, we create a bytes.Reader from the compressed data and then pass it to zlib.NewReader() to create a zlib reader. We then use ioutil.ReadAll() to read the decompressed data from the zlib reader. Finally, we print the decompressed data to the console.

Make sure to import the necessary packages bytes, compress/zlib, fmt, and io/ioutil.