archive: support using zstd (MR 25)

This external module was chosen because it's a native Go implementation
of zstd, and not a wrapper around some external utility or some CGO
thing.
This commit is contained in:
Clayton Craft
2022-11-17 16:36:45 -08:00
parent 31b7eb34ee
commit 52fc741ba8
3 changed files with 10 additions and 0 deletions

1
go.mod
View File

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

2
go.sum
View File

@@ -1,4 +1,6 @@
github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e h1:hHg27A0RSSp2Om9lubZpiMgVbvn39bsUmW9U5h0twqc= github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e h1:hHg27A0RSSp2Om9lubZpiMgVbvn39bsUmW9U5h0twqc=
github.com/cavaliercoder/go-cpio v0.0.0-20180626203310-925f9528c45e/go.mod h1:oDpT4efm8tSYHXV5tHSdRvBet/b/QzxZ+XyyPehvm3A= 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=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I= 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= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

View File

@@ -17,6 +17,7 @@ import (
"syscall" "syscall"
"github.com/cavaliercoder/go-cpio" "github.com/cavaliercoder/go-cpio"
"github.com/klauspost/compress/zstd"
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist" "gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/filelist"
"gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/osutil" "gitlab.com/postmarketOS/postmarketos-mkinitfs/internal/osutil"
) )
@@ -25,6 +26,7 @@ type CompressFormat string
const ( const (
FormatGzip CompressFormat = "gzip" FormatGzip CompressFormat = "gzip"
FormatZstd CompressFormat = "zstd"
) )
type Archive struct { type Archive struct {
@@ -233,6 +235,11 @@ func (archive *Archive) writeCompressed(path string, mode os.FileMode) error {
switch archive.compress_format { switch archive.compress_format {
case FormatGzip: case FormatGzip:
compressor = gzip.NewWriter(fd) compressor = gzip.NewWriter(fd)
case FormatZstd:
compressor, err = zstd.NewWriter(fd)
if err != nil {
return err
}
default: default:
log.Print("Unknown or no compression format set, using gzip") log.Print("Unknown or no compression format set, using gzip")
compressor = gzip.NewWriter(fd) compressor = gzip.NewWriter(fd)