-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompress.go
46 lines (42 loc) · 1020 Bytes
/
compress.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
46
package starenv
import (
"bytes"
"compress/bzip2"
"compress/flate"
"compress/gzip"
"io/ioutil"
)
// Gzip decompresses gzipped compressed ref and returns it. Default tag for this
// derefer is "gz".
func Gzip(ref string) (string, error) {
b := bytes.NewBufferString(ref)
r, err := gzip.NewReader(b)
if err != nil {
return "", err
}
out, err := ioutil.ReadAll(r)
if err != nil {
return "", err
}
return string(out), nil
}
// Bzip2 decompresses bzipped2 compressed ref and returns it. Default tag for
// this derefer is "bz2".
func Bzip2(ref string) (string, error) {
b := bytes.NewBufferString(ref)
out, err := ioutil.ReadAll(bzip2.NewReader(b))
if err != nil {
return "", err
}
return string(out), nil
}
// Flate decompresses flate compressed ref and returns it. Default tag for this
// derefer is "flate".
func Flate(ref string) (string, error) {
b := bytes.NewBufferString(ref)
out, err := ioutil.ReadAll(flate.NewReader(b))
if err != nil {
return "", err
}
return string(out), nil
}