github.com/GeniusesGroup/libgo@v0.0.0-20220929090155-5ff932cb408e/minify/css.go (about) 1 /* For license and copyright information please see LEGAL file in repository */ 2 3 package minify 4 5 import ( 6 "../protocol" 7 8 tcss "github.com/tdewolff/minify/css" 9 "github.com/tdewolff/parse/buffer" 10 ) 11 12 var CSS css 13 14 type css struct { 15 tcss.Minifier 16 } 17 18 // Minify replace file data with minify of them. 19 func (css *css) Minify(data protocol.Codec) (err protocol.Error) { 20 var rawData = data.Marshal() 21 var minifiedData []byte 22 minifiedData, err = css.MinifyBytes(rawData) 23 if err != nil { 24 return 25 } 26 err = data.Unmarshal(minifiedData) 27 return 28 } 29 30 // MinifyBytes replace file data with minify of them. 31 func (css *css) MinifyBytes(data []byte) (minifiedData []byte, err protocol.Error) { 32 var minifiedWriter = buffer.NewWriter(make([]byte, 0, len(data))) 33 var goErr = css.Minifier.Minify(minifier, minifiedWriter, buffer.NewReader(data), nil) 34 if goErr != nil { 35 // err = 36 return 37 } 38 minifiedData = minifiedWriter.Bytes() 39 return 40 }