o
    `"                     @   sT   d dl mZmZmZmZ d dl mZmZmZmZ dZ	G dd dZ
G dd dZdS )	   )_create_context	_compress_decompress
_get_block)LZ4StreamError_compress_bound_input_boundLZ4_MAX_INPUT_SIZEz/A Python wrapper for the LZ4 stream protocol.

c                   @   s:   e Zd ZdZdddZdd Zd	d
 Zdd Zdd ZdS )LZ4StreamDecompressorz( LZ4 stream decompression context.

    F    c                 C   s&   |rdnd}t |d||||d| _dS )a   Instantiates and initializes a LZ4 stream decompression context.

            Args:
                strategy (str): Buffer management strategy. Can be: ``double_buffer``.
                buffer_size (int): Size of one buffer of the double-buffer used
                    internally for stream decompression in the case of ``double_buffer``
                    strategy.

            Keyword Args:
                return_bytearray (bool): If ``False`` (the default) then the function
                    will return a ``bytes`` object. If ``True``, then the function will
                    return a ``bytearray`` object.
                store_comp_size (int): Specify the size in bytes of the following
                    compressed block. Can be: ``0`` (meaning out-of-band block size),
                    ``1``, ``2`` or ``4`` (default: ``4``).
                dictionary (str, bytes or buffer-compatible object): If specified,
                    perform decompression using this initial dictionary.

            Raises:
                Exceptions occuring during the context initialization.

                OverflowError: raised if the ``dictionary`` parameter is too large
                    for the LZ4 context.
                ValueError: raised if some parameters are invalid.
                MemoryError: raised if some internal resources cannot be allocated.
                RuntimeError: raised if some internal resources cannot be initialized.

        r       
decompress)return_bytearraystore_comp_size
dictionaryNr   _context)selfstrategybuffer_sizer   r   r    r   5/usr/lib/python3/dist-packages/lz4/stream/__init__.py__init__   s   zLZ4StreamDecompressor.__init__c                 C      | S z( Enter the LZ4 stream context.

        r   r   r   r   r   	__enter__3      zLZ4StreamDecompressor.__enter__c                 C      dS z' Exit the LZ4 stream context.

        Nr   r   exc_typeexcexc_tbr   r   r   __exit__9   r   zLZ4StreamDecompressor.__exit__c                 C      t | j|S )a   Decompress streamed compressed data.

            Decompress the given ``chunk``, using the given LZ4 stream context,
            Raises an exception if any error occurs.

            Args:
                chunk (str, bytes or buffer-compatible object): Data to decompress

            Returns:
                bytes or bytearray: Decompressed data.

            Raises:
                Exceptions occuring during decompression.

                ValueError: raised if the source is inconsistent with a finite LZ4
                    stream block chain.
                MemoryError: raised if the work output buffer cannot be allocated.
                OverflowError: raised if the source is too large for being decompressed
                    in the given context.
                LZ4StreamError: raised if the call to the LZ4 library fails. This can be
                    caused by ``decompressed_size`` being too small, or invalid data.

        )r   r   r   chunkr   r   r   r   ?   s   z LZ4StreamDecompressor.decompressc                 C   r&   )a}   Return the first LZ4 compressed block from ``stream``.

            Args:
                stream (str, bytes or buffer-compatible object): LZ4 compressed stream.

            Returns:
                bytes or bytearray: LZ4 compressed data block.

            Raises:
                Exceptions occuring while getting the first block from ``stream``.

                BufferError: raised if the function cannot return a complete LZ4
                    compressed block from the stream (i.e. the stream does not hold
                    a complete block).
                MemoryError: raised if the output buffer cannot be allocated.
                OverflowError: raised if the source is too large for being handled by
                    the given context.
                LZ4StreamError: raised if used while in an out-of-band block size record
                    configuration.

        )r   r   )r   streamr   r   r   	get_blockY   s   zLZ4StreamDecompressor.get_blockN)Fr   r   )	__name__
__module____qualname____doc__r   r   r%   r   r*   r   r   r   r   r
      s    
$r
   c                   @   s6   e Zd ZdZ		ddd	Zd
d Zdd Zdd ZdS )LZ4StreamCompressorz& LZ4 stream compressing context.

    defaultT	   Fr   r   c	           	      C   s,   |rdnd}t |d|||||||d	| _dS )a	   Instantiates and initializes a LZ4 stream compression context.

            Args:
                strategy (str): Buffer management strategy. Can be: ``double_buffer``.
                buffer_size (int): Base size of the buffer(s) used internally for stream
                    compression/decompression. In the ``double_buffer`` strategy case,
                    this is the size of each buffer of the double-buffer.

            Keyword Args:
                mode (str): If ``default`` or unspecified use the default LZ4
                    compression mode. Set to ``fast`` to use the fast compression
                    LZ4 mode at the expense of compression. Set to
                    ``high_compression`` to use the LZ4 high-compression mode at
                    the expense of speed.
                acceleration (int): When mode is set to ``fast`` this argument
                    specifies the acceleration. The larger the acceleration, the
                    faster the but the lower the compression. The default
                    compression corresponds to a value of ``1``.
                compression_level (int): When mode is set to ``high_compression`` this
                    argument specifies the compression. Valid values are between
                    ``1`` and ``12``. Values between ``4-9`` are recommended, and
                    ``9`` is the default. Only relevant if ``mode`` is
                    ``high_compression``.
                return_bytearray (bool): If ``False`` (the default) then the function
                    will return a bytes object. If ``True``, then the function will
                    return a bytearray object.
                store_comp_size (int): Specify the size in bytes of the following
                    compressed block. Can be: ``0`` (meaning out-of-band block size),
                    ``1``, ``2`` or ``4`` (default: ``4``).
                dictionary (str, bytes or buffer-compatible object): If specified,
                    perform compression using this initial dictionary.

            Raises:
                Exceptions occuring during the context initialization.

                OverflowError: raised if the ``dictionary`` parameter is too large
                    for the LZ4 context.
                ValueError: raised if some parameters are invalid.
                MemoryError: raised if some internal resources cannot be allocated.
                RuntimeError: raised if some internal resources cannot be initialized.

        r   r   compress)modeaccelerationcompression_levelr   r   r   Nr   )	r   r   r   r3   r4   r5   r   r   r   r   r   r   r   v   s   ,zLZ4StreamCompressor.__init__c                 C   r   r   r   r   r   r   r   r      r   zLZ4StreamCompressor.__enter__c                 C   r   r    r   r!   r   r   r   r%      r   zLZ4StreamCompressor.__exit__c                 C   r&   )a   Stream compress given ``chunk`` of data.

            Compress the given ``chunk``, using the given LZ4 stream context,
            returning the compressed data as a ``bytearray`` or as a ``bytes`` object.

            Args:
                chunk (str, bytes or buffer-compatible object): Data to compress

            Returns:
                bytes or bytearray: Compressed data.

            Raises:
                Exceptions occuring during compression.

                OverflowError: raised if the source is too large for being compressed in
                    the given context.
                LZ4StreamError: raised if the call to the LZ4 library fails.

        )r   r   r'   r   r   r   r2      s   zLZ4StreamCompressor.compressN)r0   Tr1   Fr   r   )r+   r,   r-   r.   r   r   r%   r2   r   r   r   r   r/   r   s    
6r/   N)_streamr   r   r   r   r   r   r   r	   r.   r
   r/   r   r   r   r   <module>   s
    g