zipfiles module... read a file from archive

Danny Pansters danny at ricin.com
Mon Mar 18 19:58:43 EST 2002


Hello,

I am not subscribed to this list because so far the documentation 
and/or the ease of Python has been so good I didn't need to ask 
anything, but I do have a problem now. So please send or CC to me!

I would like to know if reading from a zipfile is only possible by 
reading its entrire contents in memory (the read() method of the 
ZipFile class) or is there a way to do this, say, line by line.

I'm anticipating doing file uploads to users' websites through a web 
form (that way I don't need to give them FTP (yaiks) or SSH/shell 
(WinSCP) access and they dont need to learn anything but a simple web 
interface).

I want to avoid a load of client site javascript to easily do 
multiple file uploads (yes I will have a "more" button to add more 
upload widgets but if a user has a huge pile of files or wants to 
upload or overwrite a particular directory tree with some files here 
and there this method gets very time consuming) so I want to include 
the option to upload a (pk) zipped file and extract it at the server 
into the desired target. Anyone who can use winzip can then have her 
whole site uploaded in one take.

So I was hoping for a method that makes me read files in the zip 
archive line by line or bit by bit for all I care and have them 
written accordingly to their targets much like one would do with 
ordinary file upload. 

The zipfile will probably already be on the server in the user's 
directory. I guess that would be easiest to follow the routine I use 
for normal file upload and then if its a zip file have it be 
extracted after uploading it.

So, am I stuck with having every file in the zip archive in memory to 
be able to write them to disk (would yield some limits just for 
safety) or can I do it in chunks somehow?

Best regards, Python ROCKS!


-------------------------------
      Danny Pansters
      danny at ricin.com
      http://www.ricin.com
-------------------------------




More information about the Python-list mailing list