archive: support using lz4 legacy (MR 36)
fixes: https://gitlab.com/postmarketOS/postmarketos-mkinitfs/-/issues/27
This commit is contained in:
committed by
Clayton Craft
parent
0054fde90d
commit
a15c02f3aa
1
go.mod
1
go.mod
@@ -5,6 +5,7 @@ go 1.20
|
||||
require (
|
||||
github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e
|
||||
github.com/klauspost/compress v1.15.12
|
||||
github.com/pierrec/lz4/v4 v4.1.17
|
||||
github.com/ulikunitz/xz v0.5.10
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
|
||||
)
|
||||
|
2
go.sum
2
go.sum
@@ -2,6 +2,8 @@ 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/pierrec/lz4/v4 v4.1.17 h1:kV4Ip+/hUBC+8T6+2EgburRtkE9ef4nbY3f4dFhGjMc=
|
||||
github.com/pierrec/lz4/v4 v4.1.17/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4=
|
||||
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=
|
||||
|
@@ -18,6 +18,7 @@ import (
|
||||
|
||||
"github.com/cavaliercoder/go-cpio"
|
||||
"github.com/klauspost/compress/zstd"
|
||||
"github.com/pierrec/lz4/v4"
|
||||
"github.com/ulikunitz/xz"
|
||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
|
||||
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/osutil"
|
||||
@@ -28,6 +29,7 @@ type CompressFormat string
|
||||
const (
|
||||
FormatGzip CompressFormat = "gzip"
|
||||
FormatLzma CompressFormat = "lzma"
|
||||
FormatLz4 CompressFormat = "lz4"
|
||||
FormatZstd CompressFormat = "zstd"
|
||||
FormatNone CompressFormat = "none"
|
||||
)
|
||||
@@ -104,6 +106,7 @@ func ExtractFormatLevel(s string) (format CompressFormat, level CompressLevel) {
|
||||
case FormatLzma:
|
||||
log.Println("Format lzma doesn't support a compression level, using default settings")
|
||||
level = LevelDefault
|
||||
case FormatLz4:
|
||||
case FormatNone:
|
||||
case FormatZstd:
|
||||
default:
|
||||
@@ -348,6 +351,23 @@ func (archive *Archive) writeCompressed(path string, mode os.FileMode) (err erro
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case FormatLz4:
|
||||
// The default compression for the lz4 library is Fast, and
|
||||
// they don't define a Default level otherwise
|
||||
level := lz4.Fast
|
||||
switch archive.compress_level {
|
||||
case LevelBest:
|
||||
level = lz4.Level9
|
||||
case LevelFast:
|
||||
level = lz4.Fast
|
||||
}
|
||||
|
||||
var writer = lz4.NewWriter(fd)
|
||||
err = writer.Apply(lz4.LegacyOption(true), lz4.CompressionLevelOption(level))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
compressor = writer
|
||||
case FormatNone:
|
||||
compressor = fd
|
||||
case FormatZstd:
|
||||
|
@@ -249,6 +249,12 @@ func TestExtractFormatLevel(t *testing.T) {
|
||||
expectedFormat: FormatLzma,
|
||||
expectedLevel: LevelDefault,
|
||||
},
|
||||
{
|
||||
name: "lz4, fast",
|
||||
in: "lz4:fast",
|
||||
expectedFormat: FormatLz4,
|
||||
expectedLevel: LevelFast,
|
||||
},
|
||||
{
|
||||
name: "none",
|
||||
in: "none",
|
||||
|
Reference in New Issue
Block a user