-
Notifications
You must be signed in to change notification settings - Fork 38
/
decompressors.go
48 lines (39 loc) · 947 Bytes
/
decompressors.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
47
48
package fakemachine
import (
"compress/gzip"
"io"
"github.com/klauspost/compress/zstd"
"github.com/ulikunitz/xz"
)
func ZstdDecompressor(dst io.Writer, src io.Reader) error {
decompressor, err := zstd.NewReader(src)
if err != nil {
return err
}
defer decompressor.Close()
_, err = io.Copy(dst, decompressor)
return err
}
func XzDecompressor(dst io.Writer, src io.Reader) error {
decompressor, err := xz.NewReader(src)
if err != nil {
return err
}
// There is no Close() API. See: https://github.com/ulikunitz/xz/issues/45
//defer decompressor.Close()
_, err = io.Copy(dst, decompressor)
return err
}
func GzipDecompressor(dst io.Writer, src io.Reader) error {
decompressor, err := gzip.NewReader(src)
if err != nil {
return err
}
defer decompressor.Close()
_, err = io.Copy(dst, decompressor)
return err
}
func NullDecompressor(dst io.Writer, src io.Reader) error {
_, err := io.Copy(dst, src)
return err
}