-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
88 lines (80 loc) · 1.79 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
package vaar
import "errors"
// WithCompression provides the compression algorithm of tar creation and extraction.
func WithCompression(algorithm Algorithm) Option {
return func(i private) error {
if algorithm.String() == unknownValue {
return ErrUnknownValue
}
switch i := i.(type) {
case *Composer:
i.algorithm = algorithm
case *Resolver:
i.algorithm = algorithm
default:
return ErrInapplicableOption
}
return nil
}
}
// WithLevel provides the compression level during tar creation.
func WithLevel(level Level) Option {
return func(i private) error {
if level.String() == unknownValue {
return ErrUnknownValue
}
c, ok := i.(*Composer)
if !ok {
return ErrInapplicableOption
}
c.level = level
return nil
}
}
// WithThread specifies the worker number during extraction.
func WithThread(n int) Option {
return func(i private) error {
if n < 1 {
return errors.New("thread must be positive")
}
r, ok := i.(*Resolver)
if !ok {
return ErrInapplicableOption
}
r.thread = n
return nil
}
}
// WithReadAhead specifies the maximum number of files to be read ahead.
func WithReadAhead(n int) Option {
return func(i private) error {
if n < 0 {
return errors.New("read ahead mustn't be negative")
}
switch i := i.(type) {
case *Composer:
i.readAhead = n
case *Resolver:
i.readAhead = n
default:
return ErrInapplicableOption
}
return nil
}
}
// WithThreshold specifies the threshold size in bytes of buffered files during extraction.
func WithThreshold(size int64) Option {
return func(i private) error {
if size < 0 {
return errors.New("threshold mustn't be negative")
}
c, ok := i.(*Resolver)
if !ok {
return ErrInapplicableOption
}
c.threshold = size
return nil
}
}
// TODO: WithStrip
// TODO: WithCallback