This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cmcqueen1975
Recipients ced, cmcqueen1975, ezio.melotti, ivb, loewis, mark.dickinson, orsenthil, petri.lehtinen, python-dev, r.david.murray, techtonik
Date 2017-08-16.02:17:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1502849843.08.0.507202939494.issue6090@psf.upfronthosting.co.za>
In-reply-to
Content
One ongoing weakness I see with this situation is that it's difficult to code a suitable work-around if a user wants to zip files that have a date < 1980 (e.g. to zip it with a datestamp of 1-Jan-1980).
https://stackoverflow.com/q/45703747/60075

I am trying to create a zip file with Python 3.5.2 zipfile, on Linux. Some of the files I'm trying to add have timestamps of 1-Jan-1970 (embedded system without a real-time clock module). So zipfile gives an exception:

ValueError: ZIP does not support timestamps before 1980

My goal then is to implement a work-around to add these files to the zip file with a timestamp of 1-Jan-1980. However, I am finding it difficult to find a suitable work-around.

At first I thought I can do this:

def zinfo_from_file(fullname, arcname):
    st = os.stat(fullname)
    mtime = time.localtime(st.st_mtime)
    date_time = mtime[0:6]
    if date_time[0] < 1980:
        date_time = (1980, 1, 1, 0, 0, 0)
    zinfo = zipfile.ZipInfo(arcname, date_time)
    return zinfo

...
zinfo = zinfo_from_file(fullname, arcname)
chunksize=512
with open(fullname, 'rb') as src, myzipfile.open(zinfo, 'w') as dest:
    while True:
        data = src.read(chunksize)
        if not data:
            break
        dest.write(data)
...

However, it turns out that myzipfile.open(zinfo, 'w') is not supported until Python 3.6. (I'm using Yocto to build embedded Linux, which currently only supports Python 3.5.x.)

I guess I could try doing myzipfile.writestr(...), although then it appears that I have to load the entire file data into memory.
History
Date User Action Args
2017-08-16 02:17:23cmcqueen1975setrecipients: + cmcqueen1975, loewis, mark.dickinson, orsenthil, techtonik, ezio.melotti, ced, r.david.murray, ivb, python-dev, petri.lehtinen
2017-08-16 02:17:23cmcqueen1975setmessageid: <1502849843.08.0.507202939494.issue6090@psf.upfronthosting.co.za>
2017-08-16 02:17:23cmcqueen1975linkissue6090 messages
2017-08-16 02:17:22cmcqueen1975create