mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
Merge pull request #6456 from radarhere/memory
Moved tile encoding into separate function
This commit is contained in:
commit
f3551ae13e
|
@ -499,9 +499,14 @@ def _save(im, fp, tile, bufsize=0):
|
|||
try:
|
||||
fh = fp.fileno()
|
||||
fp.flush()
|
||||
exc = None
|
||||
except (AttributeError, io.UnsupportedOperation) as e:
|
||||
exc = e
|
||||
_encode_tile(im, fp, tile, bufsize, fh)
|
||||
except (AttributeError, io.UnsupportedOperation) as exc:
|
||||
_encode_tile(im, fp, tile, bufsize, None, exc)
|
||||
if hasattr(fp, "flush"):
|
||||
fp.flush()
|
||||
|
||||
|
||||
def _encode_tile(im, fp, tile, bufsize, fh, exc=None):
|
||||
for e, b, o, a in tile:
|
||||
if o > 0:
|
||||
fp.seek(o)
|
||||
|
@ -526,8 +531,6 @@ def _save(im, fp, tile, bufsize=0):
|
|||
raise OSError(f"encoder error {s} when writing image file") from exc
|
||||
finally:
|
||||
encoder.cleanup()
|
||||
if hasattr(fp, "flush"):
|
||||
fp.flush()
|
||||
|
||||
|
||||
def _safe_read(fp, size):
|
||||
|
|
Loading…
Reference in New Issue
Block a user