goProject/trunk/goutil/lz4Util/lz4.go
皮蛋13361098506 1b77f62820 初始化项目
2025-01-06 16:01:02 +08:00

36 lines
650 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package lz4Util
import (
"fmt"
"github.com/bkaradzic/go-lz4"
)
// 压缩
// data待压缩数据
// 返回值:
// 压缩后数据
// 对应的错误
func Compress(data []byte)([]byte, error) {
compressed, err := lz4.Encode(nil, data)
if err != nil {
fmt.Println("Failed to encode:", err)
return nil,err
}
return compressed,nil
}
// 解压缩
// data:待解压缩数据
// 返回值:
// 解压缩后数据
// 对应的错误
func Decompress(data []byte) ([]byte, error){
decompressed, err := lz4.Decode(nil, data)
if err != nil {
fmt.Println("Failed to decode:", err)
return nil,err
}
return decompressed,nil
}