forked from PretendoNetwork/nex-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompression.go
41 lines (33 loc) · 976 Bytes
/
compression.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package nex
import (
"bytes"
"compress/zlib"
"io/ioutil"
)
// DummyCompression represents no compression
type DummyCompression struct{}
// Compress returns the data as-is
func (compression *DummyCompression) Compress(data []byte) []byte {
return data
}
// Decompress returns the data as-is
func (compression *DummyCompression) Decompress(data []byte) []byte {
return data
}
// ZLibCompression represents ZLib compression
type ZLibCompression struct{}
// Compress returns the data as-is (needs to be updated to return ZLib compressed data)
func (compression *ZLibCompression) Compress(data []byte) []byte {
return data
}
// Decompress returns the data as-is (needs to be updated to return ZLib decompressed data)
func (compression *ZLibCompression) Decompress(data []byte) []byte {
b := bytes.NewReader(data)
r, err := zlib.NewReader(b)
if err != nil {
return []byte{}
}
defer r.Close()
decompressedData, _ := ioutil.ReadAll(r)
return decompressedData
}