Closed cjbumgardner closed 10 months ago
I encountered the same problem trying to use io.BytesIO
. I tried resetting _fobj
before saving, but there are more issues like #30 and #36. Bute since save
uses tempfile.mkstemp
anyway, I copied my BytesIO
to a tempfile.NamedTemporaryFile
and let IPTCInfo handle it like this instead:
buf = io.BytesIO()
buf.write(...) # add image data
with tempfile.NamedTemporaryFile() as src:
src.write(buf.getvalue())
iptcinfo = IPTCInfo(src.name)
# change stuff...
iptcinfo.save_as(src.name)
src.seek(0)
buf = io.BytesIO(src.read())
@cjbumgardner yeah I would adopt @ValentinVoigt approach and save to tempfile and then let IPTCInfo handle it. Why would you not start with a file in the first place? Id be happy to review any pull requests to add the functionality that would depend on the content initiating.
ok no response, closing.
Code Example:
Raises:
This may be the intended functionality, but it seems that functionality shouldn't change depending on the content initiating IPTCInfo. The ValueError is actually due to two uses of 'with' statements using
smart_open
onself._fobj
(when it is a file object). The first at the end ofIPTCInfo.__init__
would close the file object, so whensmart_open
is called inIPTCInfo.save_as
it is already closed.