Giter Club home page Giter Club logo

zipstream's Introduction

ZipStream

zipstream.py is a zip archive generator based on zipfile.py. It was created to generate a zip file on-the-fly for download in a web.py (http://webpy.org/) application. This is beneficial for when you want to provide a downloadable archive of a large collection of regular files, which would be infeasible to generate the archive prior to downloading.

The archive is generated as an iterator of strings, which, when joined, form the zip archive. For example, the following code snippet would write a zip archive containing files from 'path' to a normal file:

zf = open('zipfile.zip', 'wb')
for data in ZipStream(path):
    zf.write(data)
zf.close()

Since recent versions of web.py support returning iterators of strings to be sent to the browser, to download a dynamically generated archive, you could use something like this snippet:

def GET(self):
    path = '/path/to/dir/of/files'
    zip_filename = 'files.zip'
    web.header('Content-type' , 'application/zip')
    web.header('Content-Disposition', 'attachment; filename="%s"' % (
        zip_filename,))
    return ZipStream(path)

If the zlib module is available, ZipStream can generate compressed zip archives.

Requirements

  • Python >=2.6

License

This library was created by SpiderOak, Inc. and is released under the GPLv3. Copyright 2008-2013 SpiderOak Inc.

zipstream's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zipstream's Issues

Malformed Download URL due to UNC path

(referencing internal issue 2904)

Currently zipstream creates improperly long file names on Windows due to inappropriate use of splitdrive() on UNC paths. @rupole suggests just using os.path.split() instead, which should just work, as well as ensure we only encode the name of the directory and not the whole path.

problems with encoding of binary data

Thanks for contributing this module -- it looks very promising. I'm using it with python 2.6.5, and I have been running into issues like this:

20:57:58 T:2960314368 ERROR: File "/Applications/XBMC.app/Contents/Resources/XBMC/addons/webinterface.qxbmc/zipstream2.py", line 175, in FileHeader
20:57:58 T:2960314368 ERROR: return header + self.filename + extra
20:57:58 T:2960314368 ERROR: UnicodeDecodeError: 'ascii' codec can't decode byte 0xec in position 10: ordinal not in range(128)

(I've made some modifications to zipstream to be able to zip an arbitrary list of files rather than an entire directory tree, so you'll notice that my line numbers don't match yours; but I did also get this error with the unmodified code).

It seems that python is trying to interpret the header as if it were some sort of character data.

There are a few places in the code where this happens. I've been able to code around some of them by making multiple calls to yield instead of joining the binary strings together, but I'm not sure that's the right thing to do.

It also only happens with certain input files; some files don't trigger the problem.

Failure in encoding utf8 filenames

While working on GlobaLeaks and reusing the spideroak zipstream implementation we foound out that that implementation is failing to encode utf8 filenames.

In order to fix the issue you could use the fix implemented in globaleaks/GlobaLeaks@5b4c994

that fix make use of standard python code present in recent zipfile.py (python 2.7/3.4)

As sidenot it would be interesting for you to know that in python3.4 the zipfile.py implementation makes possibile to use also BZIP2 and LMZA that are more efficient in the compression. Among the two it would be valuable to integrate BZIP2 that has a more high compression rate while being less cpu intensive.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.