2 years ago
#66454

J'e
using python, look at the contents of a compressed file without reading the entire file
Using python, I want to look at the contents of a .zip (deflate) without reading the entire file. I have a very slow network drive containing lots of compressed files. I would like to be able to open a file and look at the contents without downloading the entire file first.
For contrast, when opening a .zip using windows 10 file explorer, it downloads the entire file. On the other hand, 7zip "Open Archive" lets you see the contents without downloading the entire file.
How can I do this with python. I've tried using the following code but like the windows10 file explorer, it downloads the entire file before printing the file names.
from zipfile import ZipFile
with ZipFile("filename.zip") as zip_obj:
for sub_file in zip_obj.namelist():
print(sub_file.filename)
python
python-zipfile
0 Answers
Your Answer