o
    h                  
   @   s  d Z ddlmZ ddlZddlmZ dd ZdeiZd(dd	Z	d)ddZ
e	de
d zddlmZ W n	 ey;   Y nw e	ded zddlmZ d*ddZe	ded W n eyl   ddlmZ e	ddd d Y nw zddlmZ e	ded e	ded W n	 ey   Y nw zddlZe	dejddd e	dejddd W n	 ey   Y nw G dd deZzddlZed e	d eg  W n eeefy   Y nw zddlZe	d!ejjd! W n	 ey   Y nw zddlZd*d"d#Z e	d$e d% W n
 ey   Y nw d&d' Z!dS )+z9Helper functions for a standard streaming compression API    )ZipFileN)AbstractBufferedFilec                 K   s   | S N )filemodekwargsr   r   f/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/fsspec/compression.py	noop_file	      r
   Fc                 C   s|   t |tr|g}| tv r|std|  |D ]}|tjjv r,|s,td| d|  dq|t| < |D ]}| tjj|< q3dS )aA  Register an "inferable" file compression type.

    Registers transparent file compression type for use with fsspec.open.
    Compression can be specified by name in open, or "infer"-ed for any files
    ending with the given extensions.

    Args:
        name: (str) The compression type name. Eg. "gzip".
        callback: A callable of form (infile, mode, **kwargs) -> file-like.
            Accepts an input file-like object, the target mode and kwargs.
            Returns a wrapped file-like object.
        extensions: (str, Iterable[str]) A file extension, or list of file
            extensions for which to infer this compression scheme. Eg. "gz".
        force: (bool) Force re-registration of compression type or extensions.

    Raises:
        ValueError: If name or extensions already registered, and not force.

    z$Duplicate compression registration: z&Duplicate compression file extension: z ()N)
isinstancestrcompr
ValueErrorfsspecutilscompressions)namecallback
extensionsforceextr   r   r	   register_compression   s   
r   rbc                    s|   d|vr%|pd}t | fddi|  j|dd}|jf fdd	|_|S t |  |d u r3  d } j|fddi|S )	Nrr   r   w)r   c                    s   |  p   S r   )close)closerzr   r	   <lambda><   s    zunzip.<locals>.<lambda>r   )r   openr   namelist)infiler   filenamer   for   r   r	   unzip7   s   r'   zip)BZ2Filebz2)igzipc                 K   s   t jd| |d|S )N)fileobjr   r   )r+   	IGzipFile)r$   r   r   r   r   r	   isalP   s   r.   gzipgzGzipFilec                 K   s   t dd| i|S )Nr,   r   r1   )fr   r   r   r	   r!   X   s    r!   )LZMAFilelzmaxzT)r   c                       s@   e Zd Z fddZdddZdddZd	d
 Zdd Z  ZS )
SnappyFilec                    sX   dd l }t jdd d|dd dd| || _d|v r%| | _d S | | _d S )Nr   snappybiɚ;)fspathr   sizer   r   )r8   super__init__stripr$   StreamDecompressorcodecStreamCompressor)selfr$   r   r   r8   	__class__r   r	   r>   m   s   zSnappyFile.__init__Fc                 C   s.   | j d | j| j  }| j| dS )Nr   T)bufferseekrA   	add_chunkreadr$   write)rC   finaloutr   r   r	   _upload_chunky   s   zSnappyFile._upload_chunkr   c                 C   s   t d)NzSnappyFile is not seekable)NotImplementedError)rC   locwhencer   r   r	   rG      s   zSnappyFile.seekc                 C   s   dS )NFr   )rC   r   r   r	   seekable   r   zSnappyFile.seekablec                 C   s   | j || }| j|S )z*Get the specified set of bytes from remote)r$   rI   rA   
decompress)rC   startenddatar   r   r	   _fetch_range   s   zSnappyFile._fetch_rangeF)r   )	__name__
__module____qualname__r>   rM   rG   rQ   rV   __classcell__r   r   rD   r	   r7   l   s    

r7       r8   lz4c                 C   s0   d|v rt  }|| S t jdd}|| S )Nr   
   )level)zstdZstdDecompressorstream_readerZstdCompressorstream_writer)r$   r   cctxr   r   r	   zstandard_file   s
   

rf   r`   zstc                   C   s   t tS )z.Return a list of the implemented compressions.)listr   r   r   r   r	   available_compressions   s   ri   rW   )r   N)r   )"__doc__zipfiler   fsspec.utilsr   fsspec.specr   r
   r   r   r'   r*   r)   ImportErrorr.   r+   r/   r2   r5   r4   lzmaffir7   r8   compress	NameErrorAttributeError	lz4.framer]   framer"   	zstandardr`   rf   ri   r   r   r   r	   <module>   sz    

%



