From 5fff2eac4781ba4664369ec87578e68a3ab30300 Mon Sep 17 00:00:00 2001 From: Ciprian Dorin Craciun Date: Wed, 17 Nov 2021 21:04:45 +0200 Subject: [PATCH] [archiver] Always enable Brotli compression. --- sources/lib/archiver/compress-brotli-with.go | 33 ------------------- .../lib/archiver/compress-brotli-without.go | 17 ---------- sources/lib/archiver/compress.go | 23 +++++++++++++ 3 files changed, 23 insertions(+), 50 deletions(-) delete mode 100644 sources/lib/archiver/compress-brotli-with.go delete mode 100644 sources/lib/archiver/compress-brotli-without.go diff --git a/sources/lib/archiver/compress-brotli-with.go b/sources/lib/archiver/compress-brotli-with.go deleted file mode 100644 index f371e5f..0000000 --- a/sources/lib/archiver/compress-brotli-with.go +++ /dev/null @@ -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 -} - diff --git a/sources/lib/archiver/compress-brotli-without.go b/sources/lib/archiver/compress-brotli-without.go deleted file mode 100644 index 69f414c..0000000 --- a/sources/lib/archiver/compress-brotli-without.go +++ /dev/null @@ -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") -} - diff --git a/sources/lib/archiver/compress.go b/sources/lib/archiver/compress.go index 09ef3c9..a445c2c 100644 --- a/sources/lib/archiver/compress.go +++ b/sources/lib/archiver/compress.go @@ -9,6 +9,7 @@ import "fmt" 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 } + + + +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 +} +