
    h                         S SK r S SKJr  S SKJr  S SKrS SKJr   " S S\5      r " S S\5      r	 " S	 S
\5      r
 " S S\5      r " S S\5      r " S S\5      rg)    N)partial)Optional)AbstractArchiveFileSystemc                      ^  \ rS rSr% SrSrSr\\S'   Sr	\\S'   Sr
\\   \S'    SS\S	\\   S
\\   4U 4S jjjr\U 4S j5       rS rS\4S jr    SS\S\4S jjrSrU =r$ )BaseCompressedFileFileSystem	   zFRead contents of compressed file as a filesystem with one file inside. Nprotocolcompression
extensionsfotarget_protocoltarget_optionsc                 X  > [         TU ]  " U 40 UD6  [        US5      (       a  UR                  5       OUU l        [        [        R                  U R                  4SUU R                  SSS.U=(       d    0 R                  S0 5      ES.U=(       d    0 D6U l
        [        R                  R                  U R                  R                  S5      S	   5      U l        S
U R                  ;   a(  U R                  SU R                  R!                  S
5       OU R                  U l        SU l        g)a  
The compressed file system can be instantiated from any compressed file.
It reads the contents of compressed file as a filesystem with one file inside, as if it was an archive.

The single file inside the filesystem is named after the compresssed file,
without the compression extension at the end of the filename.

Args:
    fo (:obj:``str``): Path to compressed file. Will fetch file using ``fsspec.open()``
    mode (:obj:``str``): Currently, only 'rb' accepted
    target_protocol(:obj:``str``, optional): To override the FS protocol inferred from a URL.
    target_options (:obj:``dict``, optional): Kwargs passed when instantiating the target FS.

__fspath__rbFT)requote_redirect_url	trust_envclient_kwargs)moder
   r   r   z::r   .N)super__init__hasattrr   r   r   fsspecopenr   pop_open_with_fsspecospathbasenamesplitcompressed_namerindexuncompressed_name	dir_cache)selfr   r   r   kwargs	__class__s        Z/home/james-whalen/.local/lib/python3.13/site-packages/datasets/filesystems/compression.pyr   %BaseCompressedFileFileSystem.__init__   s     	((%,R%>%>"--/B!(KKGG"
 $(((-! "'R,,_bA"
 #"
  "ww//d0CA0FG d***   !C4#7#7#>#>s#CD%% 	
     c                 @   > [         TU ]  U5      R                  S5      $ )N/)r   _strip_protocollstrip)clsr    r)   s     r*   r/   ,BaseCompressedFileFileSystem._strip_protocol;   s      w&t,33C88r,   c                     U R                   cP  0 U R                  5       R                  R                  U R                  5      ESU R
                  0EnUS   U0U l         g g )Nname)r&   r   fsinfor   r%   )r'   fs     r*   	_get_dirs&BaseCompressedFileFileSystem._get_dirs@   sU    >>!]4))+..33DGG<]fdF\F\]Ai^DN "r,   r    c                     U R                  5       R                  5        nUR                  5       sS S S 5        $ ! , (       d  f       g = f)N)r   r   read)r'   r    r7   s      r*   cat BaseCompressedFileFileSystem.catE   s.    ##%**,668 -,,s	   9
Ar   c                     U R                  U5      nUS:w  a  [        SU SU R                   S35      eU R                  5       R	                  5       $ )Nr   zTried to read with mode z	 on file z opened with mode 'rb')r/   
ValueErrorr   r   r   )r'   r    r   
block_size
autocommitcache_optionsr(   s          r*   _open"BaseCompressedFileFileSystem._openI   sS     ##D)4<7vYtwwiOefgg%%',,..r,   )r   r#   r&   r   r%   )r	   NN)r   NTN)__name__
__module____qualname____firstlineno____doc__root_markerr
   str__annotations__r   r   listr   dictr   classmethodr/   r8   r<   rC   __static_attributes____classcell__)r)   s   @r*   r   r   	   s    PK c  K JS	  ei&&-5c]&S[\`Sa& &P 9 9,
  // / /r,   r   c                   &    \ rS rSrSrSrSrS/rSrg)Bz2FileSystemX   z?Read contents of BZ2 file as a filesystem with one file inside.bz2z.bz2 N	rE   rF   rG   rH   rI   r
   r   r   rP   rV   r,   r*   rS   rS   X       IHKJr,   rS   c                   (    \ rS rSrSrSrSrSS/rSrg)GzipFileSystem`   z@Read contents of GZIP file as a filesystem with one file inside.gzipz.gzz.gziprV   NrW   rV   r,   r*   rZ   rZ   `   s    JHK!Jr,   rZ   c                   &    \ rS rSrSrSrSrS/rSrg)Lz4FileSystemh   z?Read contents of LZ4 file as a filesystem with one file inside.lz4z.lz4rV   NrW   rV   r,   r*   r^   r^   h   rX   r,   r^   c                   &    \ rS rSrSrSrSrS/rSrg)XzFileSystemp   zFRead contents of .xz (LZMA) file as a filesystem with one file inside.xzz.xzrV   NrW   rV   r,   r*   rb   rb   p   s    PHKJr,   rb   c                   (    \ rS rSrSrSrSrSS/rSrg)ZstdFileSystemx   zC
Read contents of .zstd file as a filesystem with one file inside.
zstdz.zstz.zstdrV   NrW   rV   r,   r*   rf   rf   x   s     HK'"Jr,   rf   )r   	functoolsr   typingr   r   fsspec.archiver   r   rS   rZ   r^   rb   rf   rV   r,   r*   <module>rl      se    	    4L/#< L/^0 "1 "0 / #1 #r,   