U
    xÊ¹j  ã                
   @   s0  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k
rx   Y nX e	dedƒ z&ddlmZ d*dd„Ze	dedƒ W n0 ek
rÜ   ddlmZ e	ddd„ dƒ Y nX z(ddlmZ e	dedƒ e	dedƒ W n ek
�r   Y nX z0ddlZe	dejddd� e	dejddd� W n ek
�rd   Y nX G dd„ deƒZz"ddlZe d¡ e	d eg ƒ W n eeefk
�r´   Y nX zddlZe	d!ejjd!ƒ W n ek
�rè   Y nX z"ddlZd+d"d#„Z e	d$e d%ƒ W n ek
�r"   Y nX d&d'„ Z!dS ),z9Helper functions for a standard streaming compression APIé    )ÚZipFileN)ÚAbstractBufferedFilec                 K   s   | S ©N© )ÚfileÚmodeÚkwargsr   r   úQ/var/www/html/bwave/python/venv/lib/python3.8/site-packages/fsspec/compression.pyÚ	noop_file	   s    r
   Fc                 C   s|   t |tƒr|g}| tkr*|s*td| › �ƒ‚|D ]*}|tjjkr.|s.td|› d| › d�ƒ‚q.|t| < |D ]}| tjj|< qfd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|krJ|pd}t | fddi|—Ž‰ ˆ j|dd�}|jf‡ fdd„	|_|S t | ƒ‰ |d krfˆ  ¡ d }ˆ j|fddi|—ŽS )	NÚrr   r   Úw)r   c                    s   | ƒ pˆ   ¡ S r   )Úclose)Zcloser©Úzr   r	   Ú<lambda><   ó    zunzip.<locals>.<lambda>r   )r   Úopenr   Únamelist)Úinfiler   Úfilenamer   Úfor   r   r	   Úunzip7   s    r&   Úzip)ÚBZ2FileÚbz2)Úigzipc                 K   s   t jf | |dœ|—ŽS )N)Úfileobjr   )r*   Z	IGzipFile)r#   r   r   r   r   r	   ÚisalP   s    r,   ÚgzipÚgz©ÚGzipFilec                 K   s   t f d| i|—ŽS )Nr+   r/   )Úfr   r   r   r	   r   X   r    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                    sV   dd l }tƒ jf d d| d¡d ddœ|—Ž || _d|krH| ¡ | _n
| ¡ | _d S )Nr   ÚsnappyÚbiÿÉš;)ÚfsÚpathr   Úsizer   )r6   ÚsuperÚ__init__Ústripr#   ZStreamDecompressorÚcodecZStreamCompressor)Úselfr#   r   r   r6   ©Ú	__class__r   r	   r<   m   s       ÿÿzSnappyFile.__init__Fc                 C   s.   | j  d¡ | j | j  ¡ ¡}| j |¡ dS )Nr   T)ÚbufferÚseekr>   Z	add_chunkÚreadr#   Úwrite)r?   ÚfinalÚoutr   r   r	   Ú_upload_chunky   s    zSnappyFile._upload_chunkr   c                 C   s   t dƒ‚d S )NzSnappyFile is not seekable)ÚNotImplementedError)r?   ÚlocÚwhencer   r   r	   rC      s    zSnappyFile.seekc                 C   s   dS )NFr   )r?   r   r   r	   Úseekable‚   s    zSnappyFile.seekablec                 C   s   | j  || ¡}| j |¡S )z*Get the specified set of bytes from remote)r#   rD   r>   Ú
decompress)r?   ÚstartÚendÚdatar   r   r	   Ú_fetch_range…   s    zSnappyFile._fetch_range)F)r   )	Ú__name__Ú
__module__Ú__qualname__r<   rH   rC   rL   rQ   Ú__classcell__r   r   r@   r	   r5   l   s
   

r5   r    r6   Úlz4c                 C   s4   d|krt  ¡ }| | ¡S t jdd�}| | ¡S d S )Nr   é
   )Úlevel)ÚzstdZZstdDecompressorZstream_readerZZstdCompressorZstream_writer)r#   r   Zcctxr   r   r	   Úzstandard_file    s
    
rZ   rY   Zzstc                   C   s   t tƒS )z.Return a list of the implemented compressions.)Úlistr   r   r   r   r	   Úavailable_compressions­   s    r\   )F)r   N)r   )r   )"Ú__doc__Úzipfiler   Zfsspec.utilsr   Zfsspec.specr   r
   r   r   r&   r)   r(   ÚImportErrorr,   r*   r-   r0   r3   r2   Zlzmaffir5   r6   ÚcompressÚ	NameErrorÚAttributeErrorZ	lz4.framerV   Úframer!   Z	zstandardrY   rZ   r\   r   r   r   r	   Ú<module>   sn   
%

  ÿ


