compress

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPathTraversal zip 条目名逃逸目标目录(C5a Zip-Slip)。
	ErrPathTraversal = errors.New("zip entry escapes destination directory")
	// ErrSymlinkEntry zip 条目为符号链接,已拒绝(防经软链二次穿越)。
	ErrSymlinkEntry = errors.New("zip entry is a symlink, rejected")
	// ErrDecompressLimit 解压大小超过上限(C5b 解压炸弹)。
	ErrDecompressLimit = errors.New("decompress size limit exceeded")
)

解压安全相关错误。

Functions

func GzipCompress

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

GzipCompress 压缩数据

func GzipCompressFile

func GzipCompressFile(src, dst string) error

GzipCompressFile 压缩文件

func GzipDecompress

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

GzipDecompress 解压缩数据。默认上限 100MB 防解压炸弹 OOM(C5b); 需解压更大文件请用 GzipDecompressWithOptions。

func GzipDecompressFile

func GzipDecompressFile(src, dst string) error

GzipDecompressFile 解压文件。默认上限 100MB 防磁盘耗尽(C5b); 需解压更大文件请用 GzipDecompressFileWithOptions。

func GzipDecompressFileWithOptions added in v1.2.0

func GzipDecompressFileWithOptions(src, dst string, opts DecompressOptions) (err error)

GzipDecompressFileWithOptions 解压文件,可配置大小上限(C5b)。

func GzipDecompressWithOptions added in v1.2.0

func GzipDecompressWithOptions(data []byte, opts DecompressOptions) ([]byte, error)

GzipDecompressWithOptions 解压缩数据,可配置大小上限(C5b)。

func Unzip

func Unzip(zipPath, dstDir string) error

Unzip 解压 zip 文件。默认启用 Zip-Slip 防护(前缀锚定 + 拒绝符号链接), 单条目上限 100MB、累计上限 1GB 防解压炸弹(C5b);需自定义上限请用 UnzipWithOptions。

func UnzipWithOptions added in v1.2.0

func UnzipWithOptions(zipPath, dstDir string, opts DecompressOptions) error

UnzipWithOptions 解压 zip 文件,可配置大小上限(C5b)。Zip-Slip 防护始终启用。

func Zip

func Zip(zipPath string, paths []string) error

Zip 压缩文件或目录 参数: zipPath 目标zip文件路径,paths 要压缩的文件或目录列表

Types

type DecompressOptions added in v1.2.0

type DecompressOptions struct {
	// MaxBytes 单流 / 单条目解压大小上限(字节)。0 = 默认 100MB,-1 = 不限制。
	MaxBytes int64
	// MaxTotalBytes Unzip 累计解压大小上限(字节)。0 = 默认 1GB,-1 = 不限制。
	// 仅 Unzip 生效。
	MaxTotalBytes int64
}

DecompressOptions 解压安全选项。Zip-Slip 防护(前缀锚定 + 拒绝符号链接)始终启用,无需配置; 本选项仅控制解压大小上限以防解压炸弹(C5b)。

Jump to

Keyboard shortcuts

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