Ë
    Í—Äjh  ã                   ó¦   — d Z ddlmZmZ ddœdededefd„Zd	d
œdedeeef   deddfd„Zdd	dœdede	dededef
d„Z
dd	dœdede	de	dededefd„Zy)zûShared binary I/O helpers for format parsers.

Variants are kept separate (rather than collapsed into one helper) because
each caller depends on slightly different semantics; stream vs random
access, raw bytes vs decoded str, simple vs chunked reads.
é    )ÚBinaryIOÚUnionF)ÚchunkedÚfiler   Úreturnc                ó–  — |r‡g }	 | j                  d«      }|sn_|j                  d«      }|dk7  r7|j                  |d| «       | j                  t	        |«      |z
  dz
   d«       n|j                  |«       Œsdj                  |«      S t        «       }	 | j                  d«      }|r|dk(  r	 t        |«      S |j                  |«       Œ6)aÉ  Read a null-terminated string from a binary file.

    Returns the bytes between the cursor and the next null (excluding the
    null itself). Caller is responsible for decoding and any filtering.

    Args:
        file: Open binary file positioned at the string start.
        chunked: If True, read in 256-byte chunks and seek back past the
        null. Faster for long strings; equivalent to char-by-char for
        short ones. Defaults to False.
    é   ó    éÿÿÿÿNé   ó    )	ÚreadÚfindÚappendÚseekÚlenÚjoinÚ	bytearrayÚextendÚbytes)r   r   ÚchunksÚchunkÚnull_posÚcharsÚchars          úVC:\Users\pivot\Documents\cueki\casual-preloader\Lib\site-packages\valve_parsers/_io.pyÚread_cstring_streamr   
   sÎ   € ñ ØˆØØ—I‘I˜c“NˆEÙØØ—z‘z 'Ó*ˆHØ˜2Š~Ø—‘˜e I XÐ.Ô/Ø—	‘	œC ›J¨Ñ1°AÑ5Ð6¸Ô:ØØ�M‰M˜%Ô ð ð �x‰x˜ÓÐä‹K€EØ
Ø�y‰y˜‹|ˆÙ�t˜w’Øä�‹<Ðð 	�‰�TÔð	 r   Úreplace©ÚerrorsÚstringr    Nc                ór   — t        |t        «      r|j                  d|¬«      }| j                  |dz   «       y)ay  Write a null-terminated string to a binary file.

    Args:
        file: Open binary file.
        string: str (ASCII-encoded with the given errors policy) or bytes
            (written as-is).
        errors: Encode error policy when `string` is a str. Defaults to
            "replace" to match the library's forgiving stance on corrupt
            or non-ASCII inputs.
    Úasciir   r
   N)Ú
isinstanceÚstrÚencodeÚwrite)r   r!   r    s      r   Úwrite_cstringr(   -   s1   € ô �&œ#ÔØ—‘˜w¨v�Ó6ˆØ‡J�Jˆv˜ÑÕ r   r#   )Úencodingr    ÚbufÚoffsetr)   c                ór   — | j                  d|«      }|dk  rt        | «      }| || j                  ||¬«      S )aW  Read a null-terminated string from a bytes buffer at a fixed offset.

    Searches forward for the null and decodes everything up to it.

    Args:
        buf: Source buffer.
        offset: Byte offset to start reading from.
        encoding: Text encoding. Defaults to ASCII.
        errors: Decode error policy. Defaults to "replace".
    r
   r   r   )r   r   Údecode)r*   r+   r)   r    Úends        r   Úread_cstring_atr/   ?   s@   € ð" �(‰(�7˜FÓ
#€CØ
ˆQ‚wÜ�#‹hˆØˆv�cˆ?×!Ñ! (°6Ð!Ó:Ð:r   Úlengthc                ón   — | |||z    }|j                  d«      }|dk\  r|d| }|j                  ||¬«      S )aÂ  Read a fixed-width null-padded string from a bytes buffer.

    Reads exactly `length` bytes from `offset`, truncates at the first null,
    and decodes. Used for fixed-width name fields in binary headers.

    Args:
        buf: Source buffer.
        offset: Byte offset to start reading from.
        length: Field width in bytes.
        encoding: Text encoding. Defaults to ASCII.
        errors: Decode error policy. Defaults to "replace".
    r
   r   Nr   )r   r-   )r*   r+   r0   r)   r    r   r.   s          r   Úread_fixed_stringr2   V   sG   € ð( ��v ‘Ð'€EØ
�*‰*�WÓ
€CØ
ˆa‚xØ�d�s�ˆØ�<‰<˜¨ˆ<Ó0Ð0r   )Ú__doc__Útypingr   r   Úboolr   r   r%   r(   Úintr/   r2   © r   r   Ú<module>r8      så   ðñ÷ #ð <Aò  ˜hð  °Dð  ÀUó  ðH AJò!Ø
ð!Ø! # u *Ñ-ð!Ø:=ð!à	ó!ð, Øò;Ø	ð;àð;ð ð	;ð
 ð;ð 	ó;ð8 Øò1Ø	ð1àð1ð ð1ð
 ð1ð ð1ð 	ô1r   