How to determine compression method of a ZIP/RAR file

Viewed 31697

I have a few zip and rar files that I'm working with, and I'm trying to analyze the properties of how each file was compressed (compression level, compression algorithm (e.g. deflate, LZMA, BZip2), dictionary size, word size, etc.), and I haven't figured out a way to do this yet.

Is there any way to analyze the files to determine these properties, with software or otherwise?

Cheers and thanks!

7 Answers

The zipfile python module can be used to get info about the zipfile. The ZipInfo class provides information like filename, compress_type, compress_size, file_size etc...

Python snippet to get filename and the compress type of files in a zip archive

import zipfile

with zipfile.ZipFile(path_to_zipfile, 'r') as zip:
    for info in zip.infolist():
        print(f'filename: {info.filename}')
        print(f'compress type: {info.compress_type}')

This would list all the filenames and their corresponding compression type(integer), which can be used to look up the compression method.
You can get a lot more info about the files using infolist().

The python module linked in the accepted answer is not available, zipfile module might help

Related