a
    h                     @   sd   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ dddZ	e 
dZG d	d
 d
eZdS )    N)AbstractArchiveFileSystem)compr)infer_compressionfile	directory)   0   5tarc                       sH   e Zd ZdZdZdZdZd fdd	Zdd	 Zd
d Z	dddZ
  ZS )TarFileSystemzzCompressed Tar archives as a file-system (read-only)

    Supports the following formats:
    tar.gz, tar.bz2, tar.xz
     r	   FNc           	   
      sN  t  jf i | |pi }t|trFtj|fd|i|| _| j }|d u rd }zPt|drf|j}n:t|drx|j	}n(t|dr|j
}nt|dr| d }W n4 ty } ztd|  W Y d }~n
d }~0 0 |d urt|}td| d|  |d urt| |}|| _|| _tj| jd	| _d | _|| _d | _|   d S )
Nprotocoloriginalpathnameinfoz:Unable to determine file name, not inferring compression: zInferred compression z from file name )fileobj)super__init__
isinstancestrfsspecopenZofhasattrr   r   r   r   	Exceptionloggerwarningr   r   Z_fo_reffotarfileTarFiler	   	dir_cacheindex_storeindex_index)	selfr   r    Ztarget_optionsZtarget_protocolcompressionkwargsr   ex	__class__ H/var/www/auris/lib/python3.9/site-packages/fsspec/implementations/tar.pyr      s@    	






zTarFileSystem.__init__c                 C   sV   i }| j D ]@}| }t|d d|d< | d d}||jf||< q
|| _d S )Ntyper   r   /)r	   get_infotypemapgetrstripoffset_datar!   )r#   outZtir   r   r)   r)   r*   r"   [   s    
zTarFileSystem._indexc                 C   sz   | j d urd S dd | | j D | _ | j D ]@}| }|d d|d< t|d d|d< || j |d < q4d S )Nc                 S   s   i | ]}||d ddqS )r   r   )r   sizer+   r)   ).0dirnamer)   r)   r*   
<dictcomp>l   s   z+TarFileSystem._get_dirs.<locals>.<dictcomp>r   r,   r+   r   )	r   Z_all_dirnamesr	   getnames
getmembersr-   r0   r.   r/   )r#   memberr   r)   r)   r*   	_get_dirsg   s    
zTarFileSystem._get_dirsrbc                 K   s>   |dkrt d| j| \}}|d dkr2t d| j|S )Nr;   z#Read-only filesystem implementationr+   r   zCan only handle regular files)
ValueErrorr!   r	   extractfile)r#   r   moder%   detailsoffsetr)   r)   r*   _openv   s    zTarFileSystem._open)r   NNNN)r;   )__name__
__module____qualname____doc__Zroot_markerr   Zcachabler   r"   r:   rA   __classcell__r)   r)   r'   r*   r
      s        Br
   )loggingr   r   Zfsspec.archiver   Zfsspec.compressionr   Zfsspec.utilsr   r.   	getLoggerr   r
   r)   r)   r)   r*   <module>   s   

