archive: support using lzma (MR 25)

fixes: https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/2
This commit is contained in:
Clayton Craft
2023-02-21 13:38:29 -08:00
parent ba1e1a77db
commit 786e09d855
4 changed files with 19 additions and 0 deletions

1
go.mod
View File

@@ -5,5 +5,6 @@ go 1.16
require (
github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e
github.com/klauspost/compress v1.15.12
github.com/ulikunitz/xz v0.5.10
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
)

2
go.sum
View File

@@ -2,5 +2,7 @@ github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e h1:hHg27A0RS
github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e/go.mod h1:oDpT4efm8tSYHXV5tHSdRvBet/b/QzxZ+XyyPehvm3A=
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/ulikunitz/xz v0.5.10 h1:t92gobL9l3HE202wg3rlk19F6X+JOxl9BBrCCMYEYd8=
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

View File

@@ -18,6 +18,7 @@ import (
"github.com/cavaliercoder/go-cpio"
"github.com/klauspost/compress/zstd"
"github.com/ulikunitz/xz"
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/osutil"
)
@@ -26,6 +27,7 @@ type CompressFormat string
const (
FormatGzip CompressFormat = "gzip"
FormatLzma CompressFormat = "lzma"
FormatZstd CompressFormat = "zstd"
)
@@ -98,6 +100,9 @@ func ExtractFormatLevel(s string) (format CompressFormat, level CompressLevel) {
switch format {
case FormatGzip:
case FormatLzma:
log.Println("Format lzma doesn't support a compression level, using default settings")
level = LevelDefault
case FormatZstd:
default:
log.Print("Unknown or no compression format set, using gzip")
@@ -295,6 +300,11 @@ func (archive *Archive) writeCompressed(path string, mode os.FileMode) error {
if err != nil {
return err
}
case FormatLzma:
compressor, err = xz.NewWriter(fd)
if err != nil {
return err
}
case FormatZstd:
level := zstd.SpeedDefault
switch archive.compress_level {

View File

@@ -243,6 +243,12 @@ func TestExtractFormatLevel(t *testing.T) {
expectedFormat: FormatGzip,
expectedLevel: LevelDefault,
},
{
name: "lzma, fast",
in: "lzma:fast",
expectedFormat: FormatLzma,
expectedLevel: LevelDefault,
},
}
for _, test := range tests {