Could zipfile module process the zip data in memory?
sjmachin at lexicon.net
Sun Apr 29 13:34:20 CEST 2007
On Apr 29, 9:15 pm, 人言落日是天涯，望极天涯不见家 <kelvin.... at gmail.com> wrote:
> I made a C/S network program, the client receive the zip file from the
> server, and read the data into a variable. how could I process the
> zipfile directly without saving it into file.
> In the document of the zipfile module, I note that it mentions the
> file-like object? what does it mean?
> class ZipFile( file[, mode[, compression[, allowZip64]]])
> Open a ZIP file, where file can be either a path to a file (a
> string) or a file-like object.
A file-like object is an object that is not a file object, but behaves
like a file object. Instead of keeping the data on disk, it will use
Python objects (e.g. str or maybe array.array) or malloc its own
memory. Have a look at the StringIO module (pure Python) and the
similar but faster cStringIO module.
More information about the Python-list