Example #1
0
    def extract_iter(self, offset):
        '''Extracts the tar item starting at offset and returns an iterable'''
        if not 'r' == self.mode:
            raise ValueError, 'Cannot extract in append mode'
        assert offset % BLOCKSIZE == 0, 'Bad offset (%d)' % offset

        info = _pylibtar.pytar_info(self.tar, offset)
        if info['size'] <= self.CHUNKSIZE:
            yield _pylibtar.pytar_extract_tobuf(self.tar, offset)
        else:
            import tempfile
            tempfd, tempfn = tempfile.mkstemp()
            _pylibtar.pytar_extract(self.tar, offset, tempfd)
            os.close(tempfd)
            fh = open(tempfn, 'rb')
            os.unlink(tempfn)
            while 1:
                chunk = fh.read(self.CHUNKSIZE)
                if not chunk: break
                yield chunk
Example #2
0
 def info(self, offset):
     '''Returns tarinfo starting at offset'''
     if not 'r' == self.mode:
         raise ValueError, 'Cannot extract in append mode'
     assert offset % BLOCKSIZE == 0, 'Bad offset (%d)' % offset
     return _pylibtar.pytar_info(self.tar, offset)