如何在Python3.x中检索单个7zip文件而不提取所有文件?

2024-06-16 09:29:31 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python中,我希望浏览所有子目录并提取一个7z文件并检查其内容。我不想提取所有的文件,但我应该能够以迭代/递归的方式窥探内容。在

主要关心的是.7z压缩包的大小为15gb,但解压缩后的大小为225gb。现在我的硬盘是160GB。在这225 GB中,我可能只需要60 GB的有效数据。只有当我能浏览单个文件中的数据时,我才能搜索到它。有吗手术室步行对.7z文件有什么作用?在

https://dumps.wikimedia.org/other/static_html_dumps/current/en/*.7z是文件,我正在研究。在

7z l *.7z

7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=C.UTF-8,Utf16=on,HugeFiles=on,64 bits,4 CPUs Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz (406E3),ASM,AES-NI)

Scanning the drive for archives:
1 file, 15363543213 bytes (15 GiB)

Listing archive: wikipedia-en-html.tar.7z

--
Path = wikipedia-en-html.tar.7z
Type = 7z
Physical Size = 15363543213
Headers Size = 100
Method = LZMA:22
Solid = -
Blocks = 1

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2008-06-18 23:32:15 ..... 223674511360  15363543113  wikipedia-en-html.tar
------------------- ----- ------------ ------------  ------------------------
2008-06-18 23:32:15       223674511360  15363543113  1 files
^{pr2}$
Traceback (most recent call last)
  <ipython-input-5-d1a496a0c194> in <module>()
      4 
      5 f = lzma.open(f7file, 'rb')
----> 6 for line in f:
      7     lzma.decompress(line)
      8     break

  ~\AppData\Local\Continuum\anaconda3\lib\lzma.py in readline(self, size)
    220         """
    221         self._check_can_read()
--> 222         return self._buffer.readline(size)
    223 
    224     def write(self, data):

  ~\AppData\Local\Continuum\anaconda3\lib\_compression.py in readinto(self, b)
     66     def readinto(self, b):
     67         with memoryview(b) as view, view.cast("B") as byte_view:
---> 68             data = self.read(len(byte_view))
     69             byte_view[:len(data)] = data
     70         return len(data)

  ~\AppData\Local\Continuum\anaconda3\lib\_compression.py in read(self, size)
    101                 else:
    102                     rawblock = b""
--> 103                 data = self._decompressor.decompress(rawblock, size)
    104             if data:
    105                 break

LZMAError: Input format not supported by decoder

Tags: 文件inselfviewdatasizelocalhtml
1条回答
网友
1楼 · 发布于 2024-06-16 09:29:31

当我必须做这样的事情时,我必须通过subprocess()调用7zCLI。通过这种方式,您可以确定文件列表以及存档中的文件内容。在

例如,要将文件直接提取到stdout,可以使用the ^{} option。在

相关问题 更多 >