File: //opt/gsutil/third_party/apitools/apitools/base/py/__pycache__/compression.cpython-39.pyc
a
�z�g � @ s@ d Z ddlmZ ddlmZ dgZddd�ZG d d
� d
e�ZdS )z!Compression support for apitools.� )�deque)�gzip�CompressStreamN� � c
C s� d}d}t � }tjd||d��R}|r.|j|k rb| �|�}t|�} |�|� || 7 }| |k r d}qbq W d � n1 sv0 Y |||fS )a� Compresses an input stream into a file-like buffer.
This reads from the input stream until either we've stored at least length
compressed bytes, or the input stream has been exhausted.
This supports streams of unknown size.
Args:
in_stream: The input stream to read from.
length: The target number of compressed bytes to buffer in the output
stream. If length is none, the input stream will be compressed
until it's exhausted.
The actual length of the output buffer can vary from the target.
If the input stream is exhaused, the output buffer may be smaller
than expected. If the data is incompressible, the maximum length
can be exceeded by can be calculated to be:
chunksize + 5 * (floor((chunksize - 1) / 16383) + 1) + 17
This accounts for additional header data gzip adds. For the default
16MiB chunksize, this results in the max size of the output buffer
being:
length + 16Mib + 5142 bytes
compresslevel: Optional, defaults to 2. The desired compression level.
chunksize: Optional, defaults to 16MiB. The chunk size used when
reading data from the input stream to write into the output
buffer.
Returns:
A file-like output buffer of compressed bytes, the number of bytes read
from the input stream, and a flag denoting if the input stream was
exhausted.
r F�wb)�mode�fileobj�
compresslevelTN)�StreamingBufferr �GzipFile�length�read�len�write)
Z in_streamr
r
� chunksizeZin_readZin_exhaustedZ
out_streamZcompress_stream�data�data_length� r �@/opt/gsutil/third_party/apitools/apitools/base/py/compression.pyr s"