~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bundle/serializer/v4.py

  • Committer: John Arbash Meinel
  • Date: 2007-12-05 22:52:58 UTC
  • mfrom: (3080 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3084.
  • Revision ID: john@arbash-meinel.com-20071205225258-kn799zf3tewncv7p
[merge] bzr.dev 3080

Show diffs side-by-side

added added

removed removed

Lines of Context:
160
160
            source_file = iterablefile.IterableFile(self.iter_decode(fileobj))
161
161
        else:
162
162
            source_file = StringIO(bz2.decompress(fileobj.read()))
163
 
        self._container = pack.ContainerReader(source_file)
 
163
        self._container_file = source_file
164
164
 
165
165
    @staticmethod
166
166
    def iter_decode(fileobj):
167
167
        """Iterate through decoded fragments of the file"""
168
168
        decompressor = bz2.BZ2Decompressor()
169
169
        for line in fileobj:
170
 
            yield decompressor.decompress(line)
 
170
            try:
 
171
                yield decompressor.decompress(line)
 
172
            except EOFError:
 
173
                return
171
174
 
172
175
    @staticmethod
173
176
    def decode_name(name):
199
202
        :return: a generator of (bytes, metadata, content_kind, revision_id,
200
203
            file_id)
201
204
        """
202
 
        iterator = self._container.iter_records()
203
 
        for names, meta_bytes in iterator:
 
205
        iterator = pack.iter_records_from_file(self._container_file)
 
206
        for names, bytes in iterator:
204
207
            if len(names) != 1:
205
208
                raise errors.BadBundle('Record has %d names instead of 1'
206
209
                                       % len(names))
207
 
            metadata = bencode.bdecode(meta_bytes(None))
 
210
            metadata = bencode.bdecode(bytes)
208
211
            if metadata['storage_kind'] == 'header':
209
212
                bytes = None
210
213
            else:
211
214
                _unused, bytes = iterator.next()
212
 
                bytes = bytes(None)
213
215
            yield (bytes, metadata) + self.decode_name(names[0][0])
214
216
 
215
217