Permalink
Browse files

support loading empty archives

  • Loading branch information...
1 parent 797d488 commit 7b6a73e9fe98e49b972a3fb668c9330c5db6ca75 @fancycode committed Sep 20, 2011
Showing with 14 additions and 2 deletions.
  1. +8 −2 py7zlib.py
  2. BIN tests/data/empty.7z
  3. +6 −0 tests/test_7zfiles.py
View
@@ -714,7 +714,7 @@ def __init__(self, file, password=None):
while True:
id = buffer.read(1)
- if id == PROPERTY_HEADER:
+ if not id or id == PROPERTY_HEADER:
break
if id != PROPERTY_ENCODED_HEADER:
@@ -737,9 +737,15 @@ def __init__(self, file, password=None):
buffer = BytesIO(data)
- self.header = Header(buffer)
self.files = []
+ if not id:
+ # empty archive
+ self.solid = False
+ self.numfiles = 0
+ self.filenames = []
+ return
+ self.header = Header(buffer)
files = self.header.files
folders = self.header.main_streams.unpackinfo.folders
packinfo = self.header.main_streams.packinfo
View
Binary file not shown.
View
@@ -176,6 +176,12 @@ def test_bugzilla_16(self):
cf = archive.getmember(filename)
self.failUnlessEqual(len(cf.read()), cf.uncompressed)
+ def test_empty(self):
+ # decompress empty archive
+ fp = open(os.path.join(ROOT, 'data', 'empty.7z'), 'rb')
+ archive = Archive7z(fp)
+ self.failUnlessEqual(archive.getnames(), [])
+
def suite():
suite = unittest.TestSuite()

0 comments on commit 7b6a73e

Please sign in to comment.