Skip to content
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

BufferedReader instances aren't used correctly #57

Open
Gilthans opened this issue Nov 20, 2022 · 2 comments
Open

BufferedReader instances aren't used correctly #57

Gilthans opened this issue Nov 20, 2022 · 2 comments

Comments

@Gilthans
Copy link

Gilthans commented Nov 20, 2022

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
Copy link

+1 for this

1 similar comment
@fuyb1992
Copy link

+1 for this

fuyb1992 added a commit to fuyb1992/imagesize_py that referenced this issue Oct 11, 2024
add BufferedReader support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants