-
Notifications
You must be signed in to change notification settings - Fork 3
/
gzip.go
45 lines (36 loc) · 1.01 KB
/
gzip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package gzipKit
import (
"github.com/gogf/gf/v2/encoding/gcompress"
"io"
)
//import "github.com/zeromicro/go-zero/core/codec"
//
//var (
// // Compress 压缩.
// Compress func(bs []byte) []byte = codec.Gzip
//
// // Decompress 解压缩.
// /*
// PS: 大小限制: 100MB.
// */
// Decompress func(bs []byte) ([]byte, error) = codec.Gunzip
//)
// Compress
/*
PS: 前端的解压,可以参考 notes/_Vue3Projects/ws-client 中的 GzipKit.
*/
func Compress(data []byte, options ...GzipOption) ([]byte, error) {
opts := loadOptions(options...)
return opts.Compress(data)
}
var (
//Compress func(data []byte, level ...int) ([]byte, error) = gcompress.Gzip
Decompress func(data []byte) ([]byte, error) = gcompress.UnGzip
)
var (
GzipFile func(srcFilePath, dstFilePath string, level ...int) (err error) = gcompress.GzipFile
GzipPathWriter func(filePath string, writer io.Writer, level ...int) error = gcompress.GzipPathWriter
)
var (
UnGzipFile func(srcFilePath, dstFilePath string) error = gcompress.UnGzipFile
)