~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tuned_gzip.py

  • Committer: Robert Collins
  • Date: 2006-04-20 04:52:19 UTC
  • mto: (1711.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1677.
  • Revision ID: robertc@robertcollins.net-20060420045219-440c2336c88c5d0e
Really fix short-read support in tuned_gzip. The python zlib module behaved differently than thought.

Show diffs side-by-side

added added

removed removed

Lines of Context:
94
94
        if buf == "":
95
95
            self._add_read_data(self.decompress.flush())
96
96
            assert len(self.decompress.unused_data) >= 8, "what does flush do?"
 
97
            self._gzip_tail = self.decompress.unused_data[0:8]
97
98
            self._read_eof()
98
99
            # tell the driving read() call we have stuffed all the data
99
100
            # in self.extrabuf
115
116
            if seek_length > 0:
116
117
                # we read too much data
117
118
                self.fileobj.seek(-seek_length, 1)
 
119
                self._gzip_tail = self.decompress.unused_data[0:8]
118
120
            elif seek_length < 0:
119
121
                # we haven't read enough to check the checksum.
120
122
                assert -8 < seek_length, "too great a seek."
121
123
                buf = self.fileobj.read(-seek_length)
122
 
                self.decompress.decompress(buf)
 
124
                self._gzip_tail = self.decompress.unused_data + buf
 
125
            else:
 
126
                self._gzip_tail = self.decompress.unused_data
123
127
 
124
128
            # Check the CRC and file size, and set the flag so we read
125
129
            # a new member on the next call
140
144
        # We then check the that the computed CRC and size of the
141
145
        # uncompressed data matches the stored values.  Note that the size
142
146
        # stored is the true file size mod 2**32.
143
 
        crc32, isize = struct.unpack("<LL", self.decompress.unused_data[0:8])
 
147
        assert len(self._gzip_tail) == 8, "gzip trailer is incorrect length."
 
148
        crc32, isize = struct.unpack("<LL", self._gzip_tail)
144
149
        # note that isize is unsigned - it can exceed 2GB
145
150
        if crc32 != U32(self.crc):
146
151
            raise IOError, "CRC check failed %d %d" % (crc32, U32(self.crc))