-2
我有一個文件,其中包含許多zlib檔案本身。該文件的 結構如下:閱讀zlib檔案列表
+-------------------------+
|+-----------------------+|
|| CMF+FLG (78DA) ||
|+-----------------------+|
|+-----------------------+|
||...compressed data 1...||
|+-----------------------+|
|+-----------------------+|
|| ADLER32 ||
|+-----------------------+|
|
|+-----------------------+|
|| CMF+FLG (78DA) ||
|+-----------------------+|
|+-----------------------+|
||...compressed data 2...||
|+-----------------------+|
|+-----------------------+|
|| ADLER32 ||
|+-----------------------+|
|
|+-----------------------+|
|| CMF+FLG (78DA) ||
|+-----------------------+|
|+-----------------------+|
||...compressed data 3...||
|+-----------------------+|
|+-----------------------+|
|| ADLER32 ||
|+-----------------------+|
| |
|.........................|
| |
|+-----------------------+|
|| CMF+FLG (78DA) ||
|+-----------------------+|
|+-----------------------+|
||...compressed data n...||
|+-----------------------+|
|+-----------------------+|
|| ADLER32 ||
|+-----------------------+|
+-------------------------+
,我需要遍歷所有的歸檔和提取它們。 我試過下面的代碼,但是這隻從文件中提取第一個存檔。
for filename in sys.argv[1:]:
with open(filename, 'r') as compressed:
with open(filename + '-decompressed', 'w') as expanded:
data = zlib.decompress(compressed.read())
expanded.write(data)
看起來好像你可以將文件分割成'CMD + FLG'標記,儘管我不清楚什麼保護你免受包含在一個壓縮數據部分中的相同序列的影響。 –
如何拆分而不刪除分隔符? – Yukarin