/*
 * SPDX-FileCopyrightText: © 2017-2025 Istari Digital, Inc.
 * SPDX-License-Identifier: Apache-2.0
 */

package y

import (
	

	
)

var (
	decoder *zstd.Decoder
	encoder *zstd.Encoder

	encOnce, decOnce sync.Once
)

// ZSTDDecompress decompresses a block using ZSTD algorithm.
func (,  []byte) ([]byte, error) {
	decOnce.Do(func() {
		var  error
		decoder,  = zstd.NewReader(nil)
		Check()
	})
	return decoder.DecodeAll(, [:0])
}

// ZSTDCompress compresses a block using ZSTD algorithm.
func (,  []byte,  int) ([]byte, error) {
	encOnce.Do(func() {
		var  error
		 := zstd.EncoderLevelFromZstd()
		encoder,  = zstd.NewWriter(nil, zstd.WithEncoderLevel())
		Check()
	})
	return encoder.EncodeAll(, [:0]), nil
}

// ZSTDCompressBound returns the worst case size needed for a destination buffer.
// Klauspost ZSTD library does not provide any API for Compression Bound. This
// calculation is based on the DataDog ZSTD library.
// See https://pkg.go.dev/github.com/DataDog/zstd#CompressBound
func ( int) int {
	 := 128 << 10 // 128 kB
	var  int
	if  <  {
		 = ( - ) >> 11
	}
	return  + ( >> 8) + 
}