+
    ~jf                     H    R t ^ RIt^ RIt^ RIHt ^ RIHt  ! R R]4      tR# )zGit LFS related utilitiesN)AbstractContextManager)BinaryIOc                      a  ] tR t^t o RtV 3R lR ltR tR tRV 3R lR lltV 3R lR	 lt	]
P                  3V 3R
 lR lltR tRtV tR# )SliceFileObja!  
Utility context manager to read a *slice* of a seekable file-like object as a seekable, file-like object.

This is NOT thread safe

Inspired by stackoverflow.com/a/29838711/593036

Credits to @julien-c

Args:
    fileobj (`BinaryIO`):
        A file-like object to slice. MUST implement `tell()` and `seek()` (and `read()` of course).
        `fileobj` will be reset to its original position when exiting the context manager.
    seek_from (`int`):
        The start of the slice (offset from position 0 in bytes).
    read_limit (`int`):
        The maximum number of bytes to read from the slice.

Attributes:
    previous_position (`int`):
        The previous position

Examples:

Reading 200 bytes with an offset of 128 bytes from a file (ie bytes 128 to 327):
```python
>>> with open("path/to/file", "rb") as file:
...     with SliceFileObj(file, seek_from=128, read_limit=200) as fslice:
...         fslice.read(...)
```

Reading a file in chunks of 512 bytes
```python
>>> import os
>>> chunk_size = 512
>>> file_size = os.getsize("path/to/file")
>>> with open("path/to/file", "rb") as file:
...     for chunk_idx in range(ceil(file_size / chunk_size)):
...         with SliceFileObj(file, seek_from=chunk_idx * chunk_size, read_limit=chunk_size) as fslice:
...             chunk = fslice.read(...)

```
c                ,   < V ^8  d   QhRS[ RS[RS[/# )   fileobj	seek_from
read_limit)r   int)format__classdict__s   "o/Users/mitch_tango/dev/rabbit-r1-livekit/agent/.venv/lib/python3.14/site-packages/huggingface_hub/utils/_lfs.py__annotate__SliceFileObj.__annotate__C   s"     % % %S %c %    c                *    Wn         W n        W0n        R # N)r   r	   r
   )selfr   r	   r
   s   &&&&r   __init__SliceFileObj.__init__C   s    "$r   c                V   V P                   P                  4       V n        V P                   P                  ^ \        P
                  4      p\        V P                  WP                  ,
          4      V n	        V P                   P                  V P                  \        P                  4       V # )    )r   tell_previous_positionseekosSEEK_ENDminr
   r	   _lenioSEEK_SET)r   end_of_streams   & r   	__enter__SliceFileObj.__enter__H   sk    "&,,"3"3"5))!R[[9)GH	$.."++6r   c                n    V P                   P                  V P                  \        P                  4       R # r   )r   r   r   r    r!   )r   exc_type	exc_value	tracebacks   &&&&r   __exit__SliceFileObj.__exit__P   s     $112;;?r   c                    < V ^8  d   QhRS[ /# )r   nr   )r   r   s   "r   r   r   S   s      c r   c                    V P                  4       pW P                  8  d   R # V P                  V,
          pV P                  P                  V^ 8  d	   V4      pV# \	        W4      4      pV# )r   )r   r   r   readr   )r   r,   posremaining_amountdatas   &&   r   r/   SliceFileObj.readS   s^    iik))99s?||  QU!1Y ADA@XYr   c                    < V ^8  d   QhRS[ /# )r   returnr-   )r   r   s   "r   r   r   [   s     4 4c 4r   c                X    V P                   P                  4       V P                  ,
          # r   )r   r   r	   r   s   &r   r   SliceFileObj.tell[   s    ||  "T^^33r   c                ,   < V ^8  d   QhRS[ RS[ RS[ /# )r   offsetwhencer5   r-   )r   r   s   "r   r   r   ^   s'     B B3 B Bc Br   c                8   V P                   pW0P                  ,           pV\        P                  \        P                  39   dL   V\        P                  8X  d	   W1,           MWA,           p\        V\        W4      4      p\        P                  pMaV\        P                  8X  d>   V P                  P                  4       p\        W5,
          \        WV,
          4      4      pM\        R V R24      hV P                  P                  W4      V P                   ,
          # )zwhence value z is not supported)r	   r   r   r!   r   maxr   SEEK_CURr   r   
ValueErrorr   )r   r:   r;   startendcur_poss   &&&   r   r   SliceFileObj.seek^   s    iibkk2;;//'-'<U^#,FF 01F[[Fr{{"ll'')G#fGm*DEF}VH4EFGG||  04>>AAr   c              #  6   "   V P                  RR7      x  R# 5i)   )r,   Ni  @ )r/   r7   s   &r   __iter__SliceFileObj.__iter__l   s     ii/i**s   )r   r   r   r
   r	   N))__name__
__module____qualname____firstlineno____doc__r   r#   r)   r/   r   r   r!   r   rF   __static_attributes____classdictcell__)r   s   @r   r   r      sS     *X% %
@ 4 4 /1kk B B+ +r   r   )rM   r    r   
contextlibr   typingr   r    r   r   <module>rS      s%      	 	 - W+) W+r   