-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Before You Begin
Before proceeding, please make sure to follow these steps:
- I have checked for similar issues in the project's issue tracker.
- I have searched closed issues to see if a similar problem was reported
before.
Issue Details
After using MutableZipFile
in write
mode for writing to an in memory zip through BytesIO
, using MutableZipFile
in append
mode raises AttributeError
due to file name request to an in memory zip.
Description
Thi minimal example to replicate the error and generated stdout
are provided below, with file paths redacted.
from io import BytesIO
from zipfile import ZIP_DEFLATED
from mutablezip import MutableZipFile
in_memory_zip = BytesIO()
with MutableZipFile(in_memory_zip, "w", compression=ZIP_DEFLATED) as file:
lines = [b"first line"]
file.writestr("foo.txt", b"\n".join(lines))
with MutableZipFile(in_memory_zip, "a", compression=ZIP_DEFLATED) as file:
lines = [b"new line"]
file.writestr("foo.txt", b"\n".join(lines))
with open("foo.zip", "wb") as file:
file.write(in_memory_zip.getvalue())
Traceback (most recent call last):
File "<file-path>", line 11, in <module>
with MutableZipFile(in_memory_zip, "a", compression=ZIP_DEFLATED) as file:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<venv-path>/lib64/python3.12/site-packages/mutablezip/__init__.py", line 105, in __exit__
self._rebuildZip()
File "<venv-path>/lib64/python3.12/site-packages/mutablezip/__init__.py", line 152, in _rebuildZip
move(tempZipPath, self.file.name)
^^^^^^^^^^^^^^
AttributeError: '_io.BytesIO' object has no attribute 'name'
System Information
Please provide the following additional information about your system or
environment:
- Operating System (OS): GNU/Linux
- OS Version: Fedora Linux 41 (Workstation Edition) x86_64
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working