golang gzip压缩数据,并直接返回二进制内容

不废话,直接上代码

import (
    "bytes"
    "compress/gzip"
)

func main(){
    data := []byte(hello world)
    gzipCompress(&data)
}

func gzipCompress(content *[]byte) []byte {
    var compressData bytes.Buffer
    gzipWriter := gzip.NewWriter(&compressData)
    defer gzipWriter.Close()
    gzipWriter.Write(*content)
    gzipWriter.Flush()
    return compressData.Bytes()
}

猜你喜欢

转载自www.cnblogs.com/alpiny/p/12936686.html
今日推荐