Skip to content

Example in library deflate documentation with deflate.DeflateIO and io.BytesIO throws OSError: [Errno 22] EINVAL #17244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
juhanijaakola opened this issue May 4, 2025 · 1 comment
Labels

Comments

@juhanijaakola
Copy link

Port, board and/or hardware

ESP32_GENERIC_C3-20250415-v1.25.0

MicroPython version

MicroPython v1.25.0 on 2025-04-15; ESP32C3 module with ESP32C3

Reproduction

with open('response_body.bin', 'rb') as f:
    data = f.read()
len(data)

1794

import deflate, io
with deflate.DeflateIO(io.BytesIO(data), deflate.ZLIB) as d:
    decompressed_data = d.read()

Traceback (most recent call last):
File "", line 2, in
OSError: [Errno 22] EINVAL

with open('response_body.bin', 'rb') as f:
    with deflate.DeflateIO(f, deflate.GZIP) as d:
        decompressed_data = d.read()

(Decompressing directly from a file stream works!)

data[:40]

b'\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\x03\xcd[\xdbn\xdbF\x10}\xcfW\x082\xfa\x12\xc4\xb2HK\x96\xec\x17c\x11\xb1\xf5\x9aWh\x97L'

Expected behaviour

Expected to work without the EINVAL exception

Observed behaviour

Using deflate.DeflateIO with a stream from io.BytesIO throws exception EINVAL

Additional Information

Here is what the Linux file command says about the data to be decompressed:

$ file response_body.bin
response_body.bin: gzip compressed data, from Unix, original size modulo 2^32 15437

Code of Conduct

Yes, I agree

@juhanijaakola
Copy link
Author

According to an example from https://docs.micropython.org/en/latest/library/deflate.html deflate.DeflateIO(io.BytesIO(compressed_data), deflate.ZLIB) should work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant