-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcompress.go
More file actions
44 lines (39 loc) · 703 Bytes
/
Copy pathcompress.go
File metadata and controls
44 lines (39 loc) · 703 Bytes
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
42
43
44
package disttopk
import (
"bytes"
"compress/zlib"
"io"
)
const USE_COMPRESSION = true
func CompressBytes(in []byte) []byte {
if USE_COMPRESSION {
var b bytes.Buffer
w := zlib.NewWriter(&b)
if _, err := w.Write(in); err != nil {
panic(err)
}
if err := w.Close(); err != nil {
panic(err)
}
return b.Bytes()
}
return in
}
func DecompressBytes(in []byte) []byte {
if USE_COMPRESSION {
inbufr := bytes.NewReader(in)
r, err := zlib.NewReader(inbufr)
if err != nil {
panic(err)
}
var outbuf bytes.Buffer
if _, err := io.Copy(&outbuf, r); err != nil {
panic(err)
}
if err := r.Close(); err != nil {
panic(err)
}
return outbuf.Bytes()
}
return in
}