[#1523] blobstor: Rename compression.CConfig to Config

Signed-off-by: Evgenii Stratonikov <evgeniy@morphbits.ru>
This commit is contained in:
Evgenii Stratonikov 2022-08-19 17:29:53 +03:00 committed by fyrchik
parent 0042c1d4a6
commit e8c6dce466
12 changed files with 34 additions and 34 deletions

View file

@ -228,6 +228,6 @@ func (b *Blobovniczas) Type() string {
}
// SetCompressor implements common.Storage.
func (b *Blobovniczas) SetCompressor(cc *compression.CConfig) {
b.CConfig = cc
func (b *Blobovniczas) SetCompressor(cc *compression.Config) {
b.compression = cc
}

View file

@ -132,7 +132,7 @@ func (b *Blobovniczas) getObject(blz *blobovnicza.Blobovnicza, prm blobovnicza.G
}
// decompress the data
data, err := b.Decompress(res.Object())
data, err := b.compression.Decompress(res.Object())
if err != nil {
return common.GetRes{}, fmt.Errorf("could not decompress object data: %w", err)
}

View file

@ -154,7 +154,7 @@ func (b *Blobovniczas) getObjectRange(blz *blobovnicza.Blobovnicza, prm common.G
}
// decompress the data
data, err := b.Decompress(res.Object())
data, err := b.compression.Decompress(res.Object())
if err != nil {
return common.GetRangeRes{}, fmt.Errorf("could not decompress object data: %w", err)
}

View file

@ -14,7 +14,7 @@ import (
func (b *Blobovniczas) Iterate(prm common.IteratePrm) (common.IterateRes, error) {
return common.IterateRes{}, b.iterateBlobovniczas(prm.IgnoreErrors, func(p string, blz *blobovnicza.Blobovnicza) error {
return blobovnicza.IterateObjects(blz, func(addr oid.Address, data []byte) error {
data, err := b.Decompress(data)
data, err := b.compression.Decompress(data)
if err != nil {
if prm.IgnoreErrors {
if prm.ErrorHandler != nil {

View file

@ -16,7 +16,7 @@ type cfg struct {
openedCacheSize int
blzShallowDepth uint64
blzShallowWidth uint64
*compression.CConfig
compression *compression.Config
blzOpts []blobovnicza.Option
}

View file

@ -14,7 +14,7 @@ import (
// returns error if could not save object in any blobovnicza.
func (b *Blobovniczas) Put(prm common.PutPrm) (common.PutRes, error) {
if !prm.DontCompress {
prm.RawData = b.CConfig.Compress(prm.RawData)
prm.RawData = b.compression.Compress(prm.RawData)
}
var putPrm blobovnicza.PutPrm

View file

@ -32,7 +32,7 @@ type Info = fstree.Info
type Option func(*cfg)
type cfg struct {
compression.CConfig
compression compression.Config
log *logger.Logger
storage []SubStorage
}
@ -51,7 +51,7 @@ func New(opts ...Option) *BlobStor {
}
for i := range bs.storage {
bs.storage[i].Storage.SetCompressor(&bs.CConfig)
bs.storage[i].Storage.SetCompressor(&bs.compression)
}
return bs
@ -86,7 +86,7 @@ func WithLogger(l *logger.Logger) Option {
// is recorded in the provided log.
func WithCompressObjects(comp bool) Option {
return func(c *cfg) {
c.Enabled = comp
c.compression.Enabled = comp
}
}
@ -94,6 +94,6 @@ func WithCompressObjects(comp bool) Option {
// for specific content types as seen by object.AttributeContentType attribute.
func WithUncompressableContentTypes(values []string) Option {
return func(c *cfg) {
c.UncompressableContentTypes = values
c.compression.UncompressableContentTypes = values
}
}

View file

@ -10,7 +10,7 @@ type Storage interface {
Close() error
Type() string
SetCompressor(cc *compression.CConfig)
SetCompressor(cc *compression.Config)
Get(GetPrm) (GetRes, error)
GetRange(GetRangePrm) (GetRangeRes, error)

View file

@ -8,8 +8,8 @@ import (
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
)
// CConfig represents common compression-related configuration.
type CConfig struct {
// Config represents common compression-related configuration.
type Config struct {
Enabled bool
UncompressableContentTypes []string
@ -22,7 +22,7 @@ type CConfig struct {
var zstdFrameMagic = []byte{0x28, 0xb5, 0x2f, 0xfd}
// Init initializes compression routines.
func (c *CConfig) Init() error {
func (c *Config) Init() error {
var err error
if c.Enabled {
@ -44,7 +44,7 @@ func (c *CConfig) Init() error {
// For an object to be compressed 2 conditions must hold:
// 1. Compression is enabled in settings.
// 2. Object MIME Content-Type is allowed for compression.
func (c *CConfig) NeedsCompression(obj *objectSDK.Object) bool {
func (c *Config) NeedsCompression(obj *objectSDK.Object) bool {
if !c.Enabled || len(c.UncompressableContentTypes) == 0 {
return c.Enabled
}
@ -73,7 +73,7 @@ func (c *CConfig) NeedsCompression(obj *objectSDK.Object) bool {
// Decompress decompresses data if it starts with the magic
// and returns data untouched otherwise.
func (c *CConfig) Decompress(data []byte) ([]byte, error) {
func (c *Config) Decompress(data []byte) ([]byte, error) {
if len(data) < 4 || !bytes.Equal(data[:4], zstdFrameMagic) {
return data, nil
}
@ -82,7 +82,7 @@ func (c *CConfig) Decompress(data []byte) ([]byte, error) {
// Compress compresses data if compression is enabled
// and returns data untouched otherwise.
func (c *CConfig) Compress(data []byte) []byte {
func (c *Config) Compress(data []byte) []byte {
if c == nil || !c.Enabled {
return data
}
@ -90,7 +90,7 @@ func (c *CConfig) Compress(data []byte) []byte {
}
// Close closes encoder and decoder, returns any error occured.
func (c *CConfig) Close() error {
func (c *Config) Close() error {
var err error
if c.encoder != nil {
err = c.encoder.Close()

View file

@ -31,7 +31,7 @@ var ErrInitBlobovniczas = errors.New("failure on blobovnicza initialization stag
func (b *BlobStor) Init() error {
b.log.Debug("initializing...")
if err := b.CConfig.Init(); err != nil {
if err := b.compression.Init(); err != nil {
return err
}
@ -60,7 +60,7 @@ func (b *BlobStor) Close() error {
}
}
err := b.CConfig.Close()
err := b.compression.Close()
if firstErr == nil {
firstErr = err
}

View file

@ -22,7 +22,7 @@ import (
type FSTree struct {
Info
*compression.CConfig
*compression.Config
Depth int
DirNameLen int
}
@ -51,7 +51,7 @@ func New(opts ...Option) *FSTree {
Permissions: 0700,
RootPath: "./",
},
CConfig: nil,
Config: nil,
Depth: 4,
DirNameLen: DirNameLen,
}
@ -318,6 +318,6 @@ func (*FSTree) Type() string {
}
// SetCompressor implements common.Storage.
func (t *FSTree) SetCompressor(cc *compression.CConfig) {
t.CConfig = cc
func (t *FSTree) SetCompressor(cc *compression.Config) {
t.Config = cc
}

View file

@ -54,5 +54,5 @@ func (b *BlobStor) Put(prm common.PutPrm) (common.PutRes, error) {
// 1. Compression is enabled in settings.
// 2. Object MIME Content-Type is allowed for compression.
func (b *BlobStor) NeedsCompression(obj *objectSDK.Object) bool {
return b.cfg.CConfig.NeedsCompression(obj)
return b.cfg.compression.NeedsCompression(obj)
}