
    gV                     T    d Z ddlmZmZ ddlmZmZ ddedee   defd	Z	d
ede
fdZy)zFUtilities to efficiently compute the SHA 256 hash of a bunch of bytes.    )BinaryIOOptional   )sha1sha256Nfileobj
chunk_sizereturnc                     ||nd}t               }	 | j                  |      }|j                  |       |s	 |j                         S 6)a  
    Computes the sha256 hash of the given file object, by chunks of size `chunk_size`.

    Args:
        fileobj (file-like object):
            The File object to compute sha256 for, typically obtained with `open(path, "rb")`
        chunk_size (`int`, *optional*):
            The number of bytes to read from `fileobj` at once, defaults to 1MB.

    Returns:
        `bytes`: `fileobj`'s sha256 hash as bytes
    i   )r   readupdatedigest)r   r	   shachunks       N/var/www/openai/venv/lib/python3.12/site-packages/huggingface_hub/utils/sha.pysha_fileobjr      sK      *5;J
(C
Z(

5::<     datac                     t               }|j                  d       |j                  t        t        |             j	                                |j                  d       |j                  |        |j                         S )aT  
    Computes the git-sha1 hash of the given bytes, using the same algorithm as git.

    This is equivalent to running `git hash-object`. See https://git-scm.com/docs/git-hash-object
    for more details.

    Note: this method is valid for regular files. For LFS files, the proper git hash is supposed to be computed on the
          pointer file content, not the actual file content. However, for simplicity, we directly compare the sha256 of
          the LFS file content when we want to compare LFS files.

    Args:
        data (`bytes`):
            The data to compute the git-hash for.

    Returns:
        `str`: the git-hash of `data` as an hexadecimal string.

    Example:
    ```python
    >>> from huggingface_hub.utils.sha import git_hash
    >>> git_hash(b"Hello, World!")
    'b45ef6fec89518d314f546fd6c3025367b721684'
    ```
    s   blob     )r   r   strlenencode	hexdigest)r   r   s     r   git_hashr       sX    6 &CJJxJJs3t9~$$&'JJuJJt==?r   )N)__doc__typingr   r   insecure_hashlibr   r   intbytesr   r   r    r   r   <module>r"      s?    L % * x}  0 5  S  r   