[archiver] Always enable Brotli compression.

This commit is contained in:
Ciprian Dorin Craciun 2021-11-17 21:04:45 +02:00
parent c6d610eaba
commit 5fff2eac47
3 changed files with 23 additions and 50 deletions

View file

@ -1,33 +0,0 @@
// +build !nobrotli
package archiver
import "bytes"
import brotli "github.com/itchio/go-brotli/enc"
func CompressBrotli (_data []byte) ([]byte, string, error) {
_buffer := & bytes.Buffer {}
_options := brotli.BrotliWriterOptions { Quality : 11, LGWin : 24}
_encoder := brotli.NewBrotliWriter (_buffer, &_options)
if _, _error := _encoder.Write (_data); _error != nil {
return nil, "", _error
}
if _error := _encoder.Close (); _error != nil {
return nil, "", _error
}
_data = _buffer.Bytes ()
return _data, "br", nil
}

View file

@ -1,17 +0,0 @@
// +build nobrotli
package archiver
import "fmt"
func CompressBrotli (_data []byte) ([]byte, string, error) {
return nil, "", fmt.Errorf ("[9252cf70] unsupported compression algorithm `%s`", "brotli")
}

View file

@ -9,6 +9,7 @@ import "fmt"
import "github.com/foobaz/go-zopfli/zopfli" import "github.com/foobaz/go-zopfli/zopfli"
import brotli "github.com/itchio/go-brotli/enc"
@ -75,3 +76,25 @@ func CompressZopfli (_data []byte) ([]byte, string, error) {
return _data, "gzip", nil return _data, "gzip", nil
} }
func CompressBrotli (_data []byte) ([]byte, string, error) {
_buffer := & bytes.Buffer {}
_options := brotli.BrotliWriterOptions { Quality : 11, LGWin : 24}
_encoder := brotli.NewBrotliWriter (_buffer, &_options)
if _, _error := _encoder.Write (_data); _error != nil {
return nil, "", _error
}
if _error := _encoder.Close (); _error != nil {
return nil, "", _error
}
_data = _buffer.Bytes ()
return _data, "br", nil
}