-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathextractor_options.go
32 lines (28 loc) · 988 Bytes
/
extractor_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
package fastzip
// ExtractorOption is an option used when creating an extractor.
type ExtractorOption func(*extractorOptions) error
type extractorOptions struct {
concurrency int
chownErrorHandler func(name string, err error) error
}
// WithExtractorConcurrency will set the maximum number of files being
// extracted concurrently. The default is set to GOMAXPROCS.
func WithExtractorConcurrency(n int) ExtractorOption {
return func(o *extractorOptions) error {
if n <= 0 {
return ErrMinConcurrency
}
o.concurrency = n
return nil
}
}
// WithExtractorChownErrorHandler sets an error handler to be called if errors are
// encountered when trying to preserve ownership of extracted files. Returning
// nil will continue extraction, returning any error will cause Extract() to
// error.
func WithExtractorChownErrorHandler(fn func(name string, err error) error) ExtractorOption {
return func(o *extractorOptions) error {
o.chownErrorHandler = fn
return nil
}
}