Skip to content

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

Closed
@juhanijaakola

Description

@juhanijaakola

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions