-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharchive.go
More file actions
58 lines (47 loc) · 765 Bytes
/
archive.go
File metadata and controls
58 lines (47 loc) · 765 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package buff
import (
"compress/gzip"
"compress/zlib"
"fmt"
"io"
)
type Compression int8
const (
None Compression = iota
Gzip
Zlib
)
func ArchiveReader(kind Compression, r io.Reader) (a io.Reader) {
var err error
switch kind {
case None:
a = r
case Gzip:
a, err = gzip.NewReader(r)
case Zlib:
a, err = zlib.NewReader(r)
default:
err = fmt.Errorf("Unknown Compression Type %d", kind)
}
if err != nil {
panic(err)
}
return a
}
func ArchiveWriter(kind Compression, w io.Writer) (a io.Writer) {
var err error
switch kind {
case None:
a = w
case Gzip:
a = gzip.NewWriter(w)
case Zlib:
a = zlib.NewWriter(w)
default:
err = fmt.Errorf("Unknown Compression Type %d", kind)
}
if err != nil {
panic(err)
}
return a
}