From e172e6e6f60b8c7852eb93c5fb63843408b6ac8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= Date: Mon, 12 May 2025 13:31:17 +0200 Subject: [PATCH] Sources/inline: support lzma+base64 encoded data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extend the inline source to support lzma compressed and base64 encoded 'data'. This will allow us to reduce the potential manifest size when embedding big files. The aim is specifically at eventually embedding SBOMs of the image. An example single SBOM can be a JSON file with size of about 1.9 MiB. The lzma+base64 combination reduces the 'data' to embed to "only" around 250 KiB. Signed-off-by: Tomáš Hozza --- sources/org.osbuild.inline | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/sources/org.osbuild.inline b/sources/org.osbuild.inline index 009c4bbe..7dfe9e42 100755 --- a/sources/org.osbuild.inline +++ b/sources/org.osbuild.inline @@ -13,6 +13,7 @@ resource is decoded and written to the store. import base64 import contextlib +import lzma import os import sys from typing import Dict @@ -34,7 +35,7 @@ SCHEMA = """ "properties": { "encoding": { "description": "The specific encoding of `data`", - "enum": ["base64"] + "enum": ["base64", "lzma+base64"] }, "data": { "description": "The ascii encoded raw data", @@ -70,7 +71,14 @@ class InlineSource(sources.SourceService): if os.path.isfile(target): return - data = base64.b64decode(desc["data"]) + encoding = desc["encoding"] + if encoding == "base64": + data = base64.b64decode(desc["data"]) + elif encoding == "lzma+base64": + data = base64.b64decode(desc["data"]) + data = lzma.decompress(data) + else: + raise RuntimeError(f"Unknown encoding {encoding}") # Write the bits to disk and then verify the checksum # This ensures that 1) the data is ok and that 2) we