Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

png.Reader not guessing bytes #118

Open
mulac opened this issue Jul 22, 2022 · 1 comment
Open

png.Reader not guessing bytes #118

mulac opened this issue Jul 22, 2022 · 1 comment
Assignees
Labels

Comments

@mulac
Copy link

mulac commented Jul 22, 2022

The docs says Reader.init takes bytes but fails on the isinstance(some_bytes, array) check.

Is this expected behaviour?

>>> import png
>>> png.Reader("tests/doop.png")
<png.Reader object at 0x7fd48d3cf100>
>>> with open("tests/doop.png", 'rb') as f:
...     png.Reader(f.read())
... 
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/calum/.cache/pypoetry/virtualenvs/hsi-ZCFKj1YC-py3.10/lib/python3.10/site-packages/png.py", line 1375, in __init__
    raise ProtocolError("expecting filename, file or bytes array")
png.ProtocolError: ProtocolError: expecting filename, file or bytes array
@drj11 drj11 self-assigned this Jul 28, 2022
@drj11 drj11 added the bug label Jul 28, 2022
@drj11
Copy link
Owner

drj11 commented Jul 28, 2022

The design predates the type bytes (it's from early Python 2, and possibly Python 1.5.2), so it only works on array.array("B").

However, i can see that png.Reader(f.read()) could be useful, so i shall consider this a bug.

png.Reader(f) should work by the way; although it does then become unclear when you should close f.

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

No branches or pull requests

2 participants