L i:ddlmZddlmZmZmZmZmZmZm Z ddl Z ddl m Z ddl mZddlmZddlmZddlmZeeeeeeZe jde j,egee j.Zee d Zed d e j6fd ZGd d eZy))contextmanager) CFUNCTYPEPOINTERc_int c_longlongc_void_pcastcreate_string_bufferN) open_files)AbstractArchiveFileSystem) MemoryFile)DEFAULT_BLOCK_SIZEread_set_seek_callback NO_OPEN_CBallc# Kt| t t fd}fd}tj|}t |}t r!tj}tj} nZtjjtj}tjjtj} tjj||5} t| |tj | d||| tjj#| dddy#1swYyxYww)zRead an archive from a seekable file-like object. The `file` object must support the standard `readinto` and 'seek' methods. cfj}t|tt}|d<|S)Nr)readintor rr) archive_pcontextptrptrlengthbufbuf_pfiles g/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/fsspec/implementations/libarchive.py read_funcz custom_reader..read_func*s0s#fgh/0q  cHj||jS)N)seektell)rroffsetwhencers r seek_funcz custom_reader..seek_func3s &&!yy{rN)r r rffi READ_CALLBACK SEEK_CALLBACKnew_apir NO_CLOSE_CB libarchiveread OPEN_CALLBACKVOID_CBCLOSE_CALLBACKnew_archive_readr read_open ArchiveRead) r format_name filter_name block_sizerr$read_cbseek_cbopen_cbclose_cbrrrs ` @@r custom_readerr9!s z *C h E  *GI&G..??//// <??11#++>  ) )+{ C5yy'2 iwBoo)))44555sC)E .AD>5 E >EE cteZdZdZdZdZdZddddeffd Ze dZ e fd Z d Z d d ZxZS) LibArchiveFileSystemayCompressed archives as a file-system (read-only) Supports the following formats: tar, pax , cpio, ISO9660, zip, mtree, shar, ar, raw, xar, lha/lzh, rar Microsoft CAB, 7-Zip, WARC See the libarchive documentation for further restrictions. https://www.libarchive.org/ Keeps file object open while instance lives. It only works in seekable file-like objects. In case the filesystem does not support this kind of file object, it is recommended to cache locally. This class is pickleable, but not necessarily thread-safe (depends on the platform). See libarchive documentation for details. r*FrNc (t||fi||dk7r tdt|tr7t |fd|i|xsi}t |dk7rtd|d|d|d}||_|j|_ ||_ d |_ y ) aB Parameters ---------- fo: str or file-like Contains ZIP, and must exist. If a str, will fetch file using :meth:`~fsspec.open_files`, which must return one file exactly. mode: str Currently, only 'r' accepted target_protocol: str (optional) If ``fo`` is a string, this value can be used to override the FS protocol inferred from a URL target_options: dict (optional) Kwargs passed when instantiating the target FS, if ``fo`` is a string. r=z%Only read from archive files acceptedprotocolzPath "z(" did not resolve to exactly one file: ""rN) super__init__ ValueError isinstancestrr lenof __enter__for4 dir_cache) selfrJmodetarget_protocoltarget_optionsr4kwargsfiles __class__s rrCzLibArchiveFileSystem.__init__^s0 (( 3;DE E b# rVOV@TRTVE5zQ RD HqQqB,,.$rc#K|jjdt|j|j5}|dddy#1swYyxYww)Nr)r4)rJr r9r4)rLarcs r _open_archivez"LibArchiveFileSystem._open_archivesB  Q 477t ? 3I   s=AA  A AAc@t||jdS)N/)rB_strip_protocollstrip)clspathrRs rrXz$LibArchiveFileSystem._strip_protocols w&t,33C88rc dddddddd}|jyi|_g}|j5}|D]}|js |js|jj |j t |jDcic] }||d d d  c}|Dcic]}|t|||}}|jrd nd |d <|j|j||j|d< ddd|jj |j |Dcic] }||d d d  c}ycc}wcc}w#1swYQxYwcc}w)NpathnamesizectimerMuidgidmtime)namer^createdrMr`rarbr directory)rcr^typerrfrc) rKrUisdirisfileupdate _all_dirnamessetrcgetattrappend)rLfields list_namesrTentrydirnamekeyfs r _get_dirszLibArchiveFileSystem._get_dirssr  >> %     ! .S .{{5<<%%(,'9'9#ejj/'J# '1k!RR BHH#S'%55HH+0;;KF& !!%**-,-qy) . .$  $11*= '1kJJ   I . .& s1AE E  E$E ;AE0E EEc T|j|}|dk7rtt}|j5}|D]K} | j|k7r| j dk(rn*| j | j D]} | }Ftdddt|||S#1swYxYw)Nrbr)fsr[data) rXNotImplementedErrorbytesrUr]r^ get_blocksrDr ) rLr[rMr4 autocommit cache_optionsrPrxrTrpblocks r_openzLibArchiveFileSystem._opens##D) 4<% %w    ! %S %>>T)::?"--ejj9%E D%%$ % %T488 % %s ABB')rvNTN)__name__ __module__ __qualname____doc__ root_markerr?cachablerrCrrU classmethodrXrtr __classcell__)rRs@rr;r;Hsq"KHH  % %N 99' X 9rr;) contextlibrctypesrrrrrr r r*libarchive.ffir%fsspecr fsspec.archiver fsspec.implementations.memoryr fsspec.utilsrr' c_archive_p check_intrhasattrr( page_sizer9r;rrrs%44+*eXz5I  s >s}} #| $$)u#5#5LM94M9r