forked from pberkel/caddy-storage-redis
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompression.go
More file actions
42 lines (32 loc) · 703 Bytes
/
compression.go
File metadata and controls
42 lines (32 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
package storageredis
import (
"bytes"
"compress/flate"
"io/ioutil"
)
func (rs *RedisStorage) compress(input []byte) ([]byte, error) {
var buf bytes.Buffer
writer, err := flate.NewWriter(&buf, flate.DefaultCompression)
if err != nil {
return nil, err
}
_, err = writer.Write(input)
if err != nil {
return nil, err
}
if err = writer.Close(); err != nil {
return nil, err
}
return buf.Bytes(), nil
}
func (rs *RedisStorage) uncompress(input []byte) ([]byte, error) {
reader := flate.NewReader(bytes.NewReader(input))
output, err := ioutil.ReadAll(reader)
if err != nil {
return nil, err
}
if err = reader.Close(); err != nil {
return nil, err
}
return output, nil
}