Skip to content

Instantly share code, notes, and snippets.

@debnath
Created January 3, 2018 03:14
Show Gist options
  • Save debnath/6d573cbd8acec89560c146050dfaabb8 to your computer and use it in GitHub Desktop.
Save debnath/6d573cbd8acec89560c146050dfaabb8 to your computer and use it in GitHub Desktop.
gzip / gunzip functions
//Gzip will take an uncompressed bytestream and gzip it
func Gzip(unzip []byte) []byte {
var zip bytes.Buffer
gz := gzip.NewWriter(&zip)
if _, err := gz.Write(unzip); err != nil {
panic(err)
}
if err := gz.Flush(); err != nil {
panic(err)
}
if err := gz.Close(); err != nil {
panic(err)
}
return zip.Bytes()
}
//Gunzip will take a gzipped bytestream and unzip it
func Gunzip(zip []byte) []byte {
rdata := bytes.NewReader(zip)
r, _ := gzip.NewReader(rdata)
unzip, err := ioutil.ReadAll(r)
if err != nil {
panic(err)
}
return unzip
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment