pythonzip

How to get offset values of all files (or given filename) in a zipfile using python?


I really don't know the complexity or the way to go forward. Any help is appreciated.


Solution

  • The ZipFile class contains all what you need:

    zf = ZipFile(...)
    
    # for all files
    for zinfo in zf.infolist():
        print(f'{zinfo.filename}: offset {zinfo.header_offset}')
    
    # for specific file
    zinfo = zf.getinfo(filename)
    print(f'{zinfo.filename}: offset {zinfo.header_offset}')