github.com/sandwich-go/boost@v1.3.29/xcompress/compressor.go (about) 1 package xcompress 2 3 import "compress/flate" 4 5 var ( 6 NoCompression = flate.NoCompression 7 BestSpeed = flate.BestSpeed 8 BestCompression = flate.BestCompression 9 DefaultCompression = flate.DefaultCompression 10 HuffmanOnly = flate.HuffmanOnly 11 ) 12 13 // Compressor 压缩器 14 type Compressor interface { 15 // Flat 压缩二进制数据 16 Flat([]byte) ([]byte, error) 17 // Inflate 解压二进制数据 18 Inflate([]byte) ([]byte, error) 19 } 20 21 // Default 默认的压缩器,使用 GZIP 方式,进行 DefaultCompression 等级的压缩与解压缩 22 var Default = MustNew(WithType(GZIP), WithLevel(DefaultCompression)) 23 24 // Flat 默认的压缩器压缩二进制数据 25 func Flat(data []byte) ([]byte, error) { return Default.Flat(data) } 26 27 // Inflate 默认的解压二进制数据 28 func Inflate(data []byte) ([]byte, error) { return Default.Inflate(data) }