Suppose a.zip is z zip file containing 'abc/def/1.txt' zf = zipfile.ZipFile('a.zip') memf = zf.open('abc/def/1.txt', 'r') zf2 = zipfile.ZipFile(memf) will raise an error. However, when a.zip is a tar file containing 'abc/def/1.txt', the following codes tf = tarfile.open('a.zip') memf = tf.open('abc/def/1.txt', 'r') zf2 = zipfile.ZipFile(memf) works well. Is it a known issue? Thanks!
The current behavior looks correct to me. abc/def/1.txt is not a ZIP file, so the error is expected. tarfile.open('a.zip') raises an error too, because a.zip is not a tar file.
Sorry, I made a mistake. I retested on the following content a.zip ==> abc/def/1.zip zf = zipfile.ZipFile('a.zip') memf = zf.open('abc/def/1.zip', 'r') zf2 = zipfile.ZipFile(memf) will raise an error. However, when a.zip is a tar file containing 'abc/def/1.zip', the following codes a.tar ===> abc/def/1.zip tf = tarfile.open('a.tar') memf = tf.extractfile('abc/def/1.zip') zf2 = zipfile.ZipFile(memf) works well. Since only one file can be uploaded, I will try to upload the tar file on the next post.
Supporting nested zip files is a new feature added in 3.7 (see ). New features can be added only in new Python versions. 3.6 currently takes only security bug fixes.
History
Date
User
Action
Args
2022-04-11 14:59:11
admin
set
github: 80269
2019-02-23 05:38:06
serhiy.storchaka
set
status: open -> closedresolution: out of datemessages: + stage: resolved