-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
58 lines (51 loc) · 1.72 KB
/
config.go
File metadata and controls
58 lines (51 loc) · 1.72 KB
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
package imx
import "time"
// config holds configuration options for metadata extraction.
// This type is unexported; users configure via Option functions.
type config struct {
HTTPTimeout time.Duration // HTTP request timeout for URL fetching
MaxBytes int64 // Maximum bytes to read from any source (0 = unlimited)
BufferSize int // Read buffer size for streaming sources
}
// defaultConfig returns a config with reasonable defaults
func defaultConfig() config {
return config{
HTTPTimeout: 30 * time.Second, // 30 second timeout
MaxBytes: 1 << 30, // 1GB limit to handle large RAW files
BufferSize: 64 << 10, // 64KB streaming buffer
}
}
// Option is a functional option for configuring an Extractor
type Option func(*config)
// WithHTTPTimeout sets the HTTP request timeout for URL fetching.
// The timeout applies only to MetadataFromURL operations.
//
// Panics if d is negative. A timeout of 0 means no timeout (unlimited).
func WithHTTPTimeout(d time.Duration) Option {
if d < 0 {
panic("imx: HTTPTimeout must be non-negative")
}
return func(cfg *config) {
cfg.HTTPTimeout = d
}
}
// WithMaxBytes sets an upper bound on the total bytes that can be read from
// any source (file, reader, or URL). A value of 0 means no limit.
func WithMaxBytes(n int64) Option {
if n < 0 {
panic("imx: MaxBytes must be non-negative")
}
return func(cfg *config) {
cfg.MaxBytes = n
}
}
// WithBufferSize sets the streaming read buffer size used for reader/URL inputs.
// A value of 0 falls back to the default buffer size.
func WithBufferSize(n int) Option {
if n < 0 {
panic("imx: BufferSize must be non-negative")
}
return func(cfg *config) {
cfg.BufferSize = n
}
}