In python 2.6, a ZipFile object has an open method that can open a named file in zip as a file object, you can sue it to read the data in pieces
import zipfile import os def read_in_chunks(zf, name): chunk_size= 4096 f = zf.open(name) data_list = [] total_read = 0 while 1: data = f.read(chunk_size) total_read += len(data) print "read",total_read if not data: break data_list.append(data) return "".join(data_list) zip_file_path = r"C:\Users\anurag\Projects\untitled-3.zip" zf = zipfile.ZipFile(zip_file_path, "r") for name in zf.namelist(): data = read_in_chunks(zf, name)
Edit: To get the total size, you can do something like this
total_size = sum((file.file_size for file in zf.infolist()))
So, now you can print the overall progress and progress for each file, for example. Suppose you only have 1 large file in zip, other methods (e.g. just counting file sizes and extracting) will not make any progress.
Anurag uniyal
source share