
A ZIP download named "project-export.zip" does not tell you what is inside it, how many entries it contains or how large its contents claim to be. Before extracting an expected export into a folder full of working files, inspect its directory information.
I would start with filenames and declared sizes, not an automatic extract-and-open workflow. Python's standard library can show that information locally without writing the archived files to disk. This is an inventory check, not a malware scan or a promise that the archive is safe.
Start with the built-in listing command
For an expected ZIP from a source you recognize, run this in a terminal with Python 3 available:
python -m zipfile -l "project-export.zip"
On a system where Python 3 is named python3, use that command instead. Replace the example filename with your actual archive path. Python documents -l as the list-files option. It is different from the extraction option, -e, which this check does not use.
Look for the files you expected to receive. Is this the report bundle, source export or photo archive you requested? If the file came unexpectedly from an unknown sender, verifying that sender and the download route comes before opening it with another tool. Even metadata inspection means asking software to parse an input file.
Summarize the archive without unpacking it
If a long listing is hard to review, this Python 3 script summarizes the entry count and sizes recorded in the ZIP metadata. It prints only the first 20 entries to keep the terminal output manageable:
from zipfile import ZipFile
with ZipFile("project-export.zip", "r") as archive:
entries = archive.infolist()
files = [entry for entry in entries if not entry.is_dir()]
print("Entries:", len(entries))
print("File entries:", len(files))
print("Declared uncompressed bytes:",
sum(entry.file_size for entry in files))
print("Compressed data bytes:",
sum(entry.compress_size for entry in files))
for entry in entries[:20]:
print(repr(entry.filename), entry.file_size)
infolist() returns information for each archive member. The file_size field is the uncompressed size and compress_size is the compressed data size. The latter sum is not necessarily the size of the ZIP file itself, because the archive also has structural information.
These are declared metadata values, not a measurement of completed extraction or a guaranteed disk-space budget. The script does not inspect nested archives recursively, and a count of entries does not prove that each filename is unique. It also builds a list in memory, so it is not a resource limit for enormous or hostile inputs.
Do not turn a size check into a safety verdict
A very small download with unexpectedly large declared contents deserves investigation, but there is no universal compression-ratio cutoff that proves an archive safe. Python's documentation warns that malicious ZIP files can exhaust disk space during decompression. Available memory and disk space are practical limits too.
Integrity checking answers another question. Python's testzip() reads archive files to check their CRCs and file headers. It is not equivalent to listing metadata, and a successful integrity check does not establish who created the files or whether their contents should be trusted. Do not add a full read of every member casually when your immediate task was only to inspect an inventory.
Choose an extraction destination deliberately
After the source and inventory make sense, use a separate destination rather than extracting over important working files. Python documents that repeated extraction can overwrite files without asking. Its ZIP documentation also warns against extracting untrusted archives without prior inspection, including concerns about member paths.
My stopping point for this first pass is a recognizable file inventory and a plausible size expectation, with the original archive retained. Unexpected entries, unexplained sizes or an uncertain source are reasons to pause and ask the sender for clarification, not reasons to click through every file in the bundle.
Comments
Post a Comment