Documentation ¶
Index ¶
Constants ¶
View Source
const DefaultUnzipWorkerNum = 1
DefaultUnzipWorkerNum 如果没有指定的话,默认情况下解压使用的并发数是多少
Variables ¶
View Source
var ( // ErrWorkerNumInvalid 解压zip文件时的并发数必须大于0,否则没法搞了 ErrWorkerNumInvalid = errors.New("options.WorkerNum it has to be greater than 0") // ErrSourceZipFileEmpty 源zip文件不能为空,否则会返回此错误 ErrSourceZipFileEmpty = errors.New("options.SourceZipFile can not empty") // ErrDestinationDirectoryEmpty 解压到的目录不能为空 ErrDestinationDirectoryEmpty = errors.New("options.DestinationDirectory can not empty") )
Functions ¶
func BuildZipSlipError ¶
BuildZipSlipError 当检查到zip slip文件时,为其构造错误信息
Types ¶
type File ¶
File 用于表示一个zip压缩文件,在原生的zip file上封装了一些基础操作
type FileHandler ¶
FileHandler 用来处理解压出来的文件
type Options ¶
type Options struct { // 源压缩文件,必须是zip格式 SourceZipFile string // 解压到的目标文件夹,必须是一个目录,如果不存在的话会自动创建,如果已经存在的话尽量为空,否则可能会被重复覆盖写文件 DestinationDirectory string // 解压的时候使用的并发数,如果不指定的话默认为 DefaultUnzipWorkerNum WorkerNum *int }
Options 解压压缩文件时可以指定的各种选项
func NewOptions ¶
func NewOptions() *Options
func (*Options) SetDestinationDirectory ¶
SetDestinationDirectory 设置解压后输出的文件夹的路径
func (*Options) SetSourceZipFile ¶
SetSourceZipFile 设置要解压的zip文件的路径
func (*Options) SetWorkerNum ¶
SetWorkerNum 设置解压时使用到的并发数
type Unzip ¶
type Unzip struct {
// contains filtered or unexported fields
}
Unzip 用于封装解压缩的逻辑
func (*Unzip) SafeTraversal ¶
func (x *Unzip) SafeTraversal(handler FileHandler) (err error)
SafeTraversal 安全的遍历压缩文件,遇到非法的或者错误的压缩文件时会自动检测报错
func (*Unzip) Traversal ¶
func (x *Unzip) Traversal(handler FileHandler) (err error)
Traversal 遍历zip文件
Click to show internal directories.
Click to hide internal directories.