MCPcopy Create free account
hub / github.com/ActiveState/code / zip

Method zip

recipes/Python/259147_FSList/recipe-259147.py:461–486  ·  view source on GitHub ↗

return a data stream of the files compressed in zip format. Returns None if the list is empty.

(self)

Source from the content-addressed store, hash-verified

459 return False
460
461 def zip(self):
462 """
463 return a data stream of the files compressed in zip format.
464 Returns None if the list is empty.
465 """
466 import cStringIO, zipfile
467 fobj = cStringIO.StringIO()
468 # make sure the list contains something
469 if len(self) >= 0:
470 try:
471 zip = zipfile.ZipFile(fobj, "w", zipfile.ZIP_DEFLATED)
472 except:
473 sys.stderr.write("Unable to open zip file.")
474 raise
475 try:
476 for name in self:
477 # only add files
478 if os.path.isfile(name):
479 zip.write(name)
480 zip.close()
481 return fobj.getvalue()
482 finally:
483 fobj.close()
484 else:
485 # return None if the list is empty.
486 return None
487
488 if COMPAT23:
489 def targz(self):

Callers 1

recipe-259147.pyFile · 0.45

Calls 4

isfileMethod · 0.80
writeMethod · 0.45
closeMethod · 0.45
getvalueMethod · 0.45

Tested by

no test coverage detected