Git Product home page Git Product logo

spideroak-zipstream's Introduction

#SpiderOak zipstream module ##THIS IS A GITHUB MIRROR ONLY

###This library was created by SpiderOak, Inc. and is released under the GPLv3.

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.

Contact the SpiderOak team at [email protected]

And be sure to back up your files! http://www.spideroak.com

##ZipStream works with HUGE files too!

Generate 6 gigs of random data

ionadmin@onfire:/results/zip$ dd if=/dev/urandom of=file.blob bs=1048576 count=6000

Get the checksum of the generated file

ionadmin@onfire:/results/zip$ md5sum file.blob
11ef7625569f44977789caa785b5f112  file.blob

Now compress it using zipstream

from zipstream import ZipStream
toZip = "/results/zip/file.blob"
zf = open('zipfile.zip', 'wb')
for data in ZipStream(toZip):
    zf.write(data)
zf.close()

Check the output zipfile checksum

ionadmin@onfire:/results/zip/output$ md5sum zipfile.zip
405437edcb0c81d7639e01f8f1e50417  zipfile.zip

Unzip the zipped file ionadmin@onfire:/results/zip/output$ unzip zipfile.zip

The resulting file checksum

ionadmin@onfire:/results/zip/output$ md5sum file.blob
11ef7625569f44977789caa785b5f112  file.blob

So ZipStream is a great solution if you need to zip large files with Python 2.6.5.

zipfile with Python 2.6.5 is broken for large files - http://bugs.python.org/issue8571

Python 2.6.5 is part of Ubuntu 10.04. So this ZipStream is a great solution to zip large files with Python 2.6.5!

Bitdeli Badge

spideroak-zipstream's People

Contributors

bitdeli-chef avatar gourneau avatar sir-sigurd avatar

Watchers

 avatar  avatar

Forkers

zavsnar

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.