diff --git a/filemdl/filezip.go b/filemdl/filezip.go index 7a677ed7b0e08ba1160aa031e3fae1ecbb8df0f6..ca89c8b6cabd0b8580db5089339a46dc840ebdfe 100644 --- a/filemdl/filezip.go +++ b/filemdl/filezip.go @@ -11,9 +11,14 @@ import ( "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/errormdl" "corelab.mkcl.org/MKCLOS/coredevelopmentplatform/corepkgv2/loggermdl" - "github.com/DataDog/zstd" + + // "github.com/DataDog/zstd" + "github.com/klauspost/compress/zstd" ) +var encoder, _ = zstd.NewWriter(nil) +var decoder, _ = zstd.NewReader(nil) + //Zip - Zip func Zip(source, target string) error { source = filepath.Clean(source) @@ -297,10 +302,11 @@ func Unzip(archive, target string) error { return nil } -//zip byte array +//ZipBytes - zip byte array func ZipBytes(inputData []byte) ([]byte, error) { - compressedData, err := zstd.CompressLevel(nil, inputData, 9) - return compressedData, err + // compressedData, err := zstd.CompressLevel(nil, inputData, 9) + compressedData := encoder.EncodeAll(inputData, make([]byte, 0, len(inputData))) + return compressedData, nil } // ZipSingleFile - Zip single file @@ -320,9 +326,10 @@ func ZipSingleFile(sourceFilePath, destFilePath string) error { return nil } -//unzip bytes - Decompress +//UnZipBytes bytes - Decompress func UnZipBytes(compressedData []byte) ([]byte, error) { - decompressedData, err := zstd.Decompress(nil, compressedData) + // decompressedData, err := zstd.Decompress(nil, compressedData) + decompressedData, err := decoder.DecodeAll(compressedData, nil) return decompressedData, errormdl.CheckErr(err) }