shibukawa / imagesize_py

MIT License
227 stars 44 forks source link

BufferedReader instances aren't used correctly #57

Open Gilthans opened 1 year ago

Gilthans commented 1 year ago

Hello! Thanks for the awesome package!

I tried doing something similar to:

with open(path, "rb") as f:
  imagesize.get(f)

But got an exception, since get expects the parameter to be either BytesIO or a PathLike/str, and it turns out open() returns a BufferedReader which is neither.

This is a simple fix since BufferedReader implements the same needed API as BytesIO. I'd like to suggest a change: if the parameter is a str or PathLike, try to open it, in any other case try to use it as a buffer.

This would solve my use case and open more possibilities (i.e. a BufferedReader reading from HTTP could be used for e.g. #44 ).

Does this sound good? If so, I'd be happy to submit a PR.

Thanks!

guangrei commented 8 months ago

+1 for this

fuyb1992 commented 2 weeks ago

+1 for this