diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-08-01 12:55:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-01 12:55:19 +0200 |
commit | ee15e76da0a032bad7cb94295dc32e2553f10850 (patch) | |
tree | 5fd414e27814eba6a57c8cb34cc86b71f85c20c7 /vendor/github.com/klauspost/compress/zstd/decoder_options.go | |
parent | 5056964d09c5de31e10bb226acdb9cb24dce84e9 (diff) | |
parent | 9d6dce119949d340ebb42becae018a3c11148690 (diff) | |
download | podman-ee15e76da0a032bad7cb94295dc32e2553f10850.tar.gz podman-ee15e76da0a032bad7cb94295dc32e2553f10850.tar.bz2 podman-ee15e76da0a032bad7cb94295dc32e2553f10850.zip |
Merge pull request #3675 from rhatdan/storage
Vendor in containers/storage v1.12.16
Diffstat (limited to 'vendor/github.com/klauspost/compress/zstd/decoder_options.go')
-rw-r--r-- | vendor/github.com/klauspost/compress/zstd/decoder_options.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/vendor/github.com/klauspost/compress/zstd/decoder_options.go b/vendor/github.com/klauspost/compress/zstd/decoder_options.go new file mode 100644 index 000000000..52c1eb066 --- /dev/null +++ b/vendor/github.com/klauspost/compress/zstd/decoder_options.go @@ -0,0 +1,66 @@ +// Copyright 2019+ Klaus Post. All rights reserved. +// License information can be found in the LICENSE file. +// Based on work by Yann Collet, released under BSD License. + +package zstd + +import ( + "errors" + "fmt" + "runtime" +) + +// DOption is an option for creating a decoder. +type DOption func(*decoderOptions) error + +// options retains accumulated state of multiple options. +type decoderOptions struct { + lowMem bool + concurrent int + maxDecodedSize uint64 +} + +func (o *decoderOptions) setDefault() { + *o = decoderOptions{ + // use less ram: true for now, but may change. + lowMem: true, + concurrent: runtime.GOMAXPROCS(0), + } + o.maxDecodedSize = 1 << 63 +} + +// WithDecoderLowmem will set whether to use a lower amount of memory, +// but possibly have to allocate more while running. +func WithDecoderLowmem(b bool) DOption { + return func(o *decoderOptions) error { o.lowMem = b; return nil } +} + +// WithDecoderConcurrency will set the concurrency, +// meaning the maximum number of decoders to run concurrently. +// The value supplied must be at least 1. +// By default this will be set to GOMAXPROCS. +func WithDecoderConcurrency(n int) DOption { + return func(o *decoderOptions) error { + if n <= 0 { + return fmt.Errorf("Concurrency must be at least 1") + } + o.concurrent = n + return nil + } +} + +// WithDecoderMaxMemory allows to set a maximum decoded size for in-memory +// (non-streaming) operations. +// Maxmimum and default is 1 << 63 bytes. +func WithDecoderMaxMemory(n uint64) DOption { + return func(o *decoderOptions) error { + if n == 0 { + return errors.New("WithDecoderMaxmemory must be at least 1") + } + if n > 1<<63 { + return fmt.Errorf("WithDecoderMaxmemorymust be less than 1 << 63") + } + o.maxDecodedSize = n + return nil + } +} |