Skip directories and empty files in ZIP archives
authorThierry Florac <thierry.florac@onf.fr>
Mon, 19 Nov 2018 13:24:44 +0100
changeset 154 a94912ae1695
parent 153 81f5c430a952
child 155 ea055b7b9ae8
Skip directories and empty files in ZIP archives
src/pyams_file/archive/zip.py
--- a/src/pyams_file/archive/zip.py	Fri Nov 16 15:16:10 2018 +0100
+++ b/src/pyams_file/archive/zip.py	Mon Nov 19 13:24:44 2018 +0100
@@ -12,16 +12,11 @@
 
 __docformat__ = 'restructuredtext'
 
-
-# import standard library
+import zipfile
 from io import BytesIO
-import zipfile
 
-# import interfaces
+from pyams_file.file import get_magic_content_type
 from pyams_file.interfaces.archive import IArchiveExtractor
-
-# import packages
-from pyams_file.file import get_magic_content_type
 from pyams_utils.registry import query_utility, utility_config
 
 
@@ -41,6 +36,8 @@
         for member in members:
             filename = member.filename
             content = self.zip_data.read(filename)
+            if not content:  # skip empty files and directories
+                continue
             mime_type = get_magic_content_type(content[:4096])
             extractor = query_utility(IArchiveExtractor, name=mime_type)
             if extractor is not None: