archive.New: accept compression level (MR 25)

I went with a simpler implementation that uses Go compression packages
to do the work. The downside of this is that the compression Level is a
bit weird to set, since most libraries discourage setting the numeric
compression level directly.

This is configured by setting `deviceinfo_initfs_compression`, the value
it expects is a string in the form: `FORMAT[:LEVEL]`, where `[:LEVEL]`
is optional. Actually setting the variable at all is optional... if
nothing is specified, or it can't parse the format/level from the string
value, it defaults to using gzip with the "default" level for the
package (which tries to mirror gzip's default, or something).

The level can be one of `default`, `fast`, `best`.

To configure gzip with the fastest compression (so, bigger size): deviceinfo_initfs_compression="gzip:fast"`

To configure zstd with the most compression: `deviceinfo_initfs_compression="zstd:best"`

To configure zstd with default compression: `deviceinfo_initfs_compression="zstd"` (or `deviceinfo_initfs_compression="zstd:default"`)

In this case, `gzip:default` is assumed: deviceinfo_initfs_compression="bananas:mmmm"`
This commit is contained in:
Clayton Craft
2023-02-21 11:47:38 -08:00
parent 322d6bb754
commit fd11f4a627
2 changed files with 10 additions and 5 deletions

View File

@@ -63,6 +63,9 @@ func main() {
return
}
// deviceinfo.InitfsCompression needs a little more post-processing
compressionFormat, compressionLevel := archive.ExtractFormatLevel(devinfo.InitfsCompression)
defer misc.TimeFunc(time.Now(), "mkinitfs")
kernVer, err := osutil.GetKernelVersion()
@@ -91,7 +94,7 @@ func main() {
log.Print("Generating for kernel version: ", kernVer)
log.Print("Output directory: ", *outDir)
if err := generateArchive("initramfs", devinfo.InitfsCompression, workDir, []filelist.FileLister{
if err := generateArchive("initramfs", compressionFormat, compressionLevel, workDir, []filelist.FileLister{
hookdirs.New("/usr/share/mkinitfs/dirs"),
hookdirs.New("/etc/mkinitfs/dirs"),
hookfiles.New("/usr/share/mkinitfs/files"),
@@ -107,7 +110,7 @@ func main() {
return
}
if err := generateArchive("initramfs-extra", devinfo.InitfsCompression, workDir, []filelist.FileLister{
if err := generateArchive("initramfs-extra", compressionFormat, compressionLevel, workDir, []filelist.FileLister{
hookfiles.New("/usr/share/mkinitfs/files-extra"),
hookfiles.New("/etc/mkinitfs/files-extra"),
hookscripts.New("/usr/share/mkinitfs/hooks-extra"),
@@ -141,10 +144,10 @@ func bootDeploy(workDir, outDir, ubootBoardname string) error {
return bd.Run()
}
func generateArchive(name string, compressionFormat string, path string, features []filelist.FileLister) error {
func generateArchive(name string, format archive.CompressFormat, level archive.CompressLevel, path string, features []filelist.FileLister) error {
log.Printf("== Generating %s ==\n", name)
defer misc.TimeFunc(time.Now(), name)
a, err := archive.New(archive.CompressFormat(compressionFormat))
a, err := archive.New(format, level)
if err != nil {
return err
}