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:
@@ -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
|
||||
}
|
||||
|
@@ -45,14 +45,16 @@ type Archive struct {
|
||||
cpioWriter *cpio.Writer
|
||||
buf *bytes.Buffer
|
||||
compress_format CompressFormat
|
||||
compress_level CompressLevel
|
||||
}
|
||||
|
||||
func New(format CompressFormat) (*Archive, error) {
|
||||
func New(format CompressFormat, level CompressLevel) (*Archive, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
archive := &Archive{
|
||||
cpioWriter: cpio.NewWriter(buf),
|
||||
buf: buf,
|
||||
compress_format: format,
|
||||
compress_level: level,
|
||||
}
|
||||
|
||||
return archive, nil
|
||||
|
Reference in New Issue
Block a user