[archiver] Add support for building without Brotli compression, therefore obtaining a static archiver executable
This commit is contained in:
parent
8f8b9d6f9a
commit
bf6849ef92
4 changed files with 50 additions and 21 deletions
|
@ -129,7 +129,8 @@
|
|||
exec -- "${ZRUN[@]}" ':: go / tool' \
|
||||
build \
|
||||
-v \
|
||||
-ldflags 'all=-s' \
|
||||
-tags 'netgo nobrotli' \
|
||||
-ldflags 'all=-s -extld=gcc -extldflags=-static' \
|
||||
-gcflags 'all=-l=4' \
|
||||
-o "${_outputs}/binaries/release/kawipiko-archiver" \
|
||||
-- ./cmd/archiver.go \
|
||||
|
|
31
sources/lib/archiver/compress-brotli-with.go
Normal file
31
sources/lib/archiver/compress-brotli-with.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
|
||||
// +build !nobrotli
|
||||
|
||||
|
||||
package archiver
|
||||
|
||||
|
||||
import "bytes"
|
||||
|
||||
import "github.com/google/brotli/go/cbrotli"
|
||||
|
||||
|
||||
|
||||
|
||||
func CompressBrotli (_data []byte) ([]byte, string, error) {
|
||||
|
||||
_buffer := & bytes.Buffer {}
|
||||
|
||||
_encoder := cbrotli.NewWriter (_buffer, cbrotli.WriterOptions { Quality : 11, LGWin : 24})
|
||||
|
||||
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
|
||||
}
|
||||
|
17
sources/lib/archiver/compress-brotli-without.go
Normal file
17
sources/lib/archiver/compress-brotli-without.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
|
||||
// +build nobrotli
|
||||
|
||||
|
||||
package archiver
|
||||
|
||||
|
||||
import "fmt"
|
||||
|
||||
|
||||
|
||||
|
||||
func CompressBrotli (_data []byte) ([]byte, string, error) {
|
||||
|
||||
return nil, "", fmt.Errorf ("[9252cf70] unsupported compression algorithm `%s`", "brotli")
|
||||
}
|
||||
|
|
@ -7,8 +7,6 @@ import "bytes"
|
|||
import "compress/gzip"
|
||||
import "fmt"
|
||||
|
||||
import "github.com/google/brotli/go/cbrotli"
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -50,21 +48,3 @@ func CompressGzip (_data []byte) ([]byte, string, error) {
|
|||
return _data, "gzip", nil
|
||||
}
|
||||
|
||||
|
||||
func CompressBrotli (_data []byte) ([]byte, string, error) {
|
||||
|
||||
_buffer := & bytes.Buffer {}
|
||||
|
||||
_encoder := cbrotli.NewWriter (_buffer, cbrotli.WriterOptions { Quality : 11, LGWin : 24})
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue