blob: b0f44c3fbbb43980ca4249280db3af58ba507da0 (
plain) (
blame)
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 main
import (
"errors"
"flag"
"io/ioutil"
"os"
"github.com/golang/snappy"
)
var (
decode = flag.Bool("d", false, "decode")
encode = flag.Bool("e", false, "encode")
)
func run() error {
flag.Parse()
if *decode == *encode {
return errors.New("exactly one of -d or -e must be given")
}
in, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
out := []byte(nil)
if *decode {
out, err = snappy.Decode(nil, in)
if err != nil {
return err
}
} else {
out = snappy.Encode(nil, in)
}
_, err = os.Stdout.Write(out)
return err
}
func main() {
if err := run(); err != nil {
os.Stderr.WriteString(err.Error() + "\n")
os.Exit(1)
}
}
|