-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (44 loc) · 781 Bytes
/
main.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
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"os"
"compress/zlib"
"io"
"io/ioutil"
"flag"
)
func decode(input io.Reader, output io.Writer) error {
r, err := zlib.NewReader(input)
if err != nil {
return err
}
_, err = io.Copy(output, r)
if err != nil {
return err
}
r.Close()
return nil
}
func encode(input io.Reader, output io.Writer) error {
w := zlib.NewWriter(output)
content, err := ioutil.ReadAll(input)
if err != nil {
return err
}
_, err = w.Write(content)
w.Close()
return nil
}
func main() {
var isDecode bool
flag.BoolVar(&isDecode, "d",false, "Uncompress the data from stdin using zlib")
flag.Parse()
var err error
if isDecode {
err = decode(os.Stdin, os.Stdout)
} else {
err = encode(os.Stdin, os.Stdout)
}
if err!= nil {
panic(err)
}
}