summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2025-04-17 10:20:33 +1000
committerDamien George <damien@micropython.org>2025-04-24 22:33:05 +1000
commitdcca3ff602c821e5b252cbe44e669806b0a6f416 (patch)
tree95ede98597dad783793e0a7b6877d33f1cf24b6f
parent584fa8800b833b53c6d6f9eb7572774a67304d2f (diff)
downloadmicropython-dcca3ff602c821e5b252cbe44e669806b0a6f416.tar.gz
micropython-dcca3ff602c821e5b252cbe44e669806b0a6f416.zip
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 <damien@micropython.org>
-rw-r--r--tools/mpremote/mpremote/commands.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/tools/mpremote/mpremote/commands.py b/tools/mpremote/mpremote/commands.py
index 690b2ea723..1e13b33afe 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: