-
Notifications
You must be signed in to change notification settings - Fork 568
/
option.go
64 lines (53 loc) · 1.41 KB
/
option.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
package chunk
import (
lru "github.com/hashicorp/golang-lru/v2"
"github.com/pachyderm/pachyderm/v2/src/internal/pachhash"
)
// StorageOption configures a storage.
type StorageOption func(s *Storage)
// WithMemoryCacheSize sets the number of decrypted, uncompressed chunks that will be stored in memory.
func WithMemoryCacheSize(size int) StorageOption {
return func(s *Storage) {
mc, err := lru.New[pachhash.Output, []byte](size)
if err != nil {
panic(err)
}
s.memCache = mc
}
}
// WithSecret sets the secret used to generate chunk encryption keys
func WithSecret(secret []byte) StorageOption {
return func(s *Storage) {
s.createOpts.Secret = append([]byte{}, secret...)
}
}
// WithCompression sets the compression algorithm used to compress chunks
func WithCompression(algo CompressionAlgo) StorageOption {
return func(s *Storage) {
s.createOpts.Compression = algo
}
}
type BatcherOption func(b *Batcher)
func WithChunkCallback(cb ChunkFunc) BatcherOption {
return func(b *Batcher) {
b.chunkFunc = cb
b.entryFunc = nil
}
}
func WithEntryCallback(cb EntryFunc) BatcherOption {
return func(b *Batcher) {
b.chunkFunc = nil
b.entryFunc = cb
}
}
type ReaderOption func(*Reader)
func WithOffsetBytes(offsetBytes int64) ReaderOption {
return func(r *Reader) {
r.offsetBytes = offsetBytes
}
}
func WithPrefetchLimit(limit int) ReaderOption {
return func(r *Reader) {
r.prefetchLimit = limit
}
}