
    j7                         d dl Z d dlZd dlZd dlmZmZmZ ddlmZm	Z	 ddl
mZ ddlmZmZ erddlmZ dgZd	gZ G d
 de      Zy)    N)BinaryIOAnyTYPE_CHECKING   )DocumentConverterDocumentConverterResult)
StreamInfo)UnsupportedFormatExceptionFileConversionException)
MarkItDownzapplication/zipz.zipc                   X     e Zd ZdZ	 	 d	 fdZdedededefdZ	dededede
fdZ xZS )
ZipConvertera  Converts ZIP files to markdown by extracting and converting all contained files.

    The converter extracts the ZIP contents to a temporary directory, processes each file
    using appropriate converters based on file extensions, and then combines the results
    into a single markdown document. The temporary directory is cleaned up after processing.

    Example output format:
    ```markdown
    Content from the zip file `example.zip`:

    ## File: docs/readme.txt

    This is the content of readme.txt
    Multiple lines are preserved

    ## File: images/example.jpg

    ImageSize: 1920x1080
    DateTimeOriginal: 2024-02-15 14:30:00
    Description: A beautiful landscape photo

    ## File: data/report.xlsx

    ## Sheet1
    | Column1 | Column2 | Column3 |
    |---------|---------|---------|
    | data1   | data2   | data3   |
    | data4   | data5   | data6   |
    ```

    Key features:
    - Maintains original file structure in headings
    - Processes nested files recursively
    - Uses appropriate converters for each file type
    - Preserves formatting of converted content
    - Cleans up temporary files after processing
    c                0    t         |           || _        y )N)super__init___markitdown)self
markitdown	__class__s     e/root/aria/tools/markitdown-venv/lib/python3.12/site-packages/markitdown/converters/_zip_converter.pyr   zZipConverter.__init__=   s    
 	%    file_streamstream_infokwargsreturnc                     |j                   xs dj                         }|j                  xs dj                         }|t        v ryt        D ]  }|j                  |      s y y)N TF)mimetypelower	extensionACCEPTED_FILE_EXTENSIONSACCEPTED_MIME_TYPE_PREFIXES
startswith)r   r   r   r   r   r    prefixs          r   acceptszZipConverter.acceptsE   sg      ((.B557 **0b779	001 	F""6*	 r   c                    |j                   xs |j                  xs |j                  }d| d}t        j                  |d      5 }|j                         D ]  }	 t        j                  |j                  |            }t        t        j                  j                  |      d   t        j                  j                  |            }	| j                  j                  ||	      }
|
|d| dz  }||
j                   dz   z  } 	 d d d        t'        |j)                         	      S # t"        $ r Y t$        $ r Y w xY w# 1 sw Y   <xY w)
NzContent from the zip file `z`:

r   )r    filename)streamr   z	## File: z

)markdown)url
local_pathr)   zipfileZipFilenamelistioBytesIOreadr	   ospathsplitextbasenamer   convert_streamr+   r
   r   r   strip)r   r   r   r   	file_path
md_contentzipObjnamez_file_streamz_file_stream_inforesults              r   convertzZipConverter.convertW   sC     OOU{'='=UAUAU	29+VD
__[#. 	&) $&JJv{{4/@$AM)3"$''"2"24"8";!#!1!1$!7*& "--<<,$6 = F )"	$t&<<
"foo&>>
	( '
0@0@0BCC 2 . #	 	s=   E B(D'E '	D=0E 2D=:E <D==E  E	)r   r   )__name__
__module____qualname____doc__r   r   r	   r   boolr%   r   rA   __classcell__)r   s   @r   r   r      ss    $L& !&   	
 
$DD  D 	D
 
!Dr   r   )r.   r1   r4   typingr   r   r   _base_converterr   r   _stream_infor	   _exceptionsr
   r   r   r   r"   r!   r    r   r   <module>rM      sM     	 	 / / H % M (   #8 ^D$ ^Dr   