-
Notifications
You must be signed in to change notification settings - Fork 4
/
utils.go
45 lines (41 loc) · 877 Bytes
/
utils.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
42
43
44
45
package mnemosyne
import (
"bytes"
"compress/zlib"
"io"
"strings"
)
func MakeKey(keys ...string) string {
return strings.Join(keys, ";")
}
// func CompressLz4(input []byte) []byte {
// var buf bytes.Buffer
// w := lz4.NewWriter(&buf)
// w.Write(input)
// w.Close()
// compressed := buf.Bytes()
// return compressed
// }
// func DecompressLz4(input []byte) []byte {
// var out bytes.Buffer
// r := lz4.NewReader(bytes.NewBuffer(input))
// io.Copy(&out, r)
// original := out.Bytes()
// return original
// }
func CompressZlib(input []byte) []byte {
var buf bytes.Buffer
w := zlib.NewWriter(&buf)
w.Write(input)
w.Close()
compressed := buf.Bytes()
return compressed
}
func DecompressZlib(input []byte) []byte {
var out bytes.Buffer
r, _ := zlib.NewReader(bytes.NewBuffer(input))
io.Copy(&out, r)
r.Close()
original := out.Bytes()
return original
}