From 1e5498e237c208b6e26a1a248ae6869209f2458c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Zaoral?= Date: Mon, 8 Dec 2025 15:42:40 +0100 Subject: [PATCH] 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 --- src/ukify/ukify.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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') -- 2.47.3