views:

64

answers:

1

I apologize for any confusion from the question title. It's kind of a complex situation with components that are new to me so I'm unsure of how to describe it succinctly.

I have some xml data and an image in an archive (zip in this case, but could easily be tar or tar.gz) and using python, gtk, and webkit, place the image in a webkit.WebView, along with some of the other data. The xml is child's play to access without extracting the files, but the image is another issue.

I'd like to avoid extracting the image to to the hdd before putting it in the WebView and doing a base64 encode of the image data feels cludgy, especially since the images could potentially reach tens of megabytes.

Basically I'm looking for a way to construct an URI to a file stored inside a container file.

I asked a few days ago in IRC and was directed toward virtual file systems. In the searches I performed I found a few references to creating a vfs from a zip file, but no examples or even much in the way of documentation on virtual file systems themselves (gnomeVFS, gvfs, gio.) I may be looking in all the wrong places, however.

+1  A: 

The zipfile module in the standard Python library provides tools to create, read, write, append, and list a ZIP file.

Using ZipFile.read(name[, pwd]) ( return the bytes of the file name in the archive), you can apply base64.b64encode(s[, altchars]) to the content. Note that in this straightforward process, the unzipped and the encoded versions are stored in memory.

gimel
Thanks, but the base64 encode is something I was trying to avoid.
Artanis