From: Lukáš Zaoral Date: Mon, 8 Dec 2025 14:42:40 +0000 (+0100) Subject: ukify: prefer compression.zstd when available X-Git-Tag: v259-rc3~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1e5498e237c208b6e26a1a248ae6869209f2458c;p=thirdparty%2Fsystemd.git ukify: prefer compression.zstd when available Python 3.14 introduced support for zstd in the standard library [1]. Therefore, let's prefer it when available to decrease the number of necessary external dependencies. [1] https://docs.python.org/3/whatsnew/3.14.html#whatsnew314-zstandard --- diff --git a/src/ukify/ukify.py b/src/ukify/ukify.py index fce36b66860..ad6560534ac 100755 --- a/src/ukify/ukify.py +++ b/src/ukify/ukify.py @@ -198,9 +198,14 @@ def get_zboot_kernel(f: IO[bytes]) -> bytes: elif comp_type.startswith(b'xzkern'): raise NotImplementedError('xzkern decompression not implemented') elif comp_type.startswith(b'zstd'): - zstd = try_import('zstandard') - data = f.read(size) - return cast(bytes, zstd.ZstdDecompressor().stream_reader(data).read()) + try: + zstd = try_import('compression.zstd') + data = f.read(size) + return cast(bytes, zstd.zstd.ZstdDecompressor().decompress(data)) + except ValueError: + zstd = try_import('zstandard') + data = f.read(size) + return cast(bytes, zstd.ZstdDecompressor().stream_reader(data).read()) raise NotImplementedError(f'unknown compressed type: {comp_type!r}') @@ -230,8 +235,12 @@ def maybe_decompress(filename: Union[str, Path]) -> bytes: return cast(bytes, gzip.open(f).read()) if start.startswith(b'\x28\xb5\x2f\xfd'): - zstd = try_import('zstandard') - return cast(bytes, zstd.ZstdDecompressor().stream_reader(f.read()).read()) + try: + zstd = try_import('compression.zstd') + return cast(bytes, zstd.zstd.ZstdDecompressor().decompress(f.read())) + except ValueError: + zstd = try_import('zstandard') + return cast(bytes, zstd.ZstdDecompressor().stream_reader(f.read()).read()) if start.startswith(b'\x02\x21\x4c\x18'): lz4 = try_import('lz4.frame', 'lz4')