o
    áË·e9
  ã                   @   s   d dl Z G dd„ deƒZdS )é    Nc                   @   sB   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚCommonChecksuma  Hashlib-alike helper for CRC32C operations.

    This class should not be used directly and requires an update implementation.

    Args:
        initial_value (Optional[bytes]): the initial chunk of data from
            which the CRC32C checksum is computed.  Defaults to b''.
    ó    c                 C   s    d| _ |dkr|  |¡ d S d S )Nr   r   )Ú_crcÚupdate)ÚselfÚinitial_value© r   úN/var/www/ideatree/venv/lib/python3.10/site-packages/google_crc32c/_checksum.pyÚ__init__   s   ÿzCommonChecksum.__init__c                 C   s   t ƒ ‚)z®Update the checksum with a new chunk of data.

        Args:
            chunk (Optional[bytes]): a chunk of data used to extend
                the CRC32C checksum.
        )ÚNotImplemented)r   Údatar   r   r	   r   !   s   zCommonChecksum.updatec                 C   s   t  d| j¡S )z¹Big-endian order, per RFC 4960.

        See: https://cloud.google.com/storage/docs/json_api/v1/objects#crc32c

        Returns:
            bytes: An eight-byte digest string.
        z>L)ÚstructÚpackr   ©r   r   r   r	   Údigest*   s   zCommonChecksum.digestc                 C   s   d  | j¡ d¡S )zªLike :meth:`digest` except returns as a bytestring of double length.

        Returns
            bytes: A sixteen byte digest string, contaiing only hex digits.
        z{:08x}Úascii)Úformatr   Úencoder   r   r   r	   Ú	hexdigest4   s   zCommonChecksum.hexdigestc                 C   s   |   ¡ }| j|_|S )zvCreate another checksum with the same CRC32C value.

        Returns:
            Checksum: the new instance.
        )Ú	__class__r   )r   Úcloner   r   r	   Úcopy<   s   zCommonChecksum.copyc                 c   s(    	 |  |¡}|sdS |  |¡ |V  q)a;  Consume chunks from a stream, extending our CRC32 checksum.

        Args:
            stream (BinaryIO): the stream to consume.
            chunksize (int): the size of the read to perform

        Returns:
            Generator[bytes, None, None]: Iterable of the chunks read from the
            stream.
        TN)Úreadr   )r   ÚstreamÚ	chunksizeÚchunkr   r   r	   ÚconsumeF   s   €

ûzCommonChecksum.consumeN)r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r
   r   r   r   r   r   r   r   r   r	   r      s    
		

r   )r   Úobjectr   r   r   r   r	   Ú<module>   s   