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

  • Committer: Robert Collins
  • Date: 2010-05-05 00:05:29 UTC
  • mto: This revision was merged to the branch mainline in revision 5206.
  • Revision ID: robertc@robertcollins.net-20100505000529-ltmllyms5watqj5u
Make 'pydoc bzrlib.tests.build_tree_shape' useful.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""ChunkWriter: write compressed data out with a fixed upper bound."""
19
19
 
20
 
from __future__ import absolute_import
21
 
 
22
20
import zlib
23
21
from zlib import Z_FINISH, Z_SYNC_FLUSH
24
22
 
101
99
        :param chunk_size: The total byte count to emit at the end of the
102
100
            chunk.
103
101
        :param reserved: How many bytes to allow for reserved data. reserved
104
 
            data space can only be written to via the write(...,
105
 
            reserved=True).
 
102
            data space can only be written to via the write(..., reserved=True).
106
103
        """
107
104
        self.chunk_size = chunk_size
108
105
        self.compressor = zlib.compressobj()
125
122
        bytes that did not fit in the chunk.
126
123
 
127
124
        :return: (compressed_bytes, unused_bytes, num_nulls_needed)
128
 
 
129
 
            * compressed_bytes: a list of bytes that were output from the
130
 
              compressor. If the compressed length was not exactly chunk_size,
131
 
              the final string will be a string of all null bytes to pad this
132
 
              to chunk_size
133
 
            * unused_bytes: None, or the last bytes that were added, which we
134
 
              could not fit.
135
 
            * num_nulls_needed: How many nulls are padded at the end
 
125
            compressed_bytes    a list of bytes that were output from the
 
126
                                compressor. If the compressed length was not
 
127
                                exactly chunk_size, the final string will be a
 
128
                                string of all null bytes to pad this to
 
129
                                chunk_size
 
130
            unused_bytes        None, or the last bytes that were added, which
 
131
                                we could not fit.
 
132
            num_nulls_needed    How many nulls are padded at the end
136
133
        """
137
 
        self.bytes_in = None  # Free the data cached so far, we don't need it
 
134
        self.bytes_in = None # Free the data cached so far, we don't need it
138
135
        out = self.compressor.flush(Z_FINISH)
139
136
        self.bytes_list.append(out)
140
137
        self.bytes_out_len += len(out)
145
142
                                 % (self.bytes_out_len, self.chunk_size))
146
143
        nulls_needed = self.chunk_size - self.bytes_out_len
147
144
        if nulls_needed:
148
 
            self.bytes_list.append(b"\x00" * nulls_needed)
 
145
            self.bytes_list.append("\x00" * nulls_needed)
149
146
        return self.bytes_list, self.unused_bytes, nulls_needed
150
147
 
151
148
    def set_optimize(self, for_size=True):
167
164
        :param extra_bytes: Optional, if supplied we will add it with
168
165
            Z_SYNC_FLUSH
169
166
        :return: (bytes_out, bytes_out_len, alt_compressed)
170
 
 
171
 
            * bytes_out: is the compressed bytes returned from the compressor
172
 
            * bytes_out_len: the length of the compressed output
173
 
            * compressor: An object with everything packed in so far, and
174
 
              Z_SYNC_FLUSH called.
 
167
            bytes_out   is the compressed bytes returned from the compressor
 
168
            bytes_out_len the length of the compressed output
 
169
            compressor  An object with everything packed in so far, and
 
170
                        Z_SYNC_FLUSH called.
175
171
        """
176
172
        compressor = zlib.compressobj()
177
173
        bytes_out = []
276
272
                    self.bytes_list = bytes_out
277
273
                    self.bytes_out_len = this_len
278
274
        return False
 
275