Skip to content Skip to sidebar Skip to footer

Zip Files Without Any Metadata

I'd like to find an easy way to zip a bunch of files without any file metadata (e.g., timestamps). The zip command seems to always perserve the metadata. I don't see a way to disab

Solution 1:

As some of the posts have already pointed out most of the metadata fields in a zip header have to be present. If the file contents you are zipping are identical each time, then the only field that will be different is the timestamp.

It is possible to force the timestamp to be specific value by creating a ZipInfo object and changing the timestamp.

Here is a proof-of-concept

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:
    withopen(name, mode='rb') as file:
        fileContent = file.read()
        member.write(fileContent)

Above code creates test.zip with the field timestamp hard-wired to 1st Jan 1980.

$ unzip -l test.zip
Archive:  test.zip
  Length      DateTime    Name
---------  ---------- -----   ----3071980-01-0100:00   tmp/testfile.txt
---------                     -------3071 file

Post a Comment for "Zip Files Without Any Metadata"