Skip to content

Commit dcca3ff

Browse files
committed
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 micropython#17140. Signed-off-by: Damien George <[email protected]>
1 parent 584fa88 commit dcca3ff

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tools/mpremote/mpremote/commands.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,9 @@ def _do_romfs_deploy(state, args):
649649
romfs_chunk += bytes(chunk_size - len(romfs_chunk))
650650
if has_deflate_io:
651651
# Needs: binascii.a2b_base64, io.BytesIO, deflate.DeflateIO.
652-
romfs_chunk_compressed = zlib.compress(romfs_chunk, wbits=-9)
652+
compressor = zlib.compressobj(wbits=-9)
653+
romfs_chunk_compressed = compressor.compress(romfs_chunk)
654+
romfs_chunk_compressed += compressor.flush()
653655
buf = binascii.b2a_base64(romfs_chunk_compressed).strip()
654656
transport.exec(f"buf=DeflateIO(BytesIO(a2b_base64({buf})),RAW,9).read()")
655657
elif has_a2b_base64:

0 commit comments

Comments
 (0)