github.com/geniusesgroup/libgo@v0.0.0-20220713101832-828057a9d3d4/compress/gzip/gzip.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package gzip 4 5 import ( 6 compress ".." 7 "../../mediatype" 8 "../../protocol" 9 ) 10 11 const ( 12 GZIPContentEncoding = "gzip" 13 GZIPExtension = "gzip" 14 ) 15 16 var GZIP = gzip{ 17 CompressType: compress.New(GZIPContentEncoding, mediatype.New("domain/gzip.protocol.data-structure").SetFileExtension(GZIPExtension)), 18 } 19 20 type gzip struct { 21 *compress.CompressType 22 } 23 24 func (g *gzip) Compress(raw protocol.Codec, options protocol.CompressOptions) (compressed protocol.Codec, err protocol.Error) { 25 compressed = &Compressor{ 26 source: raw, 27 options: options, 28 } 29 return 30 } 31 func (g *gzip) CompressBySlice(raw []byte, options protocol.CompressOptions) (compressed protocol.Codec, err protocol.Error) { 32 // TODO::: 33 return 34 } 35 func (g *gzip) CompressByReader(raw protocol.Reader, options protocol.CompressOptions) (compressed protocol.Codec, err protocol.Error) { 36 // TODO::: 37 return 38 } 39 40 func (g *gzip) Decompress(compressed protocol.Codec) (raw protocol.Codec, err protocol.Error) { 41 var gzipDecoder Decompressor 42 gzipDecoder.initByCodec(compressed) 43 raw = &gzipDecoder 44 return 45 } 46 func (g *gzip) DecompressFromSlice(compressed []byte) (raw protocol.Codec, err protocol.Error) { 47 var gzipDecoder Decompressor 48 err = gzipDecoder.Unmarshal(compressed) 49 raw = &gzipDecoder 50 return 51 } 52 func (g *gzip) DecompressFromReader(compressed protocol.Reader, compressedLen int) (raw protocol.Codec, err protocol.Error) { 53 var gzipDecoder Decompressor 54 gzipDecoder.comLen = compressedLen 55 err = gzipDecoder.Decode(compressed) 56 raw = &gzipDecoder 57 return 58 }