zipx

package
v0.15.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2026 License: Apache-2.0 Imports: 7 Imported by: 1

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

View Source
const (
	// GzipPrefix 是用于标识 gzip 压缩数据的前缀
	GzipPrefix = "GZIP:"
	// GzipPrefixLen 是 gzip 前缀的长度
	GzipPrefixLen = len(GzipPrefix)
)
View Source
const (
	// ZlibPrefix 是用于标识 zlib 压缩数据的前缀
	ZlibPrefix = "ZLIB:"
	// ZlibPrefixLen 是 zlib 前缀的长度
	ZlibPrefixLen = len(ZlibPrefix)
)

Variables

This section is empty.

Functions

func GzipCompress

func GzipCompress(data []byte) ([]byte, error)

GzipCompress 使用 gzip 压缩数据

func GzipCompressObject added in v0.11.84

func GzipCompressObject[T any](obj T) ([]byte, error)

GzipCompressObject 泛型压缩函数,支持任意类型自动JSON序列化

func GzipCompressObjectWithSize added in v0.11.84

func GzipCompressObjectWithSize[T any](obj T) ([]byte, int, error)

GzipCompressObjectWithSize 泛型压缩函数,返回压缩后的数据和原始JSON数据大小

func GzipCompressWithPrefix added in v0.11.87

func GzipCompressWithPrefix(data []byte) ([]byte, error)

GzipCompressWithPrefix 压缩数据并添加 GZIP: 前缀 返回带前缀的压缩数据,适用于需要明确标识压缩格式的场景

func GzipDecompress

func GzipDecompress(compressedData []byte) ([]byte, error)

GzipDecompress 解压缩 gzip 压缩的数据

func GzipDecompressObject added in v0.11.84

func GzipDecompressObject[T any](compressedData []byte) (T, error)

GzipDecompressObject 泛型解压缩函数,支持自动JSON反序列化

func GzipSmartDecompress added in v0.11.87

func GzipSmartDecompress(data []byte) ([]byte, error)

GzipSmartDecompress 智能解压缩函数 自动检测数据是否被压缩,如果是则解压,否则直接返回原数据 适用于需要兼容压缩/未压缩数据的场景

func GzipSmartDecompressObject added in v0.11.87

func GzipSmartDecompressObject[T any](data []byte) (T, error)

GzipSmartDecompressObject 智能解压缩对象函数 自动检测数据是否被压缩,支持自动JSON反序列化 适用于需要兼容压缩/未压缩数据的场景

func IsGzipCompressed added in v0.11.87

func IsGzipCompressed(data []byte) bool

IsGzipCompressed 检查数据是否带有 GZIP 压缩前缀

func IsZlibCompressed added in v0.11.87

func IsZlibCompressed(data []byte) bool

IsZlibCompressed 检查数据是否带有 ZLIB 压缩前缀

func MultiGZipCompress added in v0.11.5

func MultiGZipCompress(data []byte, times int) ([]byte, error)

MultiGZipCompress 支持多次压缩

func MultiGZipCompressObject added in v0.11.84

func MultiGZipCompressObject[T any](obj T, times int) ([]byte, error)

MultiGZipCompressObject 泛型多次压缩函数,支持任意类型自动JSON序列化

func MultiGZipDecompress added in v0.11.5

func MultiGZipDecompress(compressedData []byte, times int) ([]byte, error)

MultiGZipDecompress 支持多次解压缩

func MultiGZipDecompressObject added in v0.11.84

func MultiGZipDecompressObject[T any](compressedData []byte, times int) (T, error)

MultiGZipDecompressObject 泛型多次解压缩函数,支持自动JSON反序列化

func MultiZlibCompress added in v0.11.5

func MultiZlibCompress(data []byte, times int) ([]byte, error)

MultiZlibCompress 支持多次压缩

func MultiZlibCompressObject added in v0.11.84

func MultiZlibCompressObject[T any](obj T, times int) ([]byte, error)

MultiZlibCompressObject 泛型多次压缩函数,支持任意类型自动JSON序列化

func MultiZlibDecompress added in v0.11.5

func MultiZlibDecompress(compressedData []byte, times int) ([]byte, error)

MultiZlibDecompress 支持多次解压缩

func MultiZlibDecompressObject added in v0.11.84

func MultiZlibDecompressObject[T any](compressedData []byte, times int) (T, error)

MultiZlibDecompressObject 泛型多次解压缩函数,支持自动JSON反序列化

func ZlibCompress

func ZlibCompress(data []byte) ([]byte, error)

ZlibCompress 压缩数据(修复版本)

func ZlibCompressObject added in v0.11.84

func ZlibCompressObject[T any](obj T) ([]byte, error)

ZlibCompressObject 泛型压缩函数,支持任意类型自动JSON序列化

func ZlibCompressObjectWithSize added in v0.11.84

func ZlibCompressObjectWithSize[T any](obj T) ([]byte, int, error)

ZlibCompressObjectWithSize 泛型压缩函数,返回压缩后的数据和原始JSON数据大小

func ZlibCompressWithPrefix added in v0.11.87

func ZlibCompressWithPrefix(data []byte) ([]byte, error)

ZlibCompressWithPrefix 压缩数据并添加 ZLIB: 前缀 返回带前缀的压缩数据,适用于需要明确标识压缩格式的场景

func ZlibDecompress

func ZlibDecompress(compressedData []byte) ([]byte, error)

ZlibDecompress 解压缩数据(优化版本,使用对象池)

func ZlibDecompressObject added in v0.11.84

func ZlibDecompressObject[T any](compressedData []byte) (T, error)

ZlibDecompressObject 泛型解压缩函数,支持自动JSON反序列化

func ZlibSmartDecompress added in v0.11.87

func ZlibSmartDecompress(data []byte) ([]byte, error)

ZlibSmartDecompress 智能解压缩函数 自动检测数据是否被压缩,如果是则解压,否则直接返回原数据 适用于需要兼容压缩/未压缩数据的场景

func ZlibSmartDecompressObject added in v0.11.87

func ZlibSmartDecompressObject[T any](data []byte) (T, error)

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 返回压缩结果的字符串表示

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL