Closed kokumura closed 7 months ago
I found that #398 covers this problem in more detail. Please close this issue as duplication, sorry.
@kokumura when you have more time to investigate, it is a chance to dig and fix the long pending problem, flaged help wanted, and join to contributors list with Pull-Reuqest. As always it is welcome.
Describe the bug
SevenZipFile.writestr()
raisesAttributeError: 'NoneType' object has no attribute 'files'
under the following conditions:data
argument value is an empty stringwrite**
mthod call for the archive fileRelated issue
https://github.com/miurahr/py7zr/issues/398
To Reproduce
Here is a minimal code to reproduce the issue.
Run the code above, the following error occurs.
Expected behavior An empty file is created in the archive file with no errors.
Environment (please complete the following information):
v0.20.7
Test data(please attach in the report):
See thre reproduction code above.
Additional context
I found that
SevenZipFile._writef()
does not callself.header.initialize()
whensize == 0
(self.header.files_info
isNone
untilself.header.initialize()
is called.)https://github.com/miurahr/py7zr/blob/30e4184904cefd48e61c374846239b799134c41b/py7zr/py7zr.py#L1067-L1078
For a workaround, explicitly calling(Update) I noticed this workaround is not right. Do not try this. As reported in #398, writing empty file withheader.initialize()
beforewritestr()
solved my problem.writestr()
seems not working at all.