diff options
author | Mike Crute <mike@crute.us> | 2022-08-04 17:57:39 -0700 |
---|---|---|
committer | Mike Crute <mike@crute.us> | 2022-08-04 17:57:39 -0700 |
commit | 3eb5a943550842f4614d6873a7acbf63b82a0651 (patch) | |
tree | 6360f17b80b419b362909d7fdb6fa6466b92de69 | |
parent | f7b39e7e79e75396ccb0967b6c791f2e0264acef (diff) | |
download | go-inform-3eb5a943550842f4614d6873a7acbf63b82a0651.tar.bz2 go-inform-3eb5a943550842f4614d6873a7acbf63b82a0651.tar.xz go-inform-3eb5a943550842f4614d6873a7acbf63b82a0651.zip |
Support zlib compression
-rw-r--r-- | inform/codec.go | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/inform/codec.go b/inform/codec.go index 8147986..ac49aa1 100644 --- a/inform/codec.go +++ b/inform/codec.go | |||
@@ -2,6 +2,7 @@ package inform | |||
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | "bytes" | 4 | "bytes" |
5 | "compress/zlib" | ||
5 | "encoding/binary" | 6 | "encoding/binary" |
6 | "errors" | 7 | "errors" |
7 | "io" | 8 | "io" |
@@ -56,7 +57,18 @@ func (c *Codec) Unmarshal(fp io.Reader) (*InformWrapper, error) { | |||
56 | return nil, err | 57 | return nil, err |
57 | } | 58 | } |
58 | } else if w.IsZlibCompressed() { | 59 | } else if w.IsZlibCompressed() { |
59 | return nil, errors.New("payload is zlib compressed, not supported") | 60 | rb := bytes.NewReader(u) |
61 | wb := &bytes.Buffer{} | ||
62 | |||
63 | r, err := zlib.NewReader(rb) | ||
64 | if err != nil { | ||
65 | return nil, err | ||
66 | } | ||
67 | |||
68 | io.Copy(wb, r) | ||
69 | r.Close() | ||
70 | |||
71 | w.Payload = wb.Bytes() | ||
60 | } else { | 72 | } else { |
61 | w.Payload = u | 73 | w.Payload = u |
62 | } | 74 | } |