title: Convert zipped []byte to unzip []byte golang code
body: <p>I have []byte of zip file. I have to unzip it without creating a new file, and get a []byte of that unzipped file. Please help me to do that.</p>
  <p>I am making an API call and the response I get is the []byte in zipped format - I am trying to unzip it - and use it's content for creating a new zip file. So unzip - rezip.</p>
  <p>Language: Golang</p>
  <p>Code I've used:</p>
  <pre><code>func UnzipBytes(zippedBytes []byte) ([]byte, error) {
  
      reader := bytes.NewReader(zippedBytes)
      zipReader, err := zlib.NewReader(reader)
      if err != nil {
          return nil, err
      }
      defer zipReader.Close()
      p, err := ioutil.ReadAll(zipReader)
      if err != nil {
          return nil, err
      }
      return p, nil
  }
  </code></pre>
  <p>I get an error saying &quot;zlib: invalid header&quot;</p>
  <p>The code that was initially used to zip the []byte</p>
  <pre><code>buffer := new(bytes.Buffer)
  zipWriter := zip.NewWriter(buffer)
  zipFile, err := zipWriter.Create(file.name)
  _, err = zipFile.Write(file.content)
  </code></pre>
  <p>Hex dump of the []byte - the zippedBytes</p>
  <pre><code>00059350  78 b4 5b 0d 2b 81 c2 87  35 76 1b 11 4a ec 07 d1  |x.[.+...5v..J...|
  00059360  76 77 a2 e1 3b d9 12 e2  51 d4 c5 bd 4b 2f 09 da  |vw..;...Q...K/..|
  00059370  f7 21 c7 26 73 1f 8e da  f0 ff a3 52 f6 e2 00 e6  |.!.&amp;s......R....|
  </code></pre>