flush if hasattr

Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
This commit is contained in:
Hugo van Kemenade 2021-06-28 17:48:06 +03:00 committed by GitHub
parent 70fafe3da7
commit 38d45d2848
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -352,7 +352,8 @@ def _save(im, fp, filename):
fp.write(struct.pack("<i", HEADERSIZE + e["size"])[::-1])
fp.write(e["stream"].getvalue())
fp.flush()
if hasattr(fp, "flush"):
fp.flush()
Image.register_open(IcnsImageFile.format, IcnsImageFile, lambda x: x[:4] == b"icns")