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

  • Committer: John Arbash Meinel
  • Date: 2009-06-22 18:10:04 UTC
  • mto: This revision was merged to the branch mainline in revision 4471.
  • Revision ID: john@arbash-meinel.com-20090622181004-0rsmfqcnhk48fq88
Add a set_content_chunked member to GroupCompressBlock.

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
        self._z_content_length = None
109
109
        self._content_length = None
110
110
        self._content = None
 
111
        self._content_chunks = None
111
112
 
112
113
    def __len__(self):
113
114
        # This is the maximum number of bytes this object will reference if
137
138
                % (num_bytes, self._content_length))
138
139
        # Expand the content if required
139
140
        if self._content is None:
 
141
            if self._content_chunks is not None:
 
142
                self._content = ''.join(self._content_chunks)
 
143
                self._content_chunks = None
 
144
        if self._content is None:
140
145
            if self._z_content is None:
141
146
                raise AssertionError('No content to decompress')
142
147
            if self._z_content == '':
273
278
            bytes = apply_delta_to_source(self._content, content_start, end)
274
279
        return bytes
275
280
 
 
281
    def set_chunked_content(self, content_chunks):
 
282
        """Set the content of this block to the given chunks."""
 
283
        self._content_length = sum(map(len, content_chunks))
 
284
        self._content_chunks = content_chunks
 
285
        self._z_content = None
 
286
        self._content = None
 
287
 
276
288
    def set_content(self, content):
277
289
        """Set the content of this block."""
278
290
        self._content_length = len(content)
279
291
        self._content = content
280
292
        self._z_content = None
281
293
 
 
294
    def _create_z_content_using_lzma(self):
 
295
        if self._content_chunks is not None:
 
296
            self._content = ''.join(self._content_chunks)
 
297
            self._content_chunks = None
 
298
        if self._content is None:
 
299
            raise AssertionError('Nothing to compress')
 
300
        self._z_content = pylzma.compress(self._content)
 
301
        self._z_content_length = len(self._z_content)
 
302
 
 
303
    def _create_z_content_from_chunks(self):
 
304
        compressor = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION)
 
305
        compressed_chunks = []
 
306
        for chunk in self._content_chunks:
 
307
            z_bytes = compressor.compress(chunk)
 
308
            if z_bytes:
 
309
                compressed_chunks.append(z_bytes)
 
310
        compressed_chunks.append(compressor.flush())
 
311
        self._z_content = ''.join(compressed_chunks)
 
312
        self._z_content_length = len(self._z_content)
 
313
 
 
314
    def _create_z_content(self):
 
315
        if self._z_content is not None:
 
316
            return
 
317
        if _USE_LZMA:
 
318
            self._create_z_content_using_lzma()
 
319
            return
 
320
        if self._content_chunks is not None:
 
321
            self._create_z_content_from_chunks()
 
322
            return
 
323
        self._z_content = zlib.compress(self._content)
 
324
        self._z_content_length = len(self._z_content)
 
325
 
282
326
    def to_bytes(self):
283
327
        """Encode the information into a byte stream."""
284
 
        compress = zlib.compress
285
 
        if _USE_LZMA:
286
 
            compress = pylzma.compress
287
 
        if self._z_content is None:
288
 
            if self._content is None:
289
 
                raise AssertionError('Nothing to compress')
290
 
            self._z_content = compress(self._content)
291
 
            self._z_content_length = len(self._z_content)
 
328
        self._create_z_content()
292
329
        if _USE_LZMA:
293
330
            header = self.GCB_LZ_HEADER
294
331
        else: