-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
57 lines (52 loc) · 1.17 KB
/
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
package main
import (
"compress/zlib"
"flag"
"io"
"log"
"os"
"time"
csd "github.com/toravir/csd/libs"
)
func main() {
inFile := flag.String("in", "<stdin>", "Input File (cbor Encoded)")
outFile := flag.String("out", "<stdout>", "Output File to which decoded JSON will be written to (WILL overwrite if already present).")
compressedIn := flag.Bool("compress", false, "Use if input stream is zlib compressed")
follow := flag.Bool("follow", false, "tail the file (default for stdin)")
flag.Parse()
csd.DecodeTimeZone, _ = time.LoadLocation("America/Los_Angeles")
var in io.Reader = os.Stdin
var out io.Writer = os.Stdout
ch := make(chan struct{})
if *inFile != "<stdin>" {
f, err := csd.NewFollowReader(*inFile, *follow, ch)
if err != nil {
log.Fatal(err)
}
in = f
defer func() {
f.Close()
}()
}
if *compressedIn {
zin, err := zlib.NewReader(in)
if err != nil {
log.Fatal(err)
}
in = zin
defer func() {
zin.Close()
}()
}
if *outFile != "<stdout>" {
f, err := os.OpenFile(*outFile, os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
log.Fatal(err)
}
out = f
defer func() {
f.Close()
}()
}
csd.Cbor2JsonManyObjects(in, out)
}