def extract_entry(self, e, decompress='auto'): """Yield blocks of data for this entry from this MAR file. Args: e (:obj:`mardor.format.index_entry`): An index_entry object that refers to this file's size and offset inside the MAR file. path (str): Where on disk to extract this file to. decompress (str, optional): Controls whether files are decompressed when extracted. Must be one of None, 'auto', 'bz2', or 'xz'. Defaults to 'auto' Yields: Blocks of data for `e` """ self.fileobj.seek(e.offset) stream = file_iter(self.fileobj) stream = takeexactly(stream, e.size) if decompress == 'auto': stream = auto_decompress_stream(stream) elif decompress == 'bz2': stream = bz2_decompress_stream(stream) elif decompress == 'xz': stream = xz_decompress_stream(stream) elif decompress is None: pass else: raise ValueError("Unsupported decompression type: {}".format(decompress)) for block in stream: yield block
def test_bz2_stream_large(): # This is only to test the case where the compressor returns data before # the stream ends n = 70000 stream = repeat(b'hello', n) stream = bz2_decompress_stream(bz2_compress_stream(stream, level=1)) assert b''.join(stream) == b'hello' * n
def test_bz2_stream_exact_blocksize(): stream = [b'0' * 100000] stream = bz2_decompress_stream(bz2_compress_stream(stream, level=1)) assert b''.join(stream) == b'0' * 100000
def test_bz2_streams(data, level): stream = bz2_decompress_stream(bz2_compress_stream(data, level)) assert b''.join(stream) == b''.join(data)