/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tuned_gzip.py

  • Committer: Aaron Bentley
  • Date: 2006-05-20 17:51:13 UTC
  • mfrom: (1718 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1727.
  • Revision ID: aaron.bentley@utoronto.ca-20060520175113-4549e0023f9210bf
Merge from bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import struct
25
25
import zlib
26
26
 
 
27
# we want a \n preserved, break on \n only splitlines.
 
28
import bzrlib
 
29
 
27
30
__all__ = ["GzipFile"]
28
31
 
29
32
 
91
94
        if buf == "":
92
95
            self._add_read_data(self.decompress.flush())
93
96
            assert len(self.decompress.unused_data) >= 8, "what does flush do?"
 
97
            self._gzip_tail = self.decompress.unused_data[0:8]
94
98
            self._read_eof()
95
99
            # tell the driving read() call we have stuffed all the data
96
100
            # in self.extrabuf
109
113
            # (The number of bytes to seek back is the length of the unused
110
114
            # data, minus 8 because those 8 bytes are part of this member.
111
115
            seek_length = len (self.decompress.unused_data) - 8
112
 
            if seek_length:
113
 
                assert seek_length > 0
 
116
            if seek_length > 0:
 
117
                # we read too much data
114
118
                self.fileobj.seek(-seek_length, 1)
 
119
                self._gzip_tail = self.decompress.unused_data[0:8]
 
120
            elif seek_length < 0:
 
121
                # we haven't read enough to check the checksum.
 
122
                assert -8 < seek_length, "too great a seek."
 
123
                buf = self.fileobj.read(-seek_length)
 
124
                self._gzip_tail = self.decompress.unused_data + buf
 
125
            else:
 
126
                self._gzip_tail = self.decompress.unused_data
115
127
 
116
128
            # Check the CRC and file size, and set the flag so we read
117
129
            # a new member on the next call
132
144
        # We then check the that the computed CRC and size of the
133
145
        # uncompressed data matches the stored values.  Note that the size
134
146
        # stored is the true file size mod 2**32.
135
 
        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)
136
149
        # note that isize is unsigned - it can exceed 2GB
137
150
        if crc32 != U32(self.crc):
138
 
            raise IOError, "CRC check failed"
 
151
            raise IOError, "CRC check failed %d %d" % (crc32, U32(self.crc))
139
152
        elif isize != LOWU32(self.size):
140
153
            raise IOError, "Incorrect length of data produced"
141
154
 
245
258
        if sizehint <= 0:
246
259
            sizehint = -1
247
260
        content = self.read(sizehint)
248
 
        return content.splitlines(True)
 
261
        return bzrlib.osutils.split_lines(content)
249
262
 
250
263
    def _unread(self, buf, len_buf=None):
251
264
        """tuned to remove unneeded len calls.