1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| import datetime
import zipfile
import struct
from datetime import date, timedelta,time
_fileHeaderSize = struct.calcsize(zipfile.structFileHeader)
def print_info(archive_name):
print('lecture par infolist')
zf = zipfile.ZipFile(archive_name)
for info in zf.infolist():
print(info.filename)
print('\tComment:\t', info.comment)
print('\tModified:\t', datetime.datetime(*info.date_time))
print('\tSystem:\t\t', info.create_system, '(0 = Windows, 3 = Unix)')
print('\tZIP version:\t', info.create_version)
print('\tCompressed:\t', info.compress_size, 'bytes')
print('\tUncompressed:\t', info.file_size, 'bytes')
print('=====================================')
def lireHeaderFile(zipFile):
f = open(zipFile, 'r+b')
data = f.read()
pos = data.find(b'\x50\x4b\x03\x04') # début file header
if pos >= 0:
f.seek(pos)
fheader = f.read(_fileHeaderSize)
fheader = struct.unpack(zipfile.structFileHeader, fheader)
fname = f.read(fheader[zipfile._FH_FILENAME_LENGTH])
ftime = fheader[zipfile._FH_LAST_MOD_TIME]
fdate = fheader[zipfile._FH_LAST_MOD_DATE]
fcompsize = fheader[zipfile._FH_COMPRESSED_SIZE]
ftotalsize = fheader[zipfile._FH_UNCOMPRESSED_SIZE]
print("lecture par entête fichier local")
print(fname)
print('date : ',str(fdate & 0x001F),'/',str(fdate>>5 & 0x000F),'/',str((fdate>>9) + 1980))
print('heure : ',str(ftime>>11),':',str(ftime>>5 & 0x001F),':',str((ftime & 0x001F) * 2))
print('taille compressée : ',str(fcompsize))
print('taille : ',str(ftotalsize))
print('=======================================')
f.close()
if __name__ == '__main__':
lireHeaderFile('d:/temp/partofExample.zip')
print_info('d:/temp/Example.zip') |