-
-
Save debnath/6d573cbd8acec89560c146050dfaabb8 to your computer and use it in GitHub Desktop.
gzip / gunzip functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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