From 09a8f31a642d5e2d007d400dce46b45e43eaa993 Mon Sep 17 00:00:00 2001 From: valq7711 Date: Fri, 6 Jul 2018 06:21:42 +0300 Subject: [PATCH] add web2py example --- README.markdown | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.markdown b/README.markdown index a228c4d..9b0a6d5 100644 --- a/README.markdown +++ b/README.markdown @@ -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`