-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (54 loc) · 1.7 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
58
59
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"os"
"github.com/alecthomas/kingpin"
"github.com/jeremaihloo/bigfile2blocks/cores"
// "fmt"
"strconv"
)
const defaultBlockSize = 1024 * 1024
var (
app = kingpin.New("bigfile2blocks", "A command-line bigfile2blocks application.")
blocksCommand = app.Command("blocks", "Blocks a big file")
combineCommand = app.Command("combine", "Combine blocks into a big file")
bigFilePath = app.Flag("bigfile", "Big file path.").Required().String()
outPutDir = app.Flag("outputs", "Number of packets to send").Required().String()
hash = app.Flag("hash", "Big file hash to check").Bool()
debug = app.Flag("debug", "Enable debug mode.").Bool()
timeout = app.Flag("timeout", "Timeout waiting for ping.").Default("5s").OverrideDefaultFromEnvar("PING_TIMEOUT").Short('t').Duration()
blockSize = app.Flag("block-size", "Block size").Default(strconv.Itoa(defaultBlockSize)).Int64()
ext = app.Flag("block-ext", "Block extension name").Default(".block").String()
)
func main() {
app.Version("0.0.1")
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
case blocksCommand.FullCommand():
if *hash {
md5, _ := cores.Md5(*bigFilePath, *blockSize)
fmt.Printf("hash: %s\n", md5)
}
err := cores.BigFileToBlocks(*bigFilePath, *outPutDir, *blockSize, *ext)
if err != nil {
if *debug {
panic(err)
}
fmt.Println(err)
return
}
fmt.Printf("blocks saved into %s\n", *outPutDir)
case combineCommand.FullCommand():
err := cores.Blocks2BigFileByDir(*outPutDir, *bigFilePath)
if err != nil {
if *debug {
panic(err)
}
fmt.Println(err)
return
}
if *hash {
md5, _ := cores.Md5(*bigFilePath, *blockSize)
fmt.Printf("hash: %s\n", md5)
}
}
}