o
    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                       sR   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           	   
      sL  t  jd
i | |pi }t|tr#tj|fd|i|| _| j }|d u rd }z(t|dr3|j}nt|dr<|j	}nt|drE|j
}nt|drP| d }W n tyk } ztd|  W Y d }~nd }~ww |d urt|}td| d|  |d urt| |}|| _|| _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openofhasattrr   r   r   r   	Exceptionloggerwarningr   r   _fo_reffotarfileTarFiler	   	dir_cacheindex_storeindex_index)	selfr   r#   target_optionstarget_protocolcompressionkwargsr   ex	__class__r   n/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/fsspec/implementations/tar.pyr      sF   	





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&   out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 < qd 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   r0   r/   r   )	r"   _all_dirnamesr	   getnames
getmembersr1   r4   r2   r3   )r&   memberr   r   r   r.   	_get_dirsg   s   
zTarFileSystem._get_dirsrbc                 K   s>   |dkrt d| j| \}}|d dkrt d| j|S )NrA   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)rA   )__name__
__module____qualname____doc__root_markerr   cachabler   r%   r@   rG   __classcell__r   r   r,   r.   r
      s    Br
   )loggingr    r   fsspec.archiver   fsspec.compressionr   fsspec.utilsr   r2   	getLoggerr   r
   r   r   r   r.   <module>   s    

