
    Asi                         d dl Z d dlZd dlmZ d dlmZ d dlmZ  G d de j                        Z	 G d d      Z
 G d	 d
      Zy)    NGzipFile)Optional)to_bytesc                   `     e Zd ZdZej
                  f fd	Zed        Zde	de
e   fdZ xZS )GzipCompressionWrapperz1Wrapper for compressing file contents on the fly.c                     t         |           || _        t        j                  |d      | _        t               | _        y )N   )levelwbits)super__init__rawzlibcompressobjcompress	bytearrayleftover)selfr   r   	__class__s      ]/var/www/python-projects/worksol/worksolenv/lib/python3.12/site-packages/storages/compress.pyr   zGzipCompressionWrapper.__init__   s2    ((uB?!    c                       y)NT r   r   r   readablezGzipCompressionWrapper.readable   s    r   bufreturnc                 ^   t        |      }t        | j                        |k  rt        | j                  j	                  |            }|sP| j
                  rC| xj                  | j
                  j                  t        j                        z  c_        d | _        nG| xj                  | j
                  j                  |      z  c_        t        | j                        |k  rt        | j                        dk(  ry| j                  d | }t        |      }||d | | j                  |d  | _        |S )Nr   )	lenr   r   r   readr   flushr   Z_FINISH)r   r   sizechunkoutputs        r   readintozGzipCompressionWrapper.readinto   s    3x$-- 4'TXX]]401E==MMT]]%8%8%GGM$(DMMMT]]33E::M $-- 4' t}}"u%6{ET
de,r   )__name__
__module____qualname____doc__r   Z_BEST_COMPRESSIONr   staticmethodr   r   r   intr&   __classcell__)r   s   @r   r   r   	   s?    ;"&"9"9 $  I (3- r   r   c                       e Zd Zd Zy)CompressStorageMixinc                     t        |      S )zGzip a given string content.)r   )r   contents     r   _compress_contentz&CompressStorageMixin._compress_content*   s    %g..r   N)r'   r(   r)   r3   r   r   r   r0   r0   )   s    /r   r0   c                       e Zd ZddZy)CompressedFileMixinc                     t        |||      S )N)modefileobjmtimer   )r   r7   filer9   s       r   _decompress_filez$CompressedFileMixin._decompress_file0   s    T4u==r   N)g        )r'   r(   r)   r;   r   r   r   r5   r5   /   s    >r   r5   )ior   gzipr   typingr   storages.utilsr   	RawIOBaser   r0   r5   r   r   r   <module>rA      s9    	    #R\\ @/ /> >r   