Craig McQueen added the comment: 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. ---------- nosy: +cmcqueen1975 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6090> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com