-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (39 loc) · 922 Bytes
/
main.go
File metadata and controls
50 lines (39 loc) · 922 Bytes
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 (
"bytecaster/cli"
"bytecaster/encoding"
"bytecaster/encryption"
"bytecaster/output"
"log"
"os"
)
// TODO: Add comment with key and all used algorithms, and credits
func main() {
flags := cli.ParseCli()
fileInfo, err := os.Stat(flags.Input)
if err != nil {
log.Fatal("Error stating file:", err)
}
fileSize := fileInfo.Size()
data := make([]byte, fileSize)
file, err := os.Open(flags.Input)
if err != nil {
log.Fatal("Error opening file:", err)
}
defer file.Close()
_, err = file.Read(data)
if err != nil && err.Error() != "EOF" {
log.Fatal("Error reading file:", err)
}
// Encryption
if flags.EncryptionEnabled {
data = encryption.EncryptData(data, flags.EncryptionAlg, flags.EncryptionKey)
}
// Encoding
if flags.EncodingEnabled {
data = encoding.EncodeData(data, flags.Encoding)
}
// Output format
output.Output(data, flags.OutputFormat)
os.Exit(0)
}