creating ZIP files on the cheap

uticdmarceau2007 at uticdmarceau2007 at
Wed Dec 23 21:59:54 CET 2009

samwyse wrote:
> I've got an app that's creating Open Office docs; if you don't know,
> these are actually ZIP files with a different extension.  In my case,
> like many other people, I generating from boilerplate, so only one
> component (content.xml) of my ZIP file will ever change.  Instead of
> creating the entire ZIP file each time, what is the cheapest way to
> accomplish my goal?  I'd kind-of like to just write the first part of
> the file as a binary blob, then write my bit, then write most of the
> table of contents as another blob, and finally write a TOC entry for
> my bit.  Has anyone ever done anything like this?  Thanks.
I think you intend on using simply the command-line infozip tool from
python system commands:
mycmd = "zip -r content.xml"
mycmd = "zip -i your.blob"
    mycmd = "zip -r content.xml"
    retcode = call(mycmd, shell=True)
    mycmd = "zip -i your.blob"
    retcode = call(mycmd, shell=True)
    if retcode < 0:
        print >>sys.stderr, "Child was terminated by signal", -retcode
        print >>sys.stderr, "Child returned", retcode
except OSError, e:
    print >>sys.stderr, "Execution failed:", e

More information about the Python-list mailing list