This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ZipFile.open treats directory path as empty file
Type: behavior Stage:
Components: Versions: Python 3.3, Python 3.4, Python 3.5, Python 2.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Kit Yan Choi
Priority: normal Keywords:

Created on 2017-06-21 16:06 by Kit Yan Choi, last changed 2022-04-11 14:58 by admin.

Messages (1)
msg296564 - (view) Author: Kit Yan Choi (Kit Yan Choi) * Date: 2017-06-21 16:06
Given a zipfile with the following content:

subdir/
file1.txt
subdir/file2.txt

    >>> archive = ZipFile(file_path, "r")
    >>> f = archive.open("subdir/", "r")
    >>>f.read()
    b''

It is quite odd that the subdirectory can be opened as if it was an empty file.  One would expect it to raise.

One use case is that the archive is created using shutil.make_archive, which includes the subdirectory paths in the namelist.  Upon looping ZipFile.namelist(), you end up opening a subdirectory and getting the empty content, which should have led to error and prompted the developers to filter the namelist first.
History
Date User Action Args
2022-04-11 14:58:48adminsetgithub: 74909
2017-06-21 16:06:47Kit Yan Choicreate