-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
70 lines (58 loc) · 1.73 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
68
69
70
package main
import (
"fmt"
"io"
"os"
"runtime"
"github.com/gaborkolarovics/hsplit/pkg/writer"
"github.com/integrii/flaggy"
)
var (
version = "unversioned"
commit string
date string
fileName string
prefix string = "x"
bits uint = 16
minSize int = 1024
minBytesOfPart int = 1024
fanout uint = 8
)
func main() {
info := fmt.Sprintf(
"%s\t[OS: %s; Arch: %s; commit: %s; date: %s]",
version,
runtime.GOOS,
runtime.GOARCH,
commit,
date,
)
flaggy.SetName("hsplit")
flaggy.SetDescription("split a file into pieces with rolling hash")
flaggy.DefaultParser.AdditionalHelpPrepend = "\r\nDESCRIPTION\r\n\t" +
"Output pieces of FILE to PREFIXaaaa, PREFIXaaab, ...; default trailing zero bits in the rolling checksum is 16, and default PREFIX is 'x'."
flaggy.AddPositionalValue(&fileName, "FILE", 1, true, "filename_desc")
flaggy.AddPositionalValue(&prefix, "PREFIX", 2, false, "prefix_desc")
flaggy.UInt(&bits, "b", "bits", "SplitBits is the number of trailing zero bits in the rolling checksum required to produce a chunk.")
flaggy.Int(&minSize, "m", "minSize", "MinSize is the minimum chunk size.")
flaggy.UInt(&fanout, "f", "fanout", "Fan-out of the nodes in the tree produced.")
flaggy.Int(&minBytesOfPart, "p", "minBytesOfPart", "MinBytesOfPart is the minimum file part size")
flaggy.SetVersion(info)
flaggy.Parse()
f, err := os.Open(fileName)
if err != nil {
check(err)
}
defer f.Close()
w := writer.NewWriter(writer.Prefix(prefix), writer.Bits(bits), writer.Fanout(fanout), writer.MinSize(minSize), writer.MinBytesOfPart(minBytesOfPart))
_, err = io.Copy(w, f)
if err != nil {
check(err)
}
w.Close()
}
func check(e error) {
if e != nil {
panic(e)
}
}