Deflate directly
This commit is contained in:
parent
c88d13723a
commit
97348afa75
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user