Deflate directly

This commit is contained in:
Julian Kornberger 2016-03-19 23:27:07 +01:00
parent c88d13723a
commit 97348afa75
1 changed files with 6 additions and 14 deletions

View File

@ -4,7 +4,6 @@ import (
"bytes"
"compress/flate"
"encoding/json"
"io/ioutil"
"log"
"net"
"reflect"
@ -112,23 +111,16 @@ func (coll *Collector) parser() {
func (coll *Collector) parse(response *Response) (err error) {
// deflater
reader := flate.NewReader(bytes.NewReader(response.Raw))
defer reader.Close()
decompressed, err := ioutil.ReadAll(reader)
if err != nil {
return
}
// Deflate
deflater := flate.NewReader(bytes.NewReader(response.Raw))
defer deflater.Close()
// Unmarshal
res := &data.ResponseData{}
err = json.Unmarshal(decompressed, res)
if err != nil {
return
if err = json.NewDecoder(deflater).Decode(res); err == nil {
coll.onReceive(response.Address, res)
}
coll.onReceive(response.Address, res)
return
}