You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I am attempting to use zipp.Path to construct a zip archive. I encountered the following issue:
importiofromzipfileimportZipFileimportzippdefmake_zip():
"""Make zip file and return bytes."""bytes_io=io.BytesIO()
zip_file=ZipFile(bytes_io, mode="w")
zipp_path=zipp.Path(zip_file)
# use zipp.Path.openwithzipp_path.joinpath("file-a").open(mode="wb") asfp:
fp.write(b"contents of file-a")
zip_file.close()
data=bytes_io.getvalue()
bytes_io.close()
returndatazip_data=make_zip()
# Exception ignored in: <bound method ZipFile.__del__ of <zipp.CompleteDirs [closed]>># Traceback (most recent call last):# File "/Users/nw_henderson/.pyenv/versions/3.6.10/lib/python3.6/zipfile.py", line 1686, in __del__# self.close()# File "/Users/nw_henderson/.pyenv/versions/3.6.10/lib/python3.6/zipfile.py", line 1703, in close# self.fp.seek(self.start_dir)# ValueError: I/O operation on closed file.
Following the zipfile docs, I call close() before extracting the data from bytes_io. It looks like zipp.Path keeps some other reference to the file object and attempts to write when make_zip returns and objects are cleaned up. Python 3.8 exhibits the same issue.
The text was updated successfully, but these errors were encountered:
Hello! I am attempting to use
zipp.Path
to construct a zip archive. I encountered the following issue:Following the zipfile docs, I call
close()
before extracting the data frombytes_io
. It looks likezipp.Path
keeps some other reference to the file object and attempts to write whenmake_zip
returns and objects are cleaned up. Python 3.8 exhibits the same issue.The text was updated successfully, but these errors were encountered: