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

Reset file object position in is_png() #2

Merged
merged 2 commits into from
Dec 7, 2017
Merged

Conversation

chunan
Copy link
Contributor

@chunan chunan commented Dec 6, 2017

Otherwise chunk() function will miss the first 8 bytes when png is file-object-like.

Otherwise chunk() function will miss the first 8 bytes when `png` is file-object-like.
apng/__init__.py Outdated

return png[:8] == PNG_SIGN
return png_header[:8] == PNG_SIGN
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. However bytes object is not handled correctly. Please use something like:

if isinstance(png, str):
	...
elif hasattr(png, "read"):
	...
elif isinstance(png, bytes):
	png_header = png[:8]
else:
	raise TypeError("Muse be file, bytes, or str")

Also no need to slice it again:

return png_header == PNG_SIGN

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@chunan
Copy link
Contributor Author

chunan commented Dec 7, 2017

Updated as requested. PTAL.

@eight04
Copy link
Owner

eight04 commented Dec 7, 2017

👍 I'll write some tests before releasing it.

@eight04 eight04 merged commit 325479c into eight04:master Dec 7, 2017
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

Successfully merging this pull request may close these issues.

2 participants