import (
"bytes"
"compress/gzip"
"encoding/binary"
"io/IoUtil"
)
func ParseGzip(data []byte) ([]byte,error) { b := new(bytes.Buffer) binary.Write(b,binary.LittleEndian,data) r,err := gzip.NewReader(b) if err != nil { logger.Info("[ParseGzip] NewReader error: %v,maybe data is ungzip",err) return nil,err } else { defer r.Close() undatas,err := IoUtil.ReadAll(r) if err != nil { logger.Warn("[ParseGzip] IoUtil.ReadAll error: %v",err) return nil,err } return undatas,nil } }
原文链接:https://www.f2er.com/go/188920.html