
                         v    S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJr  SSK	J
r
    SS jrS rS	 rS
 rS rg)zGzip utils for gcloud storage.    N)storage_url)user_request_args_factory)
properties)filesc                 N   [        U R                  SS5      nU(       d8  U(       a  SUR                  S5      ;   d  U(       a  SUR                  S5      ;   d  g [        R                  " US5       n[
        R                  " US[        R                  R                  R                  R                  5       S9 n[        R                  " Xg5        S	S	S	5        S	S	S	5        g! , (       d  f       N= f! , (       d  f       g= f! [         a    [        R                   " U5         gf = f)
a  Checks if file is elligible for decompression and decompresses if true.

Args:
  source_resource (ObjectResource): May contain encoding metadata.
  gzipped_path (str): File path to unzip.
  destination_path (str): File path to write unzipped file to.
  do_not_decompress_flag (bool): User flag that blocks decompression.
  server_encoding (str|None): Server-reported `content-encoding` of file.

Returns:
  (bool) True if file was successfully decompressed, else False.
contentEncoding gzip,FrbT)create_path"convert_invalid_windows_charactersN)getattrmetadatasplitr
   openr   BinaryFileWriterr   VALUESstorage,convert_incompatible_windows_path_charactersGetBoolshutilcopyfileobjOSErrorosremove)source_resourcegzipped_pathdestination_pathdo_not_decompress_flagserver_encodingcontent_encodinggzipped_fileungzipped_files           3lib/googlecloudsdk/command_lib/storage/gzip_util.pydecompress_gzip_if_necessaryr&      s    " _557H"M6%5%;%;C%@@&O$9$9#$>> 	<	&,!!
'';;GGI <8 
'   
'	& 	  II		 sI   D 0AC07CC0D 
C-	)C00
C>:D >D  D$#D$c                 :   U (       a  U(       d  gU R                   nU R                   [        R                  :X  a  U R                  $ [	        U[
        5      (       aA  U H;  nSUR                  S5      -   nUR                  U5      (       d  M/  U R                  s  $    g)z8Determines what, if any, type of file should be gzipped.N.z .)
extensionsr   GZIP_ALLtype
isinstancelistlstripendswith)gzip_settings	file_pathgzip_extensions	extensiondot_separated_extensions        r%   _should_gzip_file_typer5   E   s    
I!,,/!:!C!CC/4(($	 #i&6&6t&< <			3	4	4!!! % 
    c                 N    [        X5      [        R                  R                  :H  $ )z9Determines if file qualifies for in-flight gzip encoding.)r5   r   GzipType	IN_FLIGHTr0   r1   s     r%   should_gzip_in_flightr;   T   s(    	
 #<#E#E#O#O
P Pr6   c                 N    [        X5      [        R                  R                  :H  $ )N)r5   r   r8   LOCALr:   s     r%   should_gzip_locallyr>   Z   s(    	
 #<#E#E#K#K
L Lr6   c                    U [         R                  -   n[        R                  " U 5       n[        R
                  " US5       n[        R                  " X#5        S S S 5        S S S 5        U$ ! , (       d  f       N= f! , (       d  f       U$ = f)Nwb)r   TEMPORARY_FILE_SUFFIXr   BinaryFileReaderr
   r   r   r   )r1   zipped_file_pathfile_readergzip_file_writers       r%   get_temporary_gzipped_filerF   _   so    !B!BBi(K	#T	*.>7 
+ ) 
 
+	* )( 
s#   A<A+A<+
A9	5A<<
B)FN)__doc__r
   r   r   "googlecloudsdk.command_lib.storager   r   googlecloudsdk.corer   googlecloudsdk.core.utilr   r&   r5   r;   r>   rF    r6   r%   <module>rL      sE    %  	  : H * * 9>15	&RPL
r6   