-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (44 loc) · 1006 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
package main
import (
"log"
"github.com/jmwoliver/lzw-go/commons"
"github.com/jmwoliver/lzw-go/flags"
"github.com/jmwoliver/lzw-go/lzw"
)
func main() {
file, compress, err := flags.GetFlags()
if err != nil {
log.Fatal(err)
}
// Run compress or decompress depending on what flag is used
err = runLzw(file, compress)
if err != nil {
log.Fatal(err)
}
}
func runLzw(file string, compress bool) error {
// true -> compress
// false -> decompress
if compress {
compressedSlice, err := lzw.Compress(file)
if err != nil {
return err
}
// Create the compressed file at the current directory
err = commons.CreateFile("./output/compressed.lzw", compressedSlice)
if err != nil {
return err
}
} else {
decompressedSlice, err := lzw.Decompress(file)
if err != nil {
return err
}
// Create the decompressed file at the current directory
err = commons.CreateFile("./output/decompressed.txt", decompressedSlice)
if err != nil {
return err
}
}
return nil
}