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