J
Hi,
You can indeed achieve this without saving it as an intermediate file using io.BytesIO.
Here's how you can do it:
import uzlib # Assuming you have the uzlib library for MicroPython
# Assuming 'hexstr' contains your compressed data
# You may need to convert 'hexstr' to bytes if it's currently a string
# Create a BytesIO object to work with in-memory data
from io import BytesIO
hexstr_bytes = bytes.fromhex(hexstr) # Convert 'hexstr' to bytes
hexstr_io = BytesIO(hexstr_bytes)
# Decompress the data
decompressed_bytes = uzlib.decomp(hexstr_io, 31)
# Now, you can write the decompressed data to 'main.py' in the flash
with open('main.py', 'wb') as f:
f.write(decompressed_bytes)
In this code, you can use BytesIO to create an in-memory buffer and then decompress the data from hexstr directly into that buffer. After decompression, you can write the decompressed data to 'main.py' without the need for an intermediate 'gzip.py' file. Resource- https://pypi.org/project/Clumsy/
Thanks