[Scipy-svn] r6389 - trunk/scipy/io/matlab

scipy-svn at scipy.org scipy-svn at scipy.org
Mon May 10 21:52:36 EDT 2010


Author: matthew.brett at gmail.com
Date: 2010-05-10 20:52:36 -0500 (Mon, 10 May 2010)
New Revision: 6389

Modified:
   trunk/scipy/io/matlab/mio5.py
Log:
DOC - comments on decompression fix with assert

Modified: trunk/scipy/io/matlab/mio5.py
===================================================================
--- trunk/scipy/io/matlab/mio5.py	2010-05-10 19:52:36 UTC (rev 6388)
+++ trunk/scipy/io/matlab/mio5.py	2010-05-11 01:52:36 UTC (rev 6389)
@@ -353,9 +353,15 @@
         if mdtype == miCOMPRESSED:
             # make new stream from compressed data
             data = self.mat_stream.read(byte_count)
-            # use decompressobj to work round puzzling zlib.decompress
-            # failure: http://bugs.python.org/issue8672
-            stream = StringIO(zlib.decompressobj().decompress(data))
+            # Some matlab files contain zlib streams without valid
+            # Z_STREAM_END termination.  To get round this, we use the
+            # decompressobj object, that allows you to decode an
+            # incomplete stream.  See discussion at
+            # http://bugs.python.org/issue8672
+            dcor = zlib.decompressobj()
+            stream = StringIO(dcor.decompress(data))
+            # Check the stream is not so broken as to leave cruft behind
+            assert dcor.flush() == ''
             del data
             self._matrix_reader.set_stream(stream)
             mdtype, byte_count = self._matrix_reader.read_full_tag()




More information about the Scipy-svn mailing list