mirror of
https://github.com/goreleaser/nfpm
synced 2026-07-23 05:54:49 +02:00
e1c7b33e10
* feat: replace rpmpack with a more complete implementation * chore: add extra testing * feat: add lang support and config|tree support for rpm --------- Co-authored-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
47 lines
1.1 KiB
Go
47 lines
1.1 KiB
Go
package rpm
|
|
|
|
import (
|
|
"compress/gzip"
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
|
|
"go.digitalxero.dev/rpm"
|
|
)
|
|
|
|
// parseCompression maps the nfpm compression setting (an algorithm name with an
|
|
// optional ":level" suffix, e.g. "zstd:19") onto a rpm.Compressor. xz and lzma
|
|
// do not take a level, so any provided level is ignored for them.
|
|
func parseCompression(compression string) (rpm.Compressor, error) {
|
|
name, levelStr, hasLevel := strings.Cut(compression, ":")
|
|
|
|
level := 0
|
|
levelSet := false
|
|
if hasLevel && levelStr != "" {
|
|
l, err := strconv.Atoi(levelStr)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("rpm: invalid compression level %q: %w", levelStr, err)
|
|
}
|
|
level, levelSet = l, true
|
|
}
|
|
|
|
switch name {
|
|
case "", "gzip", "gz":
|
|
if levelSet {
|
|
return rpm.GzipCompressor(level), nil
|
|
}
|
|
return rpm.GzipCompressor(gzip.DefaultCompression), nil
|
|
case "zstd":
|
|
if levelSet {
|
|
return rpm.ZstdCompressor(level), nil
|
|
}
|
|
return rpm.ZstdCompressor(3), nil
|
|
case "xz":
|
|
return rpm.XzCompressor(), nil
|
|
case "lzma":
|
|
return rpm.LzmaCompressor(), nil
|
|
default:
|
|
return nil, fmt.Errorf("rpm: unsupported compression %q", name)
|
|
}
|
|
}
|