/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 groupcompress.py

  • Committer: John Arbash Meinel
  • Date: 2009-03-04 21:22:50 UTC
  • mto: (0.17.34 trunk)
  • mto: This revision was merged to the branch mainline in revision 4280.
  • Revision ID: john@arbash-meinel.com-20090304212250-xcvwt1yx4zt76pev
Have the GroupCompressBlock decide how to compress the header and content.
It can now decide whether they should be compressed together or not.
As long as we make the to_bytes() function match the from_bytes() one, we should be fine.

Show diffs side-by-side

added added

removed removed

Lines of Context:
169
169
        pos2 = pos + z_header_length
170
170
        z_header_bytes = bytes[pos:pos2]
171
171
        assert len(z_header_bytes) == z_header_length
172
 
        header_bytes = zlib.decompress(z_header_bytes)
 
172
        d = zlib.decompressobj()
 
173
        header_bytes = d.decompress(z_header_bytes)
173
174
        assert len(header_bytes) == header_length
174
175
        del z_header_bytes
175
176
        lines = header_bytes.split('\n')
193
194
            info_dict[key] = value
194
195
        zcontent = bytes[pos2:]
195
196
        if zcontent:
196
 
            out._content = zlib.decompress(zcontent)
 
197
            out._content = d.decompress(zcontent)
 
198
            assert d.flush() == ''
197
199
            out._size = header_len + len(out._content)
198
200
        return out
199
201
 
228
230
        self._entries[key] = entry
229
231
        return entry
230
232
 
231
 
    def to_bytes(self):
 
233
    def to_bytes(self, content=''):
232
234
        """Encode the information into a byte stream."""
233
235
        chunks = []
234
236
        for key in sorted(self._entries):
248
250
            chunks.append(chunk)
249
251
        bytes = ''.join(chunks)
250
252
        info_len = len(bytes)
251
 
        z_bytes = zlib.compress(bytes)
 
253
        c = zlib.compressobj()
 
254
        z_bytes = []
 
255
        z_bytes.append(c.compress(bytes))
252
256
        del bytes
253
 
        z_len = len(z_bytes)
254
 
        chunks = [self.GCB_HEADER, '%d\n' % (z_len,), '%d\n' % (info_len,),
255
 
                  z_bytes]
 
257
        z_bytes.append(c.flush(zlib.Z_SYNC_FLUSH))
 
258
        z_len = sum(map(len, z_bytes))
 
259
        c_len = len(content)
 
260
        z_bytes.append(c.compress(content))
 
261
        z_bytes.append(c.flush())
 
262
        chunks = [self.GCB_HEADER,
 
263
                  '%d\n' % (z_len,),
 
264
                  '%d\n' % (info_len,),
 
265
                  #'%d\n' % (c_len,),
 
266
                 ]
 
267
        chunks.extend(z_bytes)
256
268
        return ''.join(chunks)
257
269
 
258
270
 
725
737
            #       label in the header is duplicated in the text.
726
738
            #       For chk pages and real bytes, I would guess this is not
727
739
            #       true.
728
 
            header = self._compressor._block.to_bytes()
729
 
            compressed = zlib.compress(''.join(self._compressor.lines))
730
 
            out = header + compressed
 
740
            bytes = self._compressor._block.to_bytes(
 
741
                ''.join(self._compressor.lines))
731
742
            index, start, length = self._access.add_raw_records(
732
 
                [(None, len(out))], out)[0]
 
743
                [(None, len(bytes))], bytes)[0]
733
744
            nodes = []
734
745
            for key, reads, refs in keys_to_add:
735
746
                nodes.append((key, "%d %d %s" % (start, length, reads), refs))