Documentation
¶
Overview ¶
* @Author: kamalyes 501893067@qq.com * @Date: 2024-10-24 11:25:16 * @LastEditors: kamalyes 501893067@qq.com * @LastEditTime: 2025-12-04 18:26:12 * @FilePath: \go-toolbox\pkg\zipx\zlib.go * @Description: * * Copyright (c) 2024 by kamalyes, All Rights Reserved.
Index ¶
- Constants
- func GzipCompress(data []byte) ([]byte, error)
- func GzipCompressObject[T any](obj T) ([]byte, error)
- func GzipCompressObjectWithSize[T any](obj T) ([]byte, int, error)
- func GzipCompressWithPrefix(data []byte) ([]byte, error)
- func GzipDecompress(compressedData []byte) ([]byte, error)
- func GzipDecompressObject[T any](compressedData []byte) (T, error)
- func GzipSmartDecompress(data []byte) ([]byte, error)
- func GzipSmartDecompressObject[T any](data []byte) (T, error)
- func IsGzipCompressed(data []byte) bool
- func IsZlibCompressed(data []byte) bool
- func MultiGZipCompress(data []byte, times int) ([]byte, error)
- func MultiGZipCompressObject[T any](obj T, times int) ([]byte, error)
- func MultiGZipDecompress(compressedData []byte, times int) ([]byte, error)
- func MultiGZipDecompressObject[T any](compressedData []byte, times int) (T, error)
- func MultiZlibCompress(data []byte, times int) ([]byte, error)
- func MultiZlibCompressObject[T any](obj T, times int) ([]byte, error)
- func MultiZlibDecompress(compressedData []byte, times int) ([]byte, error)
- func MultiZlibDecompressObject[T any](compressedData []byte, times int) (T, error)
- func ZlibCompress(data []byte) ([]byte, error)
- func ZlibCompressObject[T any](obj T) ([]byte, error)
- func ZlibCompressObjectWithSize[T any](obj T) ([]byte, int, error)
- func ZlibCompressWithPrefix(data []byte) ([]byte, error)
- func ZlibDecompress(compressedData []byte) ([]byte, error)
- func ZlibDecompressObject[T any](compressedData []byte) (T, error)
- func ZlibSmartDecompress(data []byte) ([]byte, error)
- func ZlibSmartDecompressObject[T any](data []byte) (T, error)
- type CompressResult
- func GzipCompressObjectWithInfo[T any](obj T) (*CompressResult, error)
- func GzipCompressWithInfo(data []byte) (*CompressResult, error)
- func GzipCompressWithPrefixInfo(data []byte) (*CompressResult, error)
- func MultiGZipCompressObjectWithInfo[T any](obj T, times int) (*CompressResult, error)
- func MultiGZipCompressWithInfo(data []byte, times int) (*CompressResult, error)
- func MultiZlibCompressObjectWithInfo[T any](obj T, times int) (*CompressResult, error)
- func MultiZlibCompressWithInfo(data []byte, times int) (*CompressResult, error)
- func ZlibCompressObjectWithInfo[T any](obj T) (*CompressResult, error)
- func ZlibCompressWithInfo(data []byte) (*CompressResult, error)
- func ZlibCompressWithPrefixInfo(data []byte) (*CompressResult, error)
Constants ¶
const ( // GzipPrefix 是用于标识 gzip 压缩数据的前缀 GzipPrefix = "GZIP:" // GzipPrefixLen 是 gzip 前缀的长度 GzipPrefixLen = len(GzipPrefix) )
const ( // ZlibPrefix 是用于标识 zlib 压缩数据的前缀 ZlibPrefix = "ZLIB:" // ZlibPrefixLen 是 zlib 前缀的长度 ZlibPrefixLen = len(ZlibPrefix) )
Variables ¶
This section is empty.
Functions ¶
func GzipCompressObject ¶ added in v0.11.84
GzipCompressObject 泛型压缩函数,支持任意类型自动JSON序列化
func GzipCompressObjectWithSize ¶ added in v0.11.84
GzipCompressObjectWithSize 泛型压缩函数,返回压缩后的数据和原始JSON数据大小
func GzipCompressWithPrefix ¶ added in v0.11.87
GzipCompressWithPrefix 压缩数据并添加 GZIP: 前缀 返回带前缀的压缩数据,适用于需要明确标识压缩格式的场景
func GzipDecompress ¶
GzipDecompress 解压缩 gzip 压缩的数据
func GzipDecompressObject ¶ added in v0.11.84
GzipDecompressObject 泛型解压缩函数,支持自动JSON反序列化
func GzipSmartDecompress ¶ added in v0.11.87
GzipSmartDecompress 智能解压缩函数 自动检测数据是否被压缩,如果是则解压,否则直接返回原数据 适用于需要兼容压缩/未压缩数据的场景
func GzipSmartDecompressObject ¶ added in v0.11.87
GzipSmartDecompressObject 智能解压缩对象函数 自动检测数据是否被压缩,支持自动JSON反序列化 适用于需要兼容压缩/未压缩数据的场景
func IsGzipCompressed ¶ added in v0.11.87
IsGzipCompressed 检查数据是否带有 GZIP 压缩前缀
func IsZlibCompressed ¶ added in v0.11.87
IsZlibCompressed 检查数据是否带有 ZLIB 压缩前缀
func MultiGZipCompress ¶ added in v0.11.5
MultiGZipCompress 支持多次压缩
func MultiGZipCompressObject ¶ added in v0.11.84
MultiGZipCompressObject 泛型多次压缩函数,支持任意类型自动JSON序列化
func MultiGZipDecompress ¶ added in v0.11.5
MultiGZipDecompress 支持多次解压缩
func MultiGZipDecompressObject ¶ added in v0.11.84
MultiGZipDecompressObject 泛型多次解压缩函数,支持自动JSON反序列化
func MultiZlibCompress ¶ added in v0.11.5
MultiZlibCompress 支持多次压缩
func MultiZlibCompressObject ¶ added in v0.11.84
MultiZlibCompressObject 泛型多次压缩函数,支持任意类型自动JSON序列化
func MultiZlibDecompress ¶ added in v0.11.5
MultiZlibDecompress 支持多次解压缩
func MultiZlibDecompressObject ¶ added in v0.11.84
MultiZlibDecompressObject 泛型多次解压缩函数,支持自动JSON反序列化
func ZlibCompressObject ¶ added in v0.11.84
ZlibCompressObject 泛型压缩函数,支持任意类型自动JSON序列化
func ZlibCompressObjectWithSize ¶ added in v0.11.84
ZlibCompressObjectWithSize 泛型压缩函数,返回压缩后的数据和原始JSON数据大小
func ZlibCompressWithPrefix ¶ added in v0.11.87
ZlibCompressWithPrefix 压缩数据并添加 ZLIB: 前缀 返回带前缀的压缩数据,适用于需要明确标识压缩格式的场景
func ZlibDecompress ¶
ZlibDecompress 解压缩数据(优化版本,使用对象池)
func ZlibDecompressObject ¶ added in v0.11.84
ZlibDecompressObject 泛型解压缩函数,支持自动JSON反序列化
func ZlibSmartDecompress ¶ added in v0.11.87
ZlibSmartDecompress 智能解压缩函数 自动检测数据是否被压缩,如果是则解压,否则直接返回原数据 适用于需要兼容压缩/未压缩数据的场景
func ZlibSmartDecompressObject ¶ added in v0.11.87
ZlibSmartDecompressObject 智能解压缩对象函数 自动检测数据是否被压缩,支持自动JSON反序列化 适用于需要兼容压缩/未压缩数据的场景
Types ¶
type CompressResult ¶ added in v0.11.87
type CompressResult struct {
Data []byte // 压缩后的数据
OriginalSize int // 原始数据大小(字节)
CompressedSize int // 压缩后数据大小(字节)
Ratio float64 // 压缩率(压缩后/压缩前,越小压缩效果越好)
}
CompressResult 压缩结果,包含压缩数据和统计信息
func GzipCompressObjectWithInfo ¶ added in v0.11.87
func GzipCompressObjectWithInfo[T any](obj T) (*CompressResult, error)
GzipCompressObjectWithInfo 泛型压缩函数,支持任意类型自动JSON序列化并返回压缩信息
func GzipCompressWithInfo ¶ added in v0.11.87
func GzipCompressWithInfo(data []byte) (*CompressResult, error)
GzipCompressWithInfo 使用 gzip 压缩数据并返回压缩信息
func GzipCompressWithPrefixInfo ¶ added in v0.11.87
func GzipCompressWithPrefixInfo(data []byte) (*CompressResult, error)
GzipCompressWithPrefixInfo 压缩数据并添加 GZIP: 前缀,同时返回压缩信息
func MultiGZipCompressObjectWithInfo ¶ added in v0.11.87
func MultiGZipCompressObjectWithInfo[T any](obj T, times int) (*CompressResult, error)
MultiGZipCompressObjectWithInfo 泛型多次压缩函数,支持任意类型自动JSON序列化并返回压缩信息
func MultiGZipCompressWithInfo ¶ added in v0.11.87
func MultiGZipCompressWithInfo(data []byte, times int) (*CompressResult, error)
MultiGZipCompressWithInfo 支持多次压缩并返回压缩信息
func MultiZlibCompressObjectWithInfo ¶ added in v0.11.87
func MultiZlibCompressObjectWithInfo[T any](obj T, times int) (*CompressResult, error)
MultiZlibCompressObjectWithInfo 泛型多次压缩函数,支持任意类型自动JSON序列化并返回压缩信息
func MultiZlibCompressWithInfo ¶ added in v0.11.87
func MultiZlibCompressWithInfo(data []byte, times int) (*CompressResult, error)
MultiZlibCompressWithInfo 支持多次压缩并返回压缩信息
func ZlibCompressObjectWithInfo ¶ added in v0.11.87
func ZlibCompressObjectWithInfo[T any](obj T) (*CompressResult, error)
ZlibCompressObjectWithInfo 泛型压缩函数,支持任意类型自动JSON序列化并返回压缩信息
func ZlibCompressWithInfo ¶ added in v0.11.87
func ZlibCompressWithInfo(data []byte) (*CompressResult, error)
ZlibCompressWithInfo 压缩数据并返回压缩信息
func ZlibCompressWithPrefixInfo ¶ added in v0.11.87
func ZlibCompressWithPrefixInfo(data []byte) (*CompressResult, error)
ZlibCompressWithPrefixInfo 压缩数据并添加 ZLIB: 前缀,同时返回压缩信息
func (*CompressResult) SavedBytes ¶ added in v0.11.87
func (r *CompressResult) SavedBytes() int
SavedBytes 返回节省的字节数
func (*CompressResult) SavedPercent ¶ added in v0.11.87
func (r *CompressResult) SavedPercent() float64
SavedPercent 返回节省的百分比
func (*CompressResult) String ¶ added in v0.11.87
func (r *CompressResult) String() string
String 返回压缩结果的字符串表示