From dcca3ff602c821e5b252cbe44e669806b0a6f416 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 17 Apr 2025 10:20:33 +1000 Subject: [PATCH] tools/mpremote: Use zlib.compressobj instead of zlib.compress. Because the `wbits` parameter was only added to `zlib.compress` in CPython 3.11. Using `zlib.compressobj` makes the code compatible with much older CPython versions. Fixes issue #17140. Signed-off-by: Damien George --- tools/mpremote/mpremote/commands.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py index 690b2ea72..1e13b33af 100644 --- a/tools/mpremote/mpremote/commands.py +++ b/tools/mpremote/mpremote/commands.py @@ -649,7 +649,9 @@ def _do_romfs_deploy(state, args): romfs_chunk += bytes(chunk_size - len(romfs_chunk)) if has_deflate_io: # Needs: binascii.a2b_base64, io.BytesIO, deflate.DeflateIO. - romfs_chunk_compressed = zlib.compress(romfs_chunk, wbits=-9) + compressor = zlib.compressobj(wbits=-9) + romfs_chunk_compressed = compressor.compress(romfs_chunk) + romfs_chunk_compressed += compressor.flush() buf = binascii.b2a_base64(romfs_chunk_compressed).strip() transport.exec(f"buf=DeflateIO(BytesIO(a2b_base64({buf})),RAW,9).read()") elif has_a2b_base64: