github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/x/wasm/client/utils/utils.go (about) 1 package utils 2 3 import ( 4 "bytes" 5 "compress/gzip" 6 ) 7 8 var ( 9 gzipIdent = []byte("\x1F\x8B\x08") 10 wasmIdent = []byte("\x00\x61\x73\x6D") 11 ) 12 13 // IsGzip returns checks if the file contents are gzip compressed 14 func IsGzip(input []byte) bool { 15 return bytes.Equal(input[:3], gzipIdent) 16 } 17 18 // IsWasm checks if the file contents are of wasm binary 19 func IsWasm(input []byte) bool { 20 return bytes.Equal(input[:4], wasmIdent) 21 } 22 23 // GzipIt compresses the input ([]byte) 24 func GzipIt(input []byte) ([]byte, error) { 25 // Create gzip writer. 26 var b bytes.Buffer 27 w := gzip.NewWriter(&b) 28 _, err := w.Write(input) 29 if err != nil { 30 return nil, err 31 } 32 err = w.Close() // You must close this first to flush the bytes to the buffer. 33 if err != nil { 34 return nil, err 35 } 36 37 return b.Bytes(), nil 38 }