go.mod: github.com/klauspost/compress v1.16.0
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
This commit is contained in:
		
							
								
								
									
										36
									
								
								vendor/github.com/klauspost/compress/zstd/encoder_options.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										36
									
								
								vendor/github.com/klauspost/compress/zstd/encoder_options.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -3,6 +3,8 @@ package zstd
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"math"
 | 
			
		||||
	"math/bits"
 | 
			
		||||
	"runtime"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
@@ -47,22 +49,22 @@ func (o encoderOptions) encoder() encoder {
 | 
			
		||||
	switch o.level {
 | 
			
		||||
	case SpeedFastest:
 | 
			
		||||
		if o.dict != nil {
 | 
			
		||||
			return &fastEncoderDict{fastEncoder: fastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), lowMem: o.lowMem}}}
 | 
			
		||||
			return &fastEncoderDict{fastEncoder: fastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), bufferReset: math.MaxInt32 - int32(o.windowSize*2), lowMem: o.lowMem}}}
 | 
			
		||||
		}
 | 
			
		||||
		return &fastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), lowMem: o.lowMem}}
 | 
			
		||||
		return &fastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), bufferReset: math.MaxInt32 - int32(o.windowSize*2), lowMem: o.lowMem}}
 | 
			
		||||
 | 
			
		||||
	case SpeedDefault:
 | 
			
		||||
		if o.dict != nil {
 | 
			
		||||
			return &doubleFastEncoderDict{fastEncoderDict: fastEncoderDict{fastEncoder: fastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), lowMem: o.lowMem}}}}
 | 
			
		||||
			return &doubleFastEncoderDict{fastEncoderDict: fastEncoderDict{fastEncoder: fastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), bufferReset: math.MaxInt32 - int32(o.windowSize*2), lowMem: o.lowMem}}}}
 | 
			
		||||
		}
 | 
			
		||||
		return &doubleFastEncoder{fastEncoder: fastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), lowMem: o.lowMem}}}
 | 
			
		||||
		return &doubleFastEncoder{fastEncoder: fastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), bufferReset: math.MaxInt32 - int32(o.windowSize*2), lowMem: o.lowMem}}}
 | 
			
		||||
	case SpeedBetterCompression:
 | 
			
		||||
		if o.dict != nil {
 | 
			
		||||
			return &betterFastEncoderDict{betterFastEncoder: betterFastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), lowMem: o.lowMem}}}
 | 
			
		||||
			return &betterFastEncoderDict{betterFastEncoder: betterFastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), bufferReset: math.MaxInt32 - int32(o.windowSize*2), lowMem: o.lowMem}}}
 | 
			
		||||
		}
 | 
			
		||||
		return &betterFastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), lowMem: o.lowMem}}
 | 
			
		||||
		return &betterFastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), bufferReset: math.MaxInt32 - int32(o.windowSize*2), lowMem: o.lowMem}}
 | 
			
		||||
	case SpeedBestCompression:
 | 
			
		||||
		return &bestFastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), lowMem: o.lowMem}}
 | 
			
		||||
		return &bestFastEncoder{fastBase: fastBase{maxMatchOff: int32(o.windowSize), bufferReset: math.MaxInt32 - int32(o.windowSize*2), lowMem: o.lowMem}}
 | 
			
		||||
	}
 | 
			
		||||
	panic("unknown compression level")
 | 
			
		||||
}
 | 
			
		||||
@@ -304,7 +306,13 @@ func WithLowerEncoderMem(b bool) EOption {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// WithEncoderDict allows to register a dictionary that will be used for the encode.
 | 
			
		||||
//
 | 
			
		||||
// The slice dict must be in the [dictionary format] produced by
 | 
			
		||||
// "zstd --train" from the Zstandard reference implementation.
 | 
			
		||||
//
 | 
			
		||||
// The encoder *may* choose to use no dictionary instead for certain payloads.
 | 
			
		||||
//
 | 
			
		||||
// [dictionary format]: https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md#dictionary-format
 | 
			
		||||
func WithEncoderDict(dict []byte) EOption {
 | 
			
		||||
	return func(o *encoderOptions) error {
 | 
			
		||||
		d, err := loadDict(dict)
 | 
			
		||||
@@ -315,3 +323,17 @@ func WithEncoderDict(dict []byte) EOption {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// WithEncoderDictRaw registers a dictionary that may be used by the encoder.
 | 
			
		||||
//
 | 
			
		||||
// The slice content may contain arbitrary data. It will be used as an initial
 | 
			
		||||
// history.
 | 
			
		||||
func WithEncoderDictRaw(id uint32, content []byte) EOption {
 | 
			
		||||
	return func(o *encoderOptions) error {
 | 
			
		||||
		if bits.UintSize > 32 && uint(len(content)) > dictMaxLength {
 | 
			
		||||
			return fmt.Errorf("dictionary of size %d > 2GiB too large", len(content))
 | 
			
		||||
		}
 | 
			
		||||
		o.dict = &dict{id: id, content: content, offsets: [3]int{1, 4, 8}}
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user