Ejemplo n.º 1
0
def test_auto_decompress():
    n = 10000
    stream = repeat(b'hello', n)
    stream = auto_decompress_stream(bz2_compress_stream(stream))
    assert b''.join(stream) == b'hello' * n

    n = 10000
    stream = repeat(b'hello', n)
    stream = auto_decompress_stream(stream)
    assert b''.join(stream) == b'hello' * n
Ejemplo n.º 2
0
def test_auto_decompress():
    n = 10000
    stream = repeat(b'hello', n)
    stream = auto_decompress_stream(bz2_compress_stream(stream))
    assert b''.join(stream) == b'hello' * n

    n = 10000
    stream = repeat(b'hello', n)
    stream = auto_decompress_stream(stream)
    assert b''.join(stream) == b'hello' * n
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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