You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
835 B
61 lines
835 B
package gzip
|
|
|
|
import (
|
|
"bytes"
|
|
"compress/gzip"
|
|
"io"
|
|
)
|
|
|
|
// GUnzipData 解压数据
|
|
//
|
|
// @Description:
|
|
// @param data
|
|
// @return resData
|
|
// @return err
|
|
func GUnzipData(data []byte) (resData []byte, err error) {
|
|
b := bytes.NewBuffer(data)
|
|
|
|
var r io.Reader
|
|
r, err = gzip.NewReader(b)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
var resB bytes.Buffer
|
|
_, err = resB.ReadFrom(r)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
resData = resB.Bytes()
|
|
|
|
return
|
|
}
|
|
|
|
// GZipData 压缩数据
|
|
//
|
|
// @Description:
|
|
// @param data
|
|
// @return compressedData
|
|
// @return err
|
|
func GZipData(data []byte) (compressedData []byte, err error) {
|
|
var b bytes.Buffer
|
|
gz := gzip.NewWriter(&b)
|
|
|
|
_, err = gz.Write(data)
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if err = gz.Flush(); err != nil {
|
|
return
|
|
}
|
|
|
|
if err = gz.Close(); err != nil {
|
|
return
|
|
}
|
|
|
|
compressedData = b.Bytes()
|
|
|
|
return
|
|
}
|
|
|