Skip to content

Instantly share code, notes, and snippets.

@jmoiron
Created July 23, 2014 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmoiron/1fd73d3362fb31113ded to your computer and use it in GitHub Desktop.
Save jmoiron/1fd73d3362fb31113ded to your computer and use it in GitHub Desktop.
func LoadGzippedJSON(r io.Reader, v interface{}) error {
data, err := ioutil.ReadAll(r)
if err != nil {
return err
}
// oh wait, we need a Reader again..
raw := bytes.NewBuffer(data)
unz, err := gzip.NewReader(raw)
if err != nil {
return err
}
buf, err := ioutil.ReadAll(unz)
if err != nil {
return err
}
return json.Unmarshal(buf, &v)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment