diff --git a/respond/collector.go b/respond/collector.go index d440a7a..5b32204 100644 --- a/respond/collector.go +++ b/respond/collector.go @@ -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 }