![](/img/trans.png)
[英]Without using any additional libraries, how would someone approach the challenge of reading the metadata of .pdf files in Python?
[英]zip files without any metadata
我想找到一種簡單的方法來壓縮一堆沒有任何文件元數據的文件(例如,時間戳)。 zip
命令似乎始終堅持元數據。 我沒有看到禁用元數據的方法。
我希望解決方案是一個命令或至多是一個python腳本。 謝謝。
由於一些帖子已經指出,必須存在zip標題中的大多數元數據字段。 如果您正在壓縮的文件內容每次都相同,那么唯一不同的字段是時間戳。
通過創建ZipInfo
對象並更改時間戳,可以強制時間戳為特定值。
這是一個概念驗證
import zipfile
file = zipfile.ZipFile("test.zip", "w")
name = "/tmp/testfile.txt"
zi = zipfile.ZipInfo.from_file(name)
zi.date_time = (1980,1,1,0,0,0)
with file.open(zi, mode='w') as member:
with open(name, mode='rb') as file:
fileContent = file.read()
member.write(fileContent)
上面的代碼創建了test.zip
,字段時間戳連接到1980年1月1日。
$ unzip -l test.zip
Archive: test.zip
Length Date Time Name
--------- ---------- ----- ----
307 1980-01-01 00:00 tmp/testfile.txt
--------- -------
307 1 file
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.