
    ݑfW                     z    d dl Z d dlZ ee dd       Z ee dd      Z ee dd      Z G d de j                        Zy)	    NSEEK_SETSEEK_CUR   SEEK_END   c                   T     e Zd ZdZd fd	Zef fd	Z fdZd	 fd	Zd Z	d Z
 xZS )
FileChunkIOzA
    A class that allows you reading only a chunk of a file.
    c                    |j                  d      st        d      || _        || _        |1t	        j
                  |      j                  | j                  z
  | _        t        t        | &  |||g|i | | j                  d       y)a/  
        Open a file chunk. The mode can only be 'r' for reading. Offset
        is the amount of bytes that the chunks starts after the real file's
        first byte. Bytes defines the amount of bytes the chunk has, which you
        can set to None to include the last byte of the real file.
        rzMode string must begin with 'r'Nr   )
startswith
ValueErroroffsetbytesosstatst_sizesuperr	   __init__seek)	selfnamemodeclosefdr   r   argskwargs	__class__s	           7lib/python3.12/site-packages/filechunkio/filechunkio.pyr   zFileChunkIO.__init__   sv     s#>??
=..<DJk4)$gOOO		!    c                    |t         k(  r!t        t        |   | j                  |z          y|t
        k(  r#| j                  | j                         |z          y|t        k(  r| j                  | j                  |z          yy)z/
        Move to a new chunk position.
        N)	r   r   r	   r   r   r   tellr   r   )r   r   whencer   s      r   r   zFileChunkIO.seek   sf     X+t)$++*>?xIIdiikF*+xIIdjj6)*  r   c                 B    t         t        |          | j                  z
  S )z(
        Current file position.
        )r   r	   r    r   )r   r   s    r   r    zFileChunkIO.tell*   s     [$,.<<r   c                     |dk\  r=| j                   | j                         z
  }t        ||g      }t        t        |   |      S | j                         S )z2
        Read and return at most n bytes.
        r   )r   r    minr   r	   readreadall)r   nmax_nr   s      r   r%   zFileChunkIO.read0   sK     6JJ,EQJAd033<<>!r   c                 Z    | j                  | j                  | j                         z
        S )z/
        Read all data from the chunk.
        )r%   r   r    )r   s    r   r&   zFileChunkIO.readall;   s"     yydiik122r   c                     | j                  t        |            }t        |      }	 ||d| |S # t        $ r<}ddl}t	        ||j                        s||j                  d|      |d| Y d}~|S d}~ww xY w)z/
        Same as RawIOBase.readinto().
        Nr      b)r%   len	TypeErrorarray
isinstance)r   bdatar'   errr.   s         r   readintozFileChunkIO.readintoA   sy     yyQ I	,AbqE   	,a-	KKd+AbqE	,s   . 	A31A..A3)r   Tr   N))__name__
__module____qualname____doc__r   r   r   r    r%   r&   r3   __classcell__)r   s   @r   r	   r	   
   s+    " #+ 	+=	"3r   r	   )ior   getattrr   r   r   FileIOr	    r   r   <module>r>      sI    	 	 2z1%2z1%2z1%D")) Dr   