![](/img/trans.png)
[英]how to test for passwords entries of a 7zip file using a python script?
[英]How to retrieve a single 7zip file without extracting all of it in Python3.x?
在Python中,我想瀏覽所有子目錄並提取7z文件並檢查其內容。 我不想提取所有文件,但是我應該能夠迭代/遞歸地瀏覽內容。
主要問題是.7z zip的大小為15 GB,但解壓縮后為225 GB。 現在我的硬盤是160 GB。 在這225 GB中,我可能僅需要有效的60 GB數據。 僅當我可以瀏覽單個文件中的數據時,我才能搜索該文件。 .7z文件上有os.walk類的功能嗎?
我正在探索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
import lzma
f7file = r"C:\Users\padmaraj.bhat\OneDrive - Accenture\Downloads\wiki-html\wikipedia-en-html.tar.7z"
f = lzma.open(f7file, 'rb')
for line in f:
lzma.decompress(line)
break
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
當我必須執行類似操作時,我必須通過subprocess()
調用7z
CLI。 這樣,您可以從歸檔文件中確定文件列表以及文件內容。
例如,要直接將文件提取到stdout,可以使用-so
選項 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.