Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add web2py example #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@ def GET(self):
return zipstream.ZipFile(path)
```

### web2py
```python
def zipball():
import zipstream
import os
p = 'path/to/files'
z = zipstream.ZipFile(mode='w', compression=ZIP_DEFLATED)
for fname in os.listdir(p):
fp = os.path.join(p,fname)
z.write(fp, fname)

headers = {}
headers['Content-Type'] = 'application/zip'
headers['Content-Disposition'] = 'attachment; filename="files.zip"'
def zipped_stream():
for chunk in z:
yield chunk
raise HTTP(200, zipped_stream(), **headers)
```

## Running tests

With python version > 2.6, just run the following command: `python -m unittest discover`
Expand Down