zoukankan      html  css  js  c++  java
  • using python zipFile: strange 'BadZipfile'

    using GAE with Python

    wanna generate a zip file from the server with some server-generated rtf files.

     1 import zipfile
     2 from cStringIO import StringIO 
     3 
     4 zipStream = StringIO()
     5 = zipfile.ZipFile(zipStream, 'w', zipfile.ZIP_DEFLATED)
     6 
     7 #f = StringIO()
     8 #generated by another lib
     9 #f could be any string
    10 z.writestr('test.rtf', f.getvalue())
    11 z.close()
    12 zipStream.seek(0)
    13 self.response.out.write(zipStream.getvalue())

     someone said we could not use the return value if the ZipFile was created by passing in a file-like object

    http://stackoverflow.com/questions/583791/is-it-possible-to-generate-and-return-a-zip-file-with-app-engine

     i found that we could add 

    z.close()
    zipStream.seek(0)

     then the 'BadZipfile' is gone.

     that's strange.

  • 相关阅读:
    依赖注入与控制反转
    Java NIO(三)
    Java NIO(二)
    Java NIO(一)
    Jetty 的基本架构
    spring IOC
    java代理
    spring AOP
    linux 添加用户并授权可以操作文件夹
    Centos6.5 yum 安装jdk1.8
  • 原文地址:https://www.cnblogs.com/liyinkan/p/2098789.html
Copyright © 2011-2022 走看看