
    5pj                        S r SSKJr  SSKrSSKrSSKrSSKJr  SSKJ	r	  SSK
JrJrJr  SSKJr  \\R"                  \   -  \-  r\	\   \R&                  -  r S\S	.       SS
 jjjrSS jrSS jrSS jr/ SQrg)zEFilesystem helpers used by the cache, download and upload subsystems.    )annotationsN)Path)IO   )DEFAULT_CACHE_DIR_NAMEDOWNLOAD_CHUNK_SIZE	ENV_CACHE)FileIntegrityError)
chunk_sizec                 ^^ TS:  a  [        ST 35      e[        U 5      nUR                  5       (       d  [        SU 35      e [        R
                  " U5      nUR                  S5       m[        UU4S jS5       H  nUR                  U5        M     SSS5        UR                  5       $ ! [         [        4 a  n[        SU< 35      UeSnAff = f! , (       d  f       UR                  5       $ = f)	av  Compute a hex digest of ``file_path`` using ``algorithm``.

Parameters
----------
file_path:
    Path of the file to hash.
algorithm:
    Any algorithm accepted by :func:`hashlib.new` (e.g. ``"sha256"``,
    ``"sha1"``, ``"md5"``).
chunk_size:
    Read buffer size in bytes.

Raises
------
FileIntegrityError
    If ``file_path`` is missing or the algorithm is unsupported.
   zchunk_size must be >= 1, got zCannot hash non-existent file: zUnsupported hash algorithm: Nrbc                 &   > TR                  T 5      $ )N)read)r   fhs   [/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/modelscope_hub/utils/file_utils.py<lambda>compute_hash.<locals>.<lambda>4   s    "''*"5    r   )
ValueErrorr   is_filer
   hashlibnew	TypeErroropeniterupdate	hexdigest)	file_path	algorithmr   pathhasherexcchunkr   s     `    @r   compute_hashr%      s    . A~8EFF	?D<<>> #B4&!IJJXY' 
4B5s;EMM%  < 
  	" X #?	}!MNTWWX 
 s$   B/ -*C/C?CC
C4c                v   [        U [        [        R                  [        45      (       a#  [	        U 5      R                  5       R                  $ U n UR                  5       n[        R                  " U5      R                  $ ! [        [        [        R                  4 a     Of = f[        US5      (       a  [        US5      (       d  [        S5      eUR                  5       n UR!                  S[        R"                  5        UR                  5       UR!                  U5        $ ! UR!                  U5        f = f)zHReturn the size in bytes of either a path or an open binary file object.seektellz9File-like object must support seek/tell to determine sizer   )
isinstancestrosPathLiker   statst_sizefilenofstatAttributeErrorOSErrorioUnsupportedOperationhasattrr   r(   r'   SEEK_END)path_or_fileobjfobjr/   currents       r   get_file_sizer:   9   s    /Cd#;<<O$))+333Dxx'''GR%<%<=  4  f(=(=STTiikG		!R[[!yy{		'		's   /B B#"B#$/D% %D8c                     [         R                  R                  [        5      n U (       a  [	        U 5      $ [	        [
        R                  " 5       S-  [        -  5      $ )z?Return the SDK cache directory, honouring ``MODELSCOPE_CACHE``.z.cache)r+   environgetr	   
ensure_dirr   homer   )overrides    r   get_cache_dirrA   Q   s>    zz~~i(H(##diikH,/EEFFr   c                X    [        U 5      R                  5       nUR                  SSS9  U$ )zHCreate ``path`` (and parents) if missing and return it as :class:`Path`.T)parentsexist_ok)r   
expandusermkdir)r!   ps     r   r>   r>   Y   s)    T
AGGD4G(Hr   )r%   r>   rA   r:   )sha256)r   r,   r    r*   r   intreturnr*   )r7   zPathLike | FileObjrJ   rI   )rJ   r   )r!   r,   rJ   r   )__doc__
__future__r   r   r3   r+   pathlibr   typingr   	constantsr   r   r	   errorsr
   r*   r,   bytesIOBaseFileObjr%   r:   rA   r>   __all__ r   r   <module>rV      s    K "  	 	   N N 'S!!D(
U)bii

 $ *	$$$ 	$
 	$N0Gr   