go语言通过zlib压缩数据的方法

2019-11-10 09:44:03王旭

    var buf bytes.Buffer
    compressor, err := zlib.NewWriterLevelDict(&buf, zlib.BestCompression, input)
    if err != nil {
        fmt.Println("压缩失败")
        return
    }
    compressor.Write(input)
    compressor.Close()
    fmt.Println(buf.Bytes())
    fmt.Println(len(buf.Bytes()))
    fmt.Println(len(input))
}

希望本文所述对大家的Go语言程序设计有所帮助。