This repository has been archived by the owner on Sep 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
100 lines (89 loc) · 2.04 KB
/
options.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package chunker
import (
"path/filepath"
"github.com/damoonazarpazhooh/File-Ingestion/pkg/utils"
"github.com/kardianos/osext"
"github.com/palantir/stacktrace"
)
// Option - this method is used to change splitter's configuration after
// crating a new instance
func (s *Multipart) Option(opts ...Option) error {
var err error
for _, opt := range opts {
opt(s)
}
s.stateLock.Lock()
defer s.stateLock.Unlock()
if len(s.root) != 0 {
s.root, err = filepath.Abs(s.root)
if err != nil {
err = stacktrace.Propagate(err, "[FATAL] Multipart : Error setting up root path (%s) for splitter", s.root)
return err
}
}
if len(s.root) == 0 {
path := "tmp"
selfPath, _ := osext.ExecutableFolder()
s.root = utils.PathJoin(selfPath, path)
}
return nil
}
// Option ...
type Option func(*Multipart)
// LogOps ...
func LogOps() Option {
return func(s *Multipart) {
s.stateLock.Lock()
defer s.stateLock.Unlock()
s.logOps = true
}
}
// WithRootPath -
func WithRootPath(arg string) Option {
return func(s *Multipart) {
s.stateLock.Lock()
defer s.stateLock.Unlock()
s.root = arg
}
}
// WithMetadataDirectoryPath -
func WithMetadataDirectoryPath(arg string) Option {
return func(s *Multipart) {
s.stateLock.Lock()
defer s.stateLock.Unlock()
s.rootMetaName = arg
}
}
// WithChunksDirectoryPath -
func WithChunksDirectoryPath(arg string) Option {
return func(s *Multipart) {
s.stateLock.Lock()
defer s.stateLock.Unlock()
s.rootChunksDir = arg
}
}
// WithEncryption -
func WithEncryption(key string) Option {
return func(s *Multipart) {
s.stateLock.Lock()
defer s.stateLock.Unlock()
s.encryptionKey = key
}
}
// WithChunkSizeInMegabytes -
func WithChunkSizeInMegabytes(arg int64) Option {
return func(s *Multipart) {
s.stateLock.Lock()
defer s.stateLock.Unlock()
// 000 is for versioning
s.chunkSize = int64(arg * 1 << 20)
}
}
// WithChunkSizeInKilobytes -
func WithChunkSizeInKilobytes(arg int64) Option {
return func(s *Multipart) {
s.stateLock.Lock()
defer s.stateLock.Unlock()
s.chunkSize = int64(arg * 1 << 10)
}
}