According to the shipped typing stubs, ZstdDecompressionReader implements the typing.BinaryIO interface.
Unfortunately, it lacks the fileno() method that is promised by BinaryIO so this is a bit of a lie.
This breaks when trying to do something like:
>>> f = open('foo.zstd', 'rb')
>>> d = zstandard.ZstdDecompressor()
>>> g = d.stream_reader(f)
>>> subprocess.run(['cat'], stdin = g)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/spaans/.pyenv/versions/3.12.1/lib/python3.12/subprocess.py", line 548, in run
with Popen(*popenargs, **kwargs) as process:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/spaans/.pyenv/versions/3.12.1/lib/python3.12/subprocess.py", line 992, in __init__
errread, errwrite) = self._get_handles(stdin, stdout, stderr)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/spaans/.pyenv/versions/3.12.1/lib/python3.12/subprocess.py", line 1708, in _get_handles
p2cread = stdin.fileno()
^^^^^^^^^^^^
AttributeError: 'zstd.ZstdDecompressionReader' object has no attribute 'fileno'
Note that StringIO in the standard library also doesn't support fileno, but has instead chosen to raise an Exception when it is used like this, so a possible solution could be to just mimic that behaviour.
According to the shipped typing stubs,
ZstdDecompressionReader
implements thetyping.BinaryIO
interface.Unfortunately, it lacks the
fileno()
method that is promised byBinaryIO
so this is a bit of a lie. This breaks when trying to do something like:Note that
StringIO
in the standard library also doesn't supportfileno
, but has instead chosen to raise an Exception when it is used like this, so a possible solution could be to just mimic that behaviour.